#include<fstream>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Mouse
{
double J;
double F;
double a;
};
bool Comp(const Mouse &d1,const Mouse &d2)
{
if(d1.a!=d2.a)
return d1.a>d2.a;
else
return d1.F<d2.F;
}
int main()
{
//ifstream cin("acmilan.txt");
vector<Mouse> v;
Mouse mouse;
int m,n,i;
cout.precision(3);
double sum;
while(cin>>m>>n)
{
if(m==-1&&n==-1)
break;
v.clear();
sum=0.0;
for(i=0;i<n;i++)
{
cin>>mouse.J>>mouse.F;
mouse.a=mouse.J/mouse.F;
v.push_back(mouse);
}
sort(v.begin(),v.end(),Comp);
for(i=0;i<v.size();i++)
{
if(m>=v[i].F)
{
sum=sum+v[i].J;
m=m-v[i].F;
}
else
{
sum=sum+m*v[i].a;
break;
}
}
cout<<fixed<<sum<<endl;
}
//system("pause");
return 0;
}
ZOJ 2109 FatMouse' Trade
最新推荐文章于 2022-12-07 08:13:55 发布