#include
#include
#include<stdio.h>
using namespace std;
struct L{
int w;
int v;
double density;
};
int cmp(L a,L b)
{
return a.density<b.density;
}
int main()
{
int t,i,j,w,n;
double totw,totv;
cin>>t;
for(j=0; j<t; j++)
{
cin>>w>>n;
L a[n2];
for(i=0; i<n; i++)
{
cin>>a[i].w>>a[i].v;
a[i].density=1.0a[i].v/a[i].w;
}
sort(a,a+n,cmp);
totv=totw=0;
for(i=n-1; i>=0; --i)
{
if(totw+a[i].w<=w)
{
totw+=a[i].w;
totv+=a[i].v;
}
else
{
totv+=a[i].density*(w-totw);
totw=w;
break;
}
}
printf("%.2lf\n",totv);
}
return 0;
}
1308

被折叠的 条评论
为什么被折叠?



