Cod sursa(job #2895567)

Utilizator AlexMariMarinescu Alexandru AlexMari Data 29 aprilie 2022 11:20:45
Problema Energii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");

long long n, g, ans, dp[100005];

int main()
{
    ans = LLONG_MAX;
    fin >> n >> g;
    for (long long i = 1; i <= n; i++) {
        long long x, y;
        fin >> x >> y;
        for (long long j = 10000 - x; j >= 0; j--)
            dp[j + x] = max(dp[j + x], dp[j] + y);
    }

    for (long long i = g; i <= 10000; i++)
        ans = min(ans, dp[i]);
    fout << ans;
}