其实好多同学说D是int,测试点2 3其实有数据是double。人家单位不是1,是thousand tons,那1.23 * 1000 = 1230啊。自己不仔细看题乱喷真的是。。。
#include <bits/stdc++.h>
using namespace std;
struct node {
double price, num, totalP;
};
vector<node> v;
bool cmp (node a, node b) {
return a.price > b.price;
}
int main() {
double num, price, ans = 0.0, d;
int n;
scanf ("%d %lf", &n, &d);
v.resize(n);
for (int i = 0; i < n; i++) scanf ("%lf", &v[i].num);
for (int i = 0; i < n; i++) {
scanf ("%lf", &v[i].totalP);
v[i].price = v[i].totalP / v[i].num;
}
sort (v.begin(), v.end(), cmp);
for (int i = 0; i < n; i++) {
if (d >= v[i].num) {
d -= v[i].num;
ans += v[i].totalP;
}
else {
ans += v[i].price * d;
break;
}
}
printf ("%.2lf", ans);
}