Cod sursa(job #2433338)
Utilizator | Gabor Ioana Ioana_Gabor | Data | 26 iunie 2019 21:56:12 |
---|---|---|---|
Problema | Energii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <iostream>
#include <fstream>
#define GMAX 1000
#define VMAX 5000
#define MAXVAL (1LL<<31)-1
using namespace std;
ifstream f("energii.in");
ofstream g("energii.out");
int ng,w,e,c,cost[VMAX+5];
int main(){
f>>ng>>w;
for(int i=1;i<=w;i++){
cost[i]=MAXVAL;
}
for(int i=1;i<=ng;i++){
f>>e>>c;
for(int j=w;j>=0;j--){
if(cost[j]!=MAXVAL){
cost[min(j+e,w)]=min(cost[min(j+e,w)],cost[j]+c);
}
}
}
if(MAXVAL==cost[w]){
g<<-1;
}else{
g<<cost[w];
}
f.close();
g.close();
}