Pagini recente » Cod sursa (job #452606) | Cod sursa (job #2016664) | Cod sursa (job #471331) | Cod sursa (job #288085) | Cod sursa (job #3283314)
#include<iostream>
using namespace std;
/*
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
*/
long long N , GMaxx , DP[10001];
struct Obiect{
int G;
int V;
}O[1001];
int main()
{
cin>>N>>GMaxx;
for(int i=1 ; i<=N ; i++)
cin>>O[i].G>>O[i].V;
for(int i=1 ; i<=N ; i++){
for(int cw=GMaxx ; cw>=1 ; cw--){
if(cw >= O[i].G)
DP[cw]=max(DP[cw] , O[i].V + DP[cw-O[i].G]);
else
DP[cw]=DP[cw];
}
}
cout<<DP[GMaxx]<<'\n';
return 0;
}