Pagini recente » Cod sursa (job #2870409) | Cod sursa (job #49257) | Cod sursa (job #2914674)
#include <fstream>
using namespace std;
const int MAX_G = 1e3;
const int MAX_W = 5 * 1e3;
int dp[MAX_W + 1];
int g, w;
int main() {
ifstream fin("energii.in");
ofstream fout("energii.out");
fin >> g >> w;
for (int i = 1; i <= MAX_W; i++) {
dp[i] = (1 << 30);
}
dp[0] = 0;
for (int i = 1; i <= g; i++) {
int a, b;
fin >> a >> b;
for (int j = MAX_G; j >= 1; j--) {
if (j >= a) {
dp[j] = min(dp[j], dp[j - a] + b);
} else {
dp[j] = min(dp[j], b);
}
}
}
if (dp[w] == (1 << 30)) {
fout << "-1";
} else {
fout << dp[w];
}
return 0;
}