Cod sursa(job #2691381)
Utilizator | Data | 28 decembrie 2020 14:19:32 | |
---|---|---|---|
Problema | Energii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.67 kb |
#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;
}