Cod sursa(job #3199055)

Utilizator Dragos_HuiuDragos Huiu Dragos_Huiu Data 31 ianuarie 2024 15:48:33
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 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, c[N + 1], p[N + 1];

int main()
{
    fin >> n >> w;

    for(int i = 1; i <= w; i++)
        cost[i] = 1e3;

    for(int i = 0; i < n; i++)
        fin >> c[i] >> p[i];

    for(int i = 0; i < n; i++)
        for(int j = w - c[i]; j >= 0; j--)
            if(cost[j] != 1e3)
                cost[j + c[i]] = min(cost[j + c[i]], cost[j] + p[i]);

    fout << cost[w];
}