Cod sursa(job #2895602)
Utilizator | Marinescu Alexandru AlexMari | Data | 29 aprilie 2022 11:44:35 |
---|---|---|---|
Problema | Energii | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.65 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 (int i = 1; i <= g - 1; i++) {
dp[i] = LLONG_MAX;
}
for (long long i = 1; i <= n; i++) {
long long x, y;
fin >> x >> y;
for (int j = g - 1; j >= 0; j--) {
if (dp[j] == LLONG_MAX)
continue;
if (j + x >= g)
ans = min(ans, dp[j] + y);
else
dp[j + x] = min(dp[j + x], dp[j] + y);
}
}
fout << ans;
}