Pagini recente » Cod sursa (job #1702165) | Cod sursa (job #903233) | Cod sursa (job #331257) | Cod sursa (job #3352669) | Cod sursa (job #3305019)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, gmax, dp[10010]; ///dp[i] = profitu maxim pana la o greutate totala <= i
struct Iris {
int greutate, profit;
}v[5010];
int main()
{
fin >> n >> gmax;
for(int i=1; i<=n; i++) {
fin >> v[i].greutate >> v[i].profit;
for(int j=gmax; j>=v[i].greutate; j--) dp[j] = max(dp[j], dp[j - v[i].greutate] + v[i].profit);
}
fout << *max_element(dp+1, dp+gmax+1);
return 0;
}