Cod sursa(job #2602912)

Utilizator vladth11Vlad Haivas vladth11 Data 18 aprilie 2020 08:17:32
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb

#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <int, int > pii;

const int N = 25;

int dp[1001];

int main() {
    ifstream cin("energii.in");
    ofstream cout("energii.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,g;
    cin >> n >> g;
    for(int i = 0;i <= g;i++)
        dp[i] = 1e9;
    dp[0] = 0;
    for(int i = 1;i <= n;i++){
        int x,y;
        cin >> x >> y;
        for(int j = g;j >= x;j--){
            dp[j] = min(dp[j], dp[j - x] + y);
        }
    }
    if(dp[g] == 1e9)
        cout << -1;
    else
        cout << dp[g];
    return 0;
}