Pagini recente » Cod sursa (job #1148329) | Cod sursa (job #533663) | Cod sursa (job #2628925) | Cod sursa (job #3210349) | Cod sursa (job #255201)
Cod sursa(job #255201)
#include<fstream.h>
#include<math.h>
ifstream f("energii.in");
ofstream g("energii.out");
int gen,w,smin,i,j,emin,aux;
int a[1002],b[1002];
float c[1002];
int main ()
{
f>>gen>>w;
for(i=1;i<=gen;i++)
{f>>a[i]>>b[i];
c[i]=(float)a[i]/b[i];}
for(i=1;i<gen;i++)
for(j=i+1;j<=gen;j++)
if(c[i]<c[j])
{aux=a[i];
a[i]=a[j];
a[j]=aux;
aux=b[i];
b[i]=b[j];
b[j]=aux;
aux=c[i];
c[i]=c[j];
c[j]=aux;}
smin=0;
emin=0;
for(i=1;i<=gen;i++)
{emin=emin+a[i];
smin=smin+b[i];
if(emin>=w)
break;}
if(i<=gen)
g<<smin<<"\n";
else
g<<"-1"<<"\n";
f.close();
g.close();
return 0;
}