Pagini recente » Cod sursa (job #3364615) | Cod sursa (job #3364614) | Cod sursa (job #3364605) | Cod sursa (job #3364611) | Cod sursa (job #3364613)
#include <iostream>
#include <fstream>
using namespace std;
const int GMAX=10000,NMAX=5000;
int W[NMAX+1],P[NMAX+1],D[GMAX+1];
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int main()
{
int N,G,pmax,i;
f>>N>>G;
for(int i=1;i<=N;i++)
f>>W[i]>>P[i];
for(int i=1;i<=N;i++)
for(int g=G-W[i];g>=0;--g)
{
int cw=g+W[i],cp=D[g]+P[i];
if(D[cw]<cp)
{
D[cw]=cp;
if(cp>pmax)
pmax=cp;
}
}
g<<pmax;
f.close();
g.close();
return 0;
}