-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1070.cpp
38 lines (36 loc) · 957 Bytes
/
1070.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Mooncake {
double stock;
double total_price;
double unit_price;
};
int main() {
int n;
double demand;
cin >> n >> demand;
vector<Mooncake> mooncakes(n);
for (int i = 0; i < n; i++)
cin >> mooncakes[i].stock;
for (int i = 0; i < n; i++) {
cin >> mooncakes[i].total_price;
mooncakes[i].unit_price = mooncakes[i].total_price / mooncakes[i].stock;
}
sort(mooncakes.begin(), mooncakes.end(), [](Mooncake a, Mooncake b) {
return a.unit_price > b.unit_price;
});
double answer = 0.0;
for (auto mooncake : mooncakes) {
if (mooncake.stock <= demand) {
demand -= mooncake.stock;
answer += mooncake.total_price;
} else {
answer += mooncake.unit_price * demand;
break;
}
}
printf("%.2f", answer);
return 0;
}