Pagini recente » Monitorul de evaluare | Rating Iohaniss Klaus (Klaus_Iohaniss) | Cod sursa (job #1462225) | Profil ProfuCreizii | Cod sursa (job #1711580)
#include<iostream>
using namespace std;
int vg[20001], n, i, j, g, maxi, w, p;
int max(int x, int y)
{
if(x>y)
return x;
return y;
//return x > y ? x : y;
}
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
cin>>n>>g;
for(i=1;i<=n;i++)
{
cin>>w>>p;
for(j=g;j>=1;j--)
{
if(vg[j]!=0)
{
vg[j+w]=max(vg[j+w], vg[j]+p);
}
}
vg[w]=max(vg[w], p);
}
maxi=0;
for(i=1; i<=g; i++)
maxi=max(vg[i], maxi);
cout<<maxi;
return 0;
}