Pagini recente » Cod sursa (job #3264861) | Cod sursa (job #238561) | Cod sursa (job #2668337) | Cod sursa (job #3209674) | Cod sursa (job #1889994)
#include <cstdio>
#include <iostream>
using namespace std;
const int nmx = 10002;
int dp[nmx];
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
int gmax = 0,n,x;
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; ++i)
{
int val,greutate;
scanf("%d %d", &greutate, &val);
gmax += greutate;
gmax = min(gmax,x);
for(int j = gmax; j >= greutate; --j)
dp[j] = max(dp[j],dp[j-greutate] + val);
}
int maxim = -1;
for(int i = 1; i <= x; ++i)
maxim = max(maxim,dp[i]);
printf("%d\n", maxim);
return 0;
}