Cod sursa(job #2493182)

Utilizator razvanradulescuRadulescu Razvan razvanradulescu Data 16 noiembrie 2019 09:28:27
Problema Problema rucsacului Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
#include <algorithm>
using namespace std;

ifstream f("rucsac.in");
ofstream g("rucsac.out");

int n, G;
int dp[10005];

void read()
{
    f>>n>>G;
    int x, y;
    for(int i = 0; i<n; ++i) {
        f >> x >> y;
        for (int j = G; j >= x; ++j) {
            dp[j] = max(dp[j], y + dp[j - x]);
        }
    }
}

void afisare()
{
    int maxim = 0;
    for(int i = 0; i<=G; ++i)
    {
        maxim = max(maxim, dp[i]);
    }
    g<<maxim;
}

int main() {
    read();
    afisare();
    return 0;
}