样例已过,第一个点WA……
#include <bits/stdc++.h>
using namespace std;
struct gold{
int m, v;
}a[110];
bool cmp(gold x, gold y){
return x.v * y.m > y.v * x.m;
}
int main(){
int n, t, c;
cin >> n >> t;
double ans = 0;
c = t;
for(int i = 0;i < n;i++){
cin >> a[i].m >> a[i].v;
}
sort(a, a + n, cmp);
int k;
for(int i = 0;i < n;i++){
if(a[i].m > c){
k = i;
break;
}
c -= a[i].m;
ans += a[i].v;
}
if(k < n){
ans += 1.0 * c / a[k].m * a[k].v;
}
cout << fixed << setprecision(2) << ans;
return 0;
}
然而把cout << fixed << setprecision(2) << ans;
改成printf("%.2lf", ans);
后第一个点从WA变成了RE…………
求大佬指教