Pagini recente » Cod sursa (job #2819059) | Cod sursa (job #1912355) | Cod sursa (job #1003613) | Cod sursa (job #348658) | Cod sursa (job #2691370)
#include <fstream>
using namespace std;
const int N = 5001;
int cost[N];
int main() {
ifstream in("energii.in");
ofstream out("energii.out");
int n, w, e, c, s = 0;
in >> n >> w;
for (int i = 1; i <= w; ++i)
cost[i] = -1;
while (n--) {
in >> e >> c;
s += e;
for (int i = w - 1; i >= 0; --i)
if (cost[i] >= 0) {
if (cost[max(w, i + e)] == -1)
cost[max(w, i + e)] = cost[i] + c;
else
cost[max(w, i + e)] = min(cost[i + e], cost[i] + c);
}
}
int rez = 1 << 30;
for (int i = w; i <= s; ++i)
if (cost[i] > 0)
rez = min(rez, cost[i]);
if (rez == 1 << 30)
out << -1;
else
out << rez;
in.close();
out.close();
return 0;
}