Pagini recente » Cod sursa (job #856566) | Cod sursa (job #403729) | Cod sursa (job #1045929) | Cod sursa (job #1101552) | Cod sursa (job #3352969)
#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
#define inf INT_MAX
const int gmax = 1005; // generatorare
const int wmax = 15005; // energie
int e[gmax], c[gmax];
int dp[wmax];
int g, w;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> g >> w;
for(int i = 1; i <= g; i ++) {
cin >> e[i] >> c[i];
}
for(int j = 0; j < wmax; j++) {
dp[j] = inf;
}
dp[0] = 0;
for(int i = 1; i <= g; i ++) {
for(int j = w; j >= 1; j--) {
if(j > e[i]) {
dp[j] = min(dp[j], dp[j - e[i]] + c[i]);
} else {
dp[j] = min(dp[j], c[i]);
}
}
}
if(dp[w] == inf) cout << -1;
else cout << dp[w];
return 0;
}