#include <bits/stdc++.h>
using namespace std;
#define MXN 1001
int m,n;
double ans,m2;
struct node{
int f,j;
double jf;
}r[MXN];
bool cmp(node x,node y){
return x.jf>y.jf;
}
int main()
{
while(scanf("%d %d",&m,&n)!=EOF){
if(m==-1&&n==-1)
break;
for(int i=1;i<=n;i++){
scanf("%d %d",&r[i].j,&r[i].f);
r[i].jf=1.0*r[i].j/r[i].f;
}
sort(r+1,r+n+1,cmp);
ans=0;m2=m;
for(int i=1;i<=n&&m2>0;i++){
if(m2>=r[i].f)
ans+=r[i].j,m2-=r[i].f;
else
ans+=r[i].j*m2/r[i].f,m2=0;
}
printf("%.3lf\n",ans);
}
return 0;
}
hdu 1009
最新推荐文章于 2024-09-07 14:26:30 发布