Cod sursa(job #3268342)
| Utilizator | Data | 14 ianuarie 2025 17:42:07 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#define nl '\n'
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
const int GMAX = 1e4+5;
int N, G, dp[2][GMAX], ok, ans;
int main()
{
fin >> N >> G;
for (int i = 1; i <= N; i++)
{
int w, p;
fin >> w >> p;
ok = 1-ok;
for (int j = w; j <= G; j++)
dp[ok][j] = max(dp[1-ok][j], dp[1-ok][j-w]+p);
}
for (int i = 1; i <= G; i++)
ans = max(ans, dp[ok][i]);
fout << ans;
return 0;
}
