Pagini recente » Cod sursa (job #174778) | Cod sursa (job #1654532) | Cod sursa (job #3320295) | Cod sursa (job #3320920) | Cod sursa (job #3324823)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int WMAX = 20000;
const int INF = 1e9;
int dp[WMAX + 1]; // cost minim pentru energia exactă j
int main() {
int n, wmax;
fin >> n >> wmax;
fill(dp, dp + WMAX + 1, INF);
dp[0] = 0;
for(int i = 1; i <= n; i++) {
int en, ct;
fin >> en >> ct;
for(int j = WMAX; j >= en; j--) { // 0/1 knapsack
dp[j] = min(dp[j], dp[j - en] + ct);
}
}
int ans = INF;
for(int j = wmax; j <= WMAX; j++) {
ans = min(ans, dp[j]);
}
fout << (ans == INF ? -1 : ans) << "\n";
return 0;
}