Pagini recente » Cod sursa (job #3303792) | Cod sursa (job #171047) | Monitorul de evaluare | Cod sursa (job #2868913) | Cod sursa (job #3305290)
#include <bits/stdc++.h>
#define NMAX 10000
#define MMAX 100
#define MOD 666013
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, g, w, p, ans;
int main() {
ios_base::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> n >> g;
vector<int> dp(g + 1, -1);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
fin >> w >> p;
for (int j = g; j >= w; j--) {
if (dp[j - w] != -1) {
dp[j] = max(dp[j], dp[j - w] + p);
ans = max(ans, dp[j]);
}
}
}
fout << ans;
return 0;
}