Pagini recente » Cod sursa (job #2913552) | Cod sursa (job #2981672)
#include <iostream>
using namespace std;
const int NMAX = 1000, WMAX = 5000;
int n, w, dp[WMAX + 5];
//dp[i] = costul minim pentru generarea energiei i
int main()
{
freopen("energii.in", "r", stdin);
freopen("energii.out", "w", stdout);
scanf("%d%d", &n, &w);
for(int i = 0; i <= w; ++i)
dp[i] = 1e9;
for(int i = 1, energ, cost; i <= n; ++i) {
scanf("%d%d", &energ, &cost);
for(int j = w; j; --j) {
if(j <= energ) dp[j] = min(dp[j], cost);
else dp[j] = min(dp[j], dp[j - energ] + cost);
}
}
printf("%d", dp[w] == 1e9 ? -1 : dp[w]);
return 0;
}