Pagini recente » Cod sursa (job #1845816) | Cod sursa (job #1054881) | Cod sursa (job #43782) | Cod sursa (job #584892) | Cod sursa (job #1311877)
#include <iostream>
#include <fstream>
#define nmax 10005
#define inf (1<<30)
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int main()
{
int n,g,a[nmax], b[nmax],w,p;
int *first, *second,*aux;
first=a;
second=b;
f>>n>>g;
for(int i=0; i<=g; i++)
{
*(first+i)= 0;
}
for(int i=1; i<=n; i++)
{
f>>w>>p;
for(int j=1; j<w; j++) {*(second+j)=*(first+j); cerr<<*(second+j)<<" ";}
for(int j=w; j<=g; j++){ *(second+j)=max(*(first+j-w)+p, *(first+j)); cerr<<*(second+j)<<" ";}
cerr <<endl;
aux=first;
first=second;
second=aux;
}
g<< *(first+g);
return 0;
}