Mai intai trebuie sa te autentifici.
Cod sursa(job #2793929)
Utilizator | Data | 4 noiembrie 2021 09:34:34 | |
---|---|---|---|
Problema | Energii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 1.02 kb |
#include <bits/stdc++.h>
using namespace std;
int g;
int w,sum=0;
int mn[10001];
int nou[10001];
int main() {
freopen ("energii.in", "r", stdin);
freopen ("energii.out", "w", stdout);
cin >> g;
mn[0] = 0;
for (int i = 1; i < 10001; i++) {
mn[i] = 1e9;
}
cin >> w;
for (int i = 1; i <= g; i++) {
int e, p;
cin >> e >> p;
sum = sum+e;
for (int j = 0; j < 10001; j++) {
nou[j] = mn[j];
if (j >= e) {
int potential = mn[j - e] + p;
if (potential < nou[j]) {
nou[j] = potential;
}
}
}
for (int j = 0; j < 10001; j++) {
mn[j] = nou[j];
}
}
/// mn[consum total] = cat mai mic posibil
/// conum total >= w
int solutie = 1e9;
for (int consumtotal = w; consumtotal < 10001; consumtotal++) {
int pret = mn[consumtotal];
if (pret < solutie) {
solutie = pret;
}
}
if (sum < w)
{
cout<<-1;
}
else
{
cout << solutie << "\n";
}
}