Pagini recente » Cod sursa (job #2613238) | Cod sursa (job #2537091) | Cod sursa (job #3163232) | Rating Vlad Andrei Popescu (vapopescu) | Cod sursa (job #1668514)
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gr,x,y,i,j,ma,b[10001];
int main()
{ f>>n>>gr;
f>>x>>y;
b[x]=y;
for (i=2;i<=n;++i) {
f>>x>>y;
for (j=gr-x;j>=0;--j) {
if (b[j]>0)
if (b[j+x]==0 || b[j+x]<b[j]+y)
b[j+x]=b[j]+y;}}
for (i=1;i<=gr;++i)
if (b[i]>ma)
ma=b[i];
g<<ma<<'\n';
return 0;
}