Cod sursa(job #3302120)

Utilizator SergiuS3003Sergiu Stancu Nicolae SergiuS3003 Data 3 iulie 2025 15:01:42
Problema Problema rucsacului Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
const int NMAX = 5001, GMAX = 10001;
int profitMax[GMAX];

int main()
{
    int n, G, ans = 0;
    f >> n >> G;
    for (int i = 1; i <= n; i++)
    {
        int gCrt, pCrt;
        f >> gCrt >> pCrt;
        for (int w = G; w >= gCrt; w--)
        {
            profitMax[w] = max(profitMax[w - gCrt] + pCrt, profitMax[w]);
            ans = max(ans, profitMax[w]);
        }
    }
    g << ans;
    return 0;
}