Cod sursa(job #2342055)

Utilizator MateiTrandafirMatei Trandafir MateiTrandafir Data 12 februarie 2019 16:16:25
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
#include <cstring>

constexpr int MAX_G = 10001;

int profit[MAX_G];

int main() {
    int n, G, i , j, p, g;
    std::ifstream in("rucsac.in");
    std::ofstream out("rucsac.out");
    in >> n >> G;
    for (i = 0; i < n; ++i) {
        in >> g >> p;
        for (j = G - g; j >= 0; --j) if (p + profit[j] > profit[j + g]) profit[j + g] = p + profit[j];
    }
    out << profit[G];
    return 0;
}