Pagini recente » Diferente pentru training-path intre reviziile 132 si 21 | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2408129) | Cod sursa (job #3310261)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("energii.in");
ofstream fout ("energii.out");
int main () {
int n, g;
fin >> n >> g;
vector<int> dp (g + 1, 1e9);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
int valoare, cost;
fin >> valoare >> cost;
for (int j = g - 1; j >= 0; --j) {
if (dp[j] != 1e9) {
int k = j + valoare;
if (k > g)
k = g;
dp[k] = min (dp[k], dp[j] + cost);
}
}
}
if (dp[g] == 1e9)
fout << -1;
else
fout << dp[g];
return 0;
}