Pagini recente » Cod sursa (job #239104) | Cod sursa (job #1325616) | Cod sursa (job #2442282) | Cod sursa (job #1828793) | Cod sursa (job #2895606)
#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);
}
}
if (ans == LLONG_MAX)
fout << -1;
else
fout << ans;
}