Cod sursa(job #918980)

Utilizator tytus11Trifon Titus tytus11 Data 19 martie 2013 11:58:43
Problema Problema rucsacului Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>

using namespace std;

int x,y[5003],l;

int main()
{
    int n,i,j,op,max;
    ifstream f("rucsac.in");
    ofstream g("rucsac.out");
    f>>n>>op;
    for(i=1;i<=n;i++)
    {
        f>>l>>x;
        for(j=op;j>=0;j--)
        if(y[j]>0&&j+l<=op)
        if(x+y[j]>y[j+l])
        y[j+l]=x+y[j];
        if(y[l]<x)
        y[l]=x;

    }
    max=0;
    for(i=1;i<=op;i++)
    if(y[i]>max)
    max=y[i];
    g<<max;
    f.close();
    g.close();
    return 0;
}