Cod sursa(job #2407466)

Utilizator oogaboogauvuvwevwevwe onyetenyevwe ugwemubwem ossas oogabooga Data 16 aprilie 2019 21:30:29
Problema Energii Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(a,b) for(ll i = a; i <= b; ++i)

#define Inf 1999999999
#define Gmax 10005

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

ll G,W,E[Gmax],C[Gmax],Dp[Gmax];

int main(){
    in>>G>>W;
    FOR(1, G) in>>E[i]>>C[i];
    FOR(1, Gmax-1) Dp[i] = Inf;
    FOR(1, E[1]) Dp[i] = C[1];

    FOR(2, G)
        for(int j = W; j >= E[i]; --j)
            if(Dp[j - E[i]] != Inf)
                Dp[j] = min(Dp[j], Dp[j - E[i]] + C[i]);

    out<<Dp[W];


    return 0;
}