#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Store{
double weight;
double price;
};
bool Compare(Store a,Store b){
return a.price/a.weight < b.price/b.weight;
}
int main(){
double m;
int n;
while(scanf("%lf%d",&m,&n) != EOF){
if(m==-1 && n == -1){
break;
}
Store sto[n];
for(int i = 0;i < n; i++){
scanf("%lf%lf",&sto[i].weight,&sto[i].price);
}
sort(sto,sto + n,Compare);
double weight= 0;
double sumprice= 0;
for(int i = 0;i < n;i++){
if(sumprice + sto[i].price > m){//不够买全部 只能买部分了
weight += (sto[i].weight/sto[i].price) * (m - sumprice);//单价可买重量*剩下的钱
break;
}
sumprice += sto[i].price;
weight += sto[i].weight;
}
printf("%.3lf\n",weight);
}
return 0;
}
FatMouse‘ Trade
最新推荐文章于 2021-03-06 15:14:41 发布