Cod sursa(job #3275684)

Utilizator AndreiNicolaescuEric Paturan AndreiNicolaescu Data 11 februarie 2025 15:13:34
Problema Energii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>
#define cin ci
#define cout co
using namespace std;
ifstream cin("energii.in");
ofstream cout("energii.out");
const int Wmax = 10000;
const int INF = 0x3F3F3F;
int n, w;
struct gen
{
    int weight, cost;
};
vector<gen> v;
vector<int> dp(Wmax);
int main()
{
    cin >> n >> w;
    v.resize(n+1);
    fill(dp.begin(), dp.end(), INF);
    for(int i=1; i<=n; i++)
        cin >> v[i].weight >> v[i].cost;
    dp[0] = 0;
    for(int i=1; i<=n; i++)
        for(int j = Wmax - v[i].weight; j>=0; j--)
            dp[j + v[i].weight] = min(dp[j + v[i].weight], dp[j] + v[i].cost);
    int ans = INF;
    for(int i=w; i<Wmax; i++)
        ans = min(ans, dp[i]);
    if(ans == INF)
        cout << "-1";
    else
        cout << ans;

    return 0;
}