Pagini recente » Cod sursa (job #2481419) | Cod sursa (job #2557341) | Cod sursa (job #3261132) | Cod sursa (job #3204867) | Cod sursa (job #3184497)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("date.in");
ofstream fout ("date.out");
int main()
{
int n,m;
double s=0;
cin>>n>>m;
int a[10001],b[10001];
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i];
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(b[i]*a[j]<b[j]*a[i])
{
swap(a[i],a[j]);
swap(b[i],b[j]);
}
}
}
int j=1;
while(m-a[j]>=0 && j<=n)
{
m-=a[j];
s+=b[j];
++j;
}
if(j<=n)
s+=(float )m*b[j]/a[j];
cout<<s;
return 0;
}