Pagini recente » Profil ionguzun | Cod sursa (job #1074861) | Cod sursa (job #2723813) | Cod sursa (job #394284) | Cod sursa (job #3215210)
#include <bits/stdc++.h>
using namespace std;
const int max_size = 1e4 + 20, INF = 2e9 + 1;
int dp[max_size], pr[max_size];
void solve ()
{
int n, wmax;
cin >> n >> wmax;
dp[0] = 1;
for (int i = 1; i <= n; i++)
{
int w, cost;
cin >> w >> cost;
for (int j = wmax; j >= w; j--)
{
if (dp[j - w] == 1)
{
dp[j] = 1;
pr[j] = max(pr[j], pr[j - w] + cost);
}
}
}
int ans = 0;
for (int i = 0; i <= wmax; i++)
{
ans = max(ans, pr[i]);
}
cout << ans;
cout << '\n';
}
signed main ()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#else
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long tt;
//cin >> tt;
tt = 1;
while (tt--)
{
solve();
}
return 0;
}