Cod sursa(job #3199054)

Utilizator Dragos_HuiuDragos Huiu Dragos_Huiu Data 31 ianuarie 2024 15:37:23
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.4 kb
#include <fstream>

using namespace std;

ifstream fin("energii.in");
ofstream fout("energii.out");

const int N = 1e3, W = 5e3;

int n, cost[W + 1], w;
int main()
{
    fin >> n >> w;

    for(int i = 0; i < n; i++)
    {
        int c, p;
        fin >> c >> p;

        for(int j = w; j >= c; j--)
            cost[j] = max(cost[j], cost[j - c] + p);
    }

    fout << cost[w];
}