#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct st
{
double f,m;
double v;
};
int cmp(st a,st b)
{
return a.v>b.v;
}
int main()
{
st a[100];
int M,n;
while(scanf("%d%d",&M,&n),n>0)
{
//if(M==-1&&n==-1) break;
for(int i=0;i<n;i++)
{
cin>>a[i].f>>a[i].m;
a[i].v=a[i].f/a[i].m;
}
sort(a,a+n,cmp);
double s=0;
for(int i=0;i<n;i++)
{
if(M<=0) break;
else if(M>=a[i].m)
{
s+=a[i].f;//cout<<max<<endl;
M-=a[i].m;//cout<<"ok"<<endl;
}
else
{
s+=M*a[i].v;
M-=a[i].f;
}
}
printf("%.3lf\n",s);
}
return 0;
}
/***************************************************
User name: TJRAC6015203228魏杰
Result: Accepted
Take time: 0ms
Take Memory: 164KB
Submit time: 2016-11-01 13:20:13
****************************************************/
sdut2278商人的诀窍
最新推荐文章于 2020-04-26 19:03:56 发布