提交时间:2026-04-11 20:07:55

运行 ID: 436149

#include<bits/stdc++.h> using namespace std; int main(){ int m; cin>>m; for(int i=1;i<=m;i++){ int x,n,s=0; cin>>x>>n; int a[10086],b[10086],c[10086]; for(int j=1;j<=n;j++){ cin>>a[j]>>b[j]; c[j]=1.0*b[j]/a[j]; } sort(c+1,c+n+1,greater); for(int j=1;j<=n;j++){ if(x<=0){ break; } if(x>0&&x>=a[j]){ x-=a[j]; s+=a[j]*c[j]; }else{ s+=x*c[j]; } } cout<<fixed<<setprecision(1)<<s<<endl; } return 0; }