Pagini recente » Cod sursa (job #2698263) | Cod sursa (job #2891028) | Cod sursa (job #2205571) | Cod sursa (job #1276188) | Cod sursa (job #2932789)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int prof[10001];
int main()
{
int n,i,gmax,p,g,j,max;
fin>>n>>gmax;
for(i=1;i<=gmax;i++){
prof[i]=-2000000000;
}
for(i=1;i<=n;i++){
fin>>g>>p;
for(j=gmax;j>=g;j--){
if(prof[j-g]+p>prof[j]){
prof[j]=prof[j-g]+p;
}
}
}
max=0;
for(i=1;i<=gmax;i++){
if(prof[i]>max){
max=prof[i];
}
}
fout<<max;
return 0;
}