Pagini recente » Cod sursa (job #715910) | Cod sursa (job #2627806) | Cod sursa (job #379338) | Cod sursa (job #558501) | Cod sursa (job #1496829)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("in.in");
ofstream g ("out.out");
const int NMax = 5005;
int D[NMax][NMax];
int main()
{
int n, Gmax, x, value, i, j;
f >> n >> Gmax;
for(i = 1; i <= n; i++)
{
f >> x >> value;
for(j = 1; j <= Gmax; j++)
if(j >= x)
{
D[i][j] = max(D[i - 1][j], D[i - 1][j - x] + value);
}
else
{
D[i][j] = D[i - 1][j];
}
}
g << D[n][Gmax];
return 0;
}