Cod sursa(job #3200205)
| Utilizator | Data | 3 februarie 2024 20:15:11 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
#define int long long
const int GMAX = 1e4;
using namespace std;
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
int dp[GMAX + 5], n, G, a, b, ans;
signed main() {
fin >> n >> G;
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; i++){
fin >> a >> b;
for (int j = G - a; j >= 0; j--){
if (dp[j] != -1)
dp[j + a] = max(dp[a + j], dp[j] + b);
}
}
for (int i = 1; i <= G; i++)
ans = max(ans, dp[i]);
fout << ans;
return 0;
}
