按性价比由高到底排序
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct P {
float m;
float p;
float pp;
};
int cmp(P a, P b) {
return a.pp > b.pp;
}
int main() {
int n, m;
cin >> n >> m;
P moonc[n];
for(int i=0; i<n; i++) {
cin>> moonc[i].m;
}
for(int i=0; i<n; i++) {
cin>> moonc[i].p;
moonc[i].pp = moonc[i].p/moonc[i].m;
}
sort(moonc, moonc+n, cmp);
/* for(int i=0; i<n; i++) {
moonc[i].pp = moonc[i].p/moonc[i].m;
cout << moonc[i].pp << "=" << moonc[i].p<<"/" <<moonc[i].m << endl;
}
*/
float ans=0;
for(int i=0; i<n; i++) {
if(m-moonc[i].m>0) {
ans+=moonc[i].p;
m -= moonc[i].m;
} else {
ans += moonc[i].pp*(m);
break;
}
}
printf("%.2f\n", ans);
return 0;
}