Cod sursa(job #2449359)
| Utilizator | Data | 19 august 2019 14:42:36 | |
|---|---|---|---|
| Problema | Energii | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
int g, w, e, c, dp[2][5001], L;
int main()
{
fin >> g >> w;
L = 1;
for(int i = 1; i <= g; ++i, L = 1 - L)
{
fin >> e >> c;
for(int j = 0; j <= w; ++j)
{
dp[L][j] = dp[1 - L][j];
if(j >= e)
dp[L][j] = max(dp[L][j], dp[1 - L][j - e] + c);
}
}
L = 1 - L;
int sol = 0;
for(int i = 1; i <= w; ++i)
sol = max(sol, dp[L][i]);
fout << sol;
return 0;
}
