提交时间:2023-12-26 21:30:37

运行 ID: 35139

#include<iostream> #include<iomanip> #include<algorithm> using namespace std; struct s{ int w; double all,money; }a[10010]; bool cmp(s A,s B){ return A.money>B.money; } double ans; int n,wl,s; int main(){ cin>>n; for(int i=1;i<=n;i++){ ans=0.0; cin>>wl>>s; for(int j=1;j<=s;j++){ cin>>a[j].w>>a[j].all; a[i].money=a[j].all/a[j].w; } sort(a+1,a+1+s,cmp); int k=1; while((wl-a[k].w)>=0&&k<=s){ ans+=a[k].all; wl-=a[k].w; k++; } ans+=a[k].money*wl; cout<<fixed<<setprecision(2)<<ans; cout<<endl; } return 0; }