Cod sursa(job #3240085)

Utilizator stefanrotaruRotaru Stefan-Florin stefanrotaru Data 12 august 2024 14:04:49
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#include <vector>

using namespace std;

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

int n, G, greutate, profit;

int main()
{
    f >> n >> G;

    vector <int> dp(G + 5, 0);

    for (int i = 1; i <= n; ++i) {
        f >> greutate >> profit;

        for (int j = G; j >= greutate; --j) {
            dp[j] = max(dp[j], dp[j -  greutate] + profit);
        }
    }

    g << dp[G];

    return 0;
}