3 20
18 15 10
75 72 45

94.50

# 代码

## C++解法

```#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
const int maxn = 1005;
const double eps = 1e-9;

struct Node {
double w, p;
double getPrice() const { return p / w; }
bool operator<(const Node &rhs) const {
return getPrice() > rhs.getPrice();
}
};
Node goods[maxn];

int sgn(double n) { return fabs(n) < eps ? 0 : n > 0 ? 1 : -1; }
int double_round(double n) { return sgn(n) > 0 ? n + 0.5 : n - 0.5; }

int main() {
int n, D;
scanf("%d%d", &n, &D);
for (int i = 0; i < n; ++i)
scanf("%lf", &goods[i].w);
for (int i = 0; i < n; ++i)
scanf("%lf", &goods[i].p);
sort(goods, goods + n);

double ans = 0.0;
for (int i = 0; i < n && D > 0; ++i) {
if (D >= goods[i].w) {
ans += goods[i].p;
D -= goods[i].w;
} else {
ans += goods[i].getPrice() * D;
D = 0;
}
}
printf("%.2f\n", (double)double_round(ans * 100) / 100);
return 0;
}
```

## Python解法

```(n, D) = [int(i) for i in input().split(" ")]
w = [float(i) for i in input().split(" ")]
p = [float(i) for i in input().split(" ")]
node = [(w[i], p[i]) for i in range(n)]
node.sort(key=lambda x: x[1] / x[0], reverse=True)
ans = 0.0
for i in range(n):
if D >= node[i][0]:
ans += node[i][1]
D -= node[i][0]
else:
ans += D * node[i][1] / node[i][0]
D = 0
if D == 0:
break
print("%.2f" % (round(ans * 100) / 100))

```