Pagini recente » Cod sursa (job #1696620) | Rating Sisu Anca (ancasisu) | Diferente pentru utilizator/_andrei__ intre reviziile 1 si 3 | Profil Octavian123 | Cod sursa (job #2349811)
#include <fstream>
using namespace std;
ifstream fin("energii.in");
ofstream fout("energii.out");
const int NMAX = 10001;
int op[NMAX], g, w, e, c, s;
int main() {
fin >> g >> w;
for(int i = 0; i <= w; ++i)
op[i] = NMAX;
for(int i = 1; i <= g; ++i) {
fin >> e >> c;
for(int j = w; j >= 1; --j)
e >= j ? op[j] = min(op[j], c) : op[j] = min(op[j], op[j - e] + c);
}
op[w] == NMAX ? fout << -1 : fout << op[w];
}