Pagini recente » Cod sursa (job #355846) | Cod sursa (job #157058) | Cod sursa (job #783553) | Profil VNohai | Cod sursa (job #277568)
Cod sursa(job #277568)
#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;
costcrt -= cost[j];
engcrt -= eng[j];
}
if(eng[i] + eng[j]>= pwn){
if(cost[i]+cost[j]<costmin)
costmin = cost[i]+cost[j];
}
}
}
}
fprintf(g,"%ld",costmin);
fclose(f);
fclose(g);
return 0;
}