Pagini recente » Cod sursa (job #805463) | Cod sursa (job #1038383) | Cod sursa (job #717498) | Cod sursa (job #378760) | Cod sursa (job #2971127)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, Gmax;
int g[1005], v[1005], o[10001];
int main()
{
// cin.tie(0);
// ios::sync_with_stdio(0);
fin >> n >> Gmax;
for(int i=1; i<=n; i++)
fin >> g[i] >> v[i];
o[0] = 0;
int sol = 0;
for(int i=1; i<=n; i++)
for(int j = Gmax - g[i]; j >= 0; j--)
if(o[j+g[i]] < o[j] + v[i])
{
o[j + g[i]] = o[j] + v[i];
if(o[j+g[i]] > sol) sol = o[j + g[i]];
}
fout << sol;
}