Pagini recente » Cod sursa (job #2919946) | Cod sursa (job #1256131) | Clasament oji_simulare_2017_cl10 | Cod sursa (job #1517294) | Cod sursa (job #778801)
Cod sursa(job #778801)
#include<stdio.h>
double v[1002],et[1002],wt[1002];
int main(){
freopen("energii.in","r",stdin);
freopen("energii.out","w",stdout);
int t,w,i,e=0,c=0,max,maxi;
double x,y,total=0;
scanf("%d%d",&t,&w);
for(i=1;i<=t;i++){
scanf("%lf%lf",&x,&y);
et[i]=x;
total+=x;
wt[i]=y;
v[i]=x/y;
}
if(total<w){
printf("-1\n");
}
if(total>=w){
while(e<w){
max=-1;
maxi=-1;
for(i=1;i<=t;i++){
if(v[i]>max){
max=v[i];
maxi=i;
}
}
e+=et[maxi];
c+=wt[maxi];
v[maxi]=-1;
}
printf("%d\n",c);
}
}