Pagini recente » Cod sursa (job #812109) | Cod sursa (job #1352153) | Cod sursa (job #1666826) | Cod sursa (job #2765987) | Cod sursa (job #614302)
Cod sursa(job #614302)
#include <stdio.h>
#define Max(x,y) (x)>(y)?(x):(y)
class problem{
int n,g,G[10001];
public:
problem();
~problem();
void add(int,int);
};
void problem::add(int x,int y){
int i;
for(i=g-x;i>=0;i--)
if(G[i]!=0)
G[i+x]=Max(G[i+x],G[i]+y);
}
problem::problem(){
int i;
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
scanf("%d%d",&n,&g);
for(i=0;i<=g;i++)G[i]=0;
for(i=1;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
G[x]=Max(G[x],y);}
}
problem::~problem(){
int max=0,i;
for(i=0;i<=g;i++)if(G[i]>max)max=G[i];
printf("%d\n",max);
}
int main(){
problem rucsac;
}