Pagini recente » Cod sursa (job #1676821) | Cod sursa (job #2926206) | Cod sursa (job #3295086) | Cod sursa (job #301060) | Cod sursa (job #2691381)
#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;
in >> n >> w;
for (int i = 1; i <= w; ++i)
cost[i] = -1;
while (n--) {
in >> e >> c;
for (int i = w - 1; i >= 0; --i)
if (cost[i] >= 0) {
if (cost[min(w, i + e)] == -1)
cost[min(w, i + e)] = cost[i] + c;
else
cost[min(w, i + e)] = min(cost[min(w, i + e)], cost[i] + c);
}
}
out << cost[w];
in.close();
out.close();
return 0;
}