提交时间:2023-12-26 21:01:56

运行 ID: 35135

#include<iostream> #include<iomanip> #include<algorithm> using namespace std; struct s{ int w; double all,money; }a[10005]; 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); for(int j=1;j<=s;j++){ if(wl>=a[j].w){ wl-=a[j].w; ans+=a[j].all; } else { ans+=a[j].all/a[j].w*wl; } if(wl=0) break; } cout<<fixed<<setprecision(2)<<ans; cout<<endl; } return 0; }