Pagini recente » Cod sursa (job #2306881) | Cod sursa (job #223988) | Cod sursa (job #2140901) | Cod sursa (job #2560266) | Cod sursa (job #2091581)
#include <bits/stdc++.h>
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
#define INF 1e9 + 1
int dp[6010], n, w;
int main()
{
in >> n >> w;
for(int i = 1; i <= w; ++i)
dp[i] = INF;
for(int i = 1; i <= n; ++i) {
int energy, cost;
in >> energy >> cost;
for(int j = w - 1; j >= 0; --j) {
if(j + energy <= w && dp[j + energy] > dp[j] + cost)
dp[j + energy] = dp[j] + cost;
else
if(j + energy > w && dp[w] > dp[j] + cost)
dp[w] = dp[j] + cost;
}
}
if(dp[w] == INF)
out << -1;
else
out << dp[w];
in.close(); out.close();
return 0;
}