Pagini recente » Cod sursa (job #7479) | Cod sursa (job #1028899) | Cod sursa (job #1091004) | Cod sursa (job #728816) | Cod sursa (job #3241332)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int MAX_NUM = 1e3;
const int MAX_W = 5e3;
int g, w, e[MAX_NUM], c[MAX_NUM];
vector<int> minCost(MAX_W, INT_MAX);
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
fin >> g >> w;
for (int i = 0; i < g; ++i) {
fin >> e[i] >> c[i];
}
minCost[0] = 0;
for (int i = 0; i < g; ++i) {
for (int j = w - 1; j >= 0; --j) {
if (minCost[j] != INT_MAX) {
int currentW = min(e[i] + j, w);
minCost[currentW] = min(minCost[currentW], minCost[j] + c[i]);
}
}
}
if (minCost[w] != INT_MAX) {
fout << minCost[w];
} else {
fout << -1;
}
return 0;
}