2续hdu1009
#include<iostream>
#include<algorithm>
using namespace std;
struct Food
{
double x,y;
}food[1005];
int cmp(Food i,Food j)
{
return i.x*j.y>j.x*i.y;
}
int main()
{
double s,m;
int i,M,N;
while(scanf("%d%d",&M,&N)!=EOF&&(M>=0&&N>=0))
{
for(i=0;i<N;i++)
scanf("%lf%lf",&food[i].x,&food[i].y);
sort(food,food+N,cmp);
s=0;
m=M*1.0;
for(i=0;i<N;i++)
{
if(m>food[i].y){s +=food[i].x;m=m-food[i].y; }
else {s +=m*food[i].x/food[i].y; break;}
}
printf("%.3lf\n",s);
}
return 0;
}