Pagini recente » Cod sursa (job #1697459) | Cod sursa (job #158642) | Cod sursa (job #2384706) | Cod sursa (job #1893983) | Cod sursa (job #2046099)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
#define lim 10010
int n,dp[lim],gmax,g,p,rez=-1;
int main()
{
fin>>n>>gmax;
for (int i=1; i<=n; i++)
{
fin>>g>>p;
for (int j=gmax-g; j>0; j--)
if (dp[j] && dp[j+g] < dp[j]+p)
dp[j+g] = dp[j]+p, rez = max (rez, dp[j+g]);
dp[g] = max (dp[g], p);
rez = max (rez, dp[g]);
}
fout<<rez;
fin.close();
fout.close();
return 0;
}