Cod sursa(job #3286601)
| Utilizator | Data | 14 martie 2025 13:52:20 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, g, dp[10003], maxx;
pair <int, int> a[5003];
int main()
{
int i, j;
fin >> n >> g;
for (i = 1; i <= n; i++)
fin >> a[i].first >> a[i].second;
for (i = 1; i <= n; i++)
for (j = g; j >= a[i].first; j--)
dp[j] = max(dp[j], dp[j - a[i].first] + a[i].second);
for (i = 1; i <= g; i++)
maxx = max(maxx, dp[i]);
fout << maxx << "\n";
return 0;
}
