Cod sursa(job #1777490)

Utilizator calin1Serban Calin calin1 Data 12 octombrie 2016 16:07:56
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, g_max, vec[10005];

void citire()
{
    scanf("%d %d\n",&n,&g_max);

    int x,y;
    for(int i = 0 ; i < n ; ++i)
    {
        scanf("%d %d\n",&x,&y);

        for(int j = g_max ; j >= x ; --j)
        {
            vec[j] = max(vec[j],vec[j - x] + y);
        }
    }
    printf("%d",vec[g_max]);
}

int main()
{
    freopen("rucsac.in","r",stdin);
    freopen("rucsac.out","w",stdout);

    citire();

    return 0;
}