Cod sursa(job #3317931)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 26 octombrie 2025 10:40:27
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#define cin ci
#define cout co
using namespace std;
ifstream cin("energii.in");
ofstream cout("energii.out");
const int inf = 1e9;
const int Vmax = 10000;
int n, g, sum;
vector<pair<int, int>> ob;
vector<int> dp;
int main()
{
    cin >> n >> g;
    ob.resize(n + 1);
    for(int i = 1; i <= n; i++)
    {
        cin >> ob[i].first >> ob[i].second;
        sum += ob[i].second;
    }
    dp.assign(Vmax + 1,  inf);
    dp[0] = 0;
    for(int i = 1; i <= n; i++)
        for(int j = Vmax - ob[i].second; j >= 0; j--)
            dp[j + ob[i].first] = min(dp[j + ob[i].first], dp[j] + ob[i].second);
    int ans = inf;
    for(int i = g; i <= Vmax; i++)
        ans = min(ans, dp[i]);
    if(ans == INF)
        cout << "-1";
    else
        cout << ans;
    return 0;
}