#include <bits/stdc++.h> using namespace std; int main(){ int k; cin>>k; for(int x = 1;x<=k;x++){ int w,s; cin>>w>>s; double n[s+5],v[s+5]; double sum = 0; for(int i = 1;i<=s;i++){ cin>>n[i]>>v[i]; } for(int i = 1;i<s;i++){ for(int j = i+1;j<=s;j++){ if(v[i]/n[i]<v[j]/n[j]){ swap(v[i],v[j]); swap(n[i],n[j]); } } } for(int i = 1;i<=s;i++){ cout<<n[i]<<" "<<v[i]<<endl; } int i = 1; while(w>0){ if(w>n[i]){ sum += v[i]; w -= n[i]; }else{ sum += w/n[i]*v[i]; w = 0; } } cout<<sum<<endl; } return 0; }
标签:std,int,double,sum,111,main From: https://www.cnblogs.com/wangyihang-xh/p/18475989