Pagini recente » Cod sursa (job #282958) | Cod sursa (job #1938566) | Cod sursa (job #372991) | Cod sursa (job #1805484) | Cod sursa (job #2769049)
#include <iostream>
#include <fstream>
using namespace std;
int n,g;
int dp[2][10005];
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int main()
{
int L=1;
int w,p;
fin>>n>>g;
for(int i=1; i<=n; i++,L=1-L)
{
fin>>w>>p;
for(int j=0; j<=g; j++)
{
dp[L][j]=dp[1-L][j];
if(j>=w)
{
dp[L][j]=max(dp[L][j],dp[1-L][j-w]+p);
}
}
}
L=1-L;
int maxim=0;
for(int i=0;i<=g;i++)
{
maxim=max(maxim,dp[L][i]);
}
fout<<maxim;
return 0;
}