Pagini recente » Cod sursa (job #2489369) | Cod sursa (job #159952) | Cod sursa (job #1676271) | Rating Vasiluta Mihai-Alexandru (AlexVasiluta) | Cod sursa (job #3283315)
#include<fstream>
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;
}