Cod sursa(job #3273042)

Utilizator FlaviuuuFlaviu Flaviuuu Data 1 februarie 2025 09:20:22
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
ifstream cin("energii.in");
ofstream cout("energii.out");
#define ll long long
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll g;
    cin>>g;
    ll w;
    cin>>w;
    ll e, c;
    ll dp[10001];
    dp[0] = 0;
    for(int i = 1; i <= 10000; i++)
        dp[i] = 1e15;
    for(int i = 1; i <= g; i++)
    {
        cin>>e>>c;
        if(e <= w)
            dp[e] = min(dp[e], c);
        else
            dp[w] = min(dp[w], c);
        for(int j = w; j >= e + 1; j--)
            dp[j] = min(dp[j], dp[j - e] + c);
    }
    cout<<dp[w];
    return 0;
}