#include <algorithm>
#include <iostream>
using namespace std;
struct node
{
int cost,weight;
};
int cmp (node a, node b)
{
return a.weight<b.weight;
}
int main()
{
int n;
int kinds,i;
double ans,temp,money;
node data[1000];
scanf("%d",&n);
while(n--)
{
ans=0;
scanf("%lf%d",&money,&kinds);
for(i=0;i<kinds;i++)
scanf("%d%d",&data[i].cost,&data[i].weight);
sort(data,data+kinds,cmp);
for(i=0;i<kinds;i++)
{
if(money>=data[i].cost*data[i].weight)
{
ans+=(double)data[i].weight;
money-=(double)data[i].cost*data[i].weight;
}
else
{
temp=(double)money/data[i].cost;
ans+=temp;
money-=(double)temp*data[i].cost;
}
}
printf("%.2lf\n",ans);
}
return 0;
}
如果把排序改成qsort的话,就可以通过,不知道为什么