Cod sursa(job #2614129)

Utilizator MatteoalexandruMatteo Verzotti Matteoalexandru Data 11 mai 2020 12:02:01
Problema Energii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.55 kb
/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
// aparent costurile pot fi si 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>

using namespace std;

const int INF = 2e9;
const int N = 1e3;
const int W = 5e3;

int dp[5 + W];

int main() {
    freopen("energii.in", "r", stdin);
    freopen("energii.out", "w", stdout);
    int n, w;
    scanf("%d%d", &n, &w);

    for(int i = 1; i <= w; i++) dp[i] = INF;

    for(int i = 1; i <= n; i++) {
        int p, g;
        scanf("%d%d", &g, &p);

        for(int j = w; j >= 0; j--) {
            dp[min(w, j + g)] = min(dp[min(w, j + g)], dp[j] + p);
        }
    }

    if(dp[w] != INF) printf("%d\n", dp[w]);
    else printf("-1\n");
    return 0;
}