Cod sursa(job #2514191)

Utilizator AkribischerADgabriela droc AkribischerAD Data 24 decembrie 2019 18:29:03
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
using namespace std;
ifstream in ("rucsac.in");
ofstream out ("rucsac.out");
int v[50011];
int main()
{
    int n,i,a,b,g,j,p=0,c=0;
    v[0]=1;
    in>>n>>g;
    for(i=1;i<=n;i++)
    {
        in>>a>>b;
        for(j=g;j>=0;j--)
        {
           if(v[j-a]!=0 && v[j-a]+b>v[j])
            v[j]=v[j-a]+b;
            if(v[j]>c)
                c=v[j];
        }

    }
    out<<c-1;

    return 0;
}