Cod sursa(job #2920251)
Utilizator | Data | 23 august 2022 11:55:45 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <bits/stdc++.h>
using namespace std;
int dp[10001];
int main()
{
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int n, gmax;
cin >> n >> gmax;
dp[0] = 1;
for(int i = 1; i <= n; i ++)
{
int g, p;
cin >> g >> p;
for(int j = gmax; j >= g; j --)
{
if(dp[j - g] != 0 and dp[j - g] + p > dp[j])
dp[j] = dp[j - g] + p;
}
}
cout << dp[gmax] - 1;
return 0;
}