Pagini recente » Cod sursa (job #2688802) | Cod sursa (job #2735391) | Cod sursa (job #2688729) | Cod sursa (job #2688752) | Cod sursa (job #874636)
Cod sursa(job #874636)
#include<fstream>
#define nmax 10002
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gmax,i,w[nmax],p[nmax],v[nmax];
int main()
{
f>>n>>gmax;
int sol=0;
for(i=1;i<=n;i++){
f>>w[i];
f>>p[i];
}
v[0]=0;
for(i=1;i<=n;i++)
for(int j=gmax-w[i];j>=0;j--){
if(v[j+w[i]]<v[j]+p[i])
{
v[j+w[i]]=v[j]+p[i];
if(v[j+w[i]]>sol) sol=v[j+w[i]];
}
}
g<<sol;
f.close();g.close();
return 0;
}