Pagini recente » Cod sursa (job #940538) | Cod sursa (job #2802228) | Cod sursa (job #3256154) | Cod sursa (job #1405591) | Cod sursa (job #2449359)
#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;
}