Pagini recente » Cod sursa (job #1112318) | Cod sursa (job #795903) | Cod sursa (job #2118776) | Cod sursa (job #345787) | Cod sursa (job #277669)
Cod sursa(job #277669)
#include<stdio.h>
long nrg,pwn,engcrt,costcrt,costmin,eng[1005],cost[5005];
long i,j;
int main(){
FILE *f = fopen("energii.in","r");
FILE *g = fopen("energii.out","w");
costmin = 50009;
fscanf(f,"%ld%ld",&nrg,&pwn);
for(i=1;i<=nrg;i++){
fscanf(f,"%ld%ld",&eng[i],&cost[i]);
}
for(i=1;i<=nrg;i++){
engcrt = eng[i];
costcrt = cost [i];
for(j=i+1;j<=nrg;j++){
if(eng[j]>=pwn) {
if(cost[j]<costmin)
costmin = cost[j];
}else{
engcrt +=eng[j];
costcrt += cost[j];
if(engcrt >= pwn){
if(costcrt<costmin)
costmin = costcrt;
if(costcrt>costmin){
engcrt = eng[i] + eng[j];
costcrt = cost[i] + cost[j];
}
}
}
}
}
fprintf(g,"%ld",costmin);
fclose(f);
fclose(g);
return 0;
}