Pagini recente » Cod sursa (job #2356483) | Istoria paginii teorema-chineza-a-resturilor | Cod sursa (job #117964) | Cod sursa (job #2474450) | Cod sursa (job #129271)
Cod sursa(job #129271)
#include <stdio.h>
FILE *in,*o;
int s,d,i,g,w;
long co;
float a,f[1003],e[1003],c[1003];
int main()
{
in=fopen("energii.in","r");
o=fopen("energii.out","w");
fscanf(in,"%d",&g);
fscanf(in,"%d",&w);
for (i=1;i<=g;i++)
{
fscanf(in,"%f%f",&e[i],&c[i]);
f[i]=c[i]/e[i];
}
d=0;
while (d==0)
{
d=1;
for (i=1;i<g;i++)
if (f[i]>f[i+1])
{
a=f[i];
f[i]=f[i+1];
f[i+1]=a;
a=e[i];
e[i]=e[i+1];
e[i+1]=a;
a=c[i];
c[i]=c[i+1];
c[i+1]=a;
d=0;
}
}
s=0;
for (i=1;i<=g && s<w;i++)
{
s=s+e[i];
co=co+c[i];
}
if (s>=w)
fprintf(o,"%d",co);
else fprintf(o,"-1");
fclose(in);
fclose(o);
return 0;
}