Cod sursa(job #1706960)

Utilizator david12345Rotari David david12345 Data 23 mai 2016 21:58:08
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>
using namespace std;
ofstream fout("rucsac.out");
ifstream fin ("rucsac.in");
int v[11001],i,j,maxim,g,n,a,b;
int main()
{
    fin>>n>>g;
    for(int i = 1 ; i <= n ; i++)
    {
        fin>>a>>b;
        for( j = g ; j >= a ; j--)
        {
            if(v[ j ] < v[ j - a ] + b)
            {
                v[ j ] = v[ j - a ] + b;
            }
        }
    }
    fout<<v[ g ];
}