Pagini recente » Cod sursa (job #3202809) | Cod sursa (job #930922) | Cod sursa (job #2931284) | Cod sursa (job #1955447) | Cod sursa (job #2212182)
#include <iostream>
#include <fstream>
#define DMAX 1000000001
using namespace std;
ifstream in("energii.in");
ofstream out("energii.out");
int g, energCeruta, energie[1010], cost[1010];
int castig[3][5010];
void citire(){
in >> g >> energCeruta;
for(int i = 1; i <= g; i++){
in >> energie[i] >> cost[i];
}
in.close();
}
void intializare(){
for(int i = 1; i <= energCeruta; i++){
castig[1][i] = DMAX;
}
}
void rezolvare(){
for(int i = 1; i <= g; i++){
for(int j = 0; j <= energCeruta; j++) {
if(energie[i] >= j){
castig[2][j] = min(castig[1][j], cost[i]);
}else{
castig[2][j] = min(castig[1][j], castig[1][j - energie[i]] + cost[i]);
}
}
for(int j = 1; j <= energCeruta; j++){
castig[1][j] = castig[2][j];
}
}
out << castig[2][energCeruta];
}
int main() {
citire();
intializare();
rezolvare();
return 0;
}