Pagini recente » Statistici tudorlovin (tudorlovin) | Xmoto | Clasament Grigore Moisil 2009, clasa a 10a | Istoria paginii utilizator/doru.nitu | Cod sursa (job #3294443)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
#define cin fin
#define cout fout
#define int long long
const int WMAX = 5007;
const int INF = 1e9;
int dp[WMAX];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, w;
cin >> n >> w;
for (int i = 0; i < WMAX; ++i)
{
dp[i] = INF;
}
dp[0] = 0;
int answer = INF;
for (int i = 0; i < n; ++i)
{
int energy, cost;
cin >> energy >> cost;
for (int j = w - 1; j >= 0; --j)
{
if (dp[j] != INF)
{
dp[j + energy] = min(dp[j + energy], dp[j] + cost);
if (j + energy >= w)
{
answer = min(dp[j + energy], answer);
}
}
}
}
fout << (dp[w] == INF ? -1 : answer);
return 0;
}