Pagini recente » Cod sursa (job #2715129) | Cod sursa (job #3155604) | Cod sursa (job #619018) | Cod sursa (job #2269133) | Cod sursa (job #2895602)
#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;
}