#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int price,weight;
}stu[1100];
bool cmp(node x,node y)
{
return x.price<y.price;
}
int main()
{
int C,n,m,i,num;
double sum;
scanf("%d",&C);
while(C--)
{
sum=0;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++)
{
scanf("%d%d",&stu[i].price,&stu[i].weight);
}
sort(stu+1,stu+m+1,cmp);
for(i=1;i<=m;i++)
{
num=stu[i].price*stu[i].weight;
if(n>=num)
{
n-=num;
sum+=stu[i].weight;
}
else
{
sum+=1.0*n/num*stu[i].weight;
break;
}
}
printf("%.2f\n",sum);
}
return 0;
}
杭电2187
最新推荐文章于 2020-12-20 02:14:02 发布