-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMooncake.cpp
50 lines (47 loc) · 931 Bytes
/
Mooncake.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
39
40
41
42
43
44
45
46
47
48
49
50
#include <algorithm>
#include <iomanip>
#include <iostream>
struct Mooncake
{
double amant;
double totalp;
double price;
};
Mooncake m[1010];
bool cmp(Mooncake a, Mooncake b)
{
return a.price > b.price;
}
int main()
{
int n, d;
std::cin >> n >> d;
for (int i = 0; i < n; i++)
{
std::cin >> m[i].amant;
}
for (int i = 0; i < n; i++)
{
std::cin >> m[i].totalp;
m[i].price = m[i].totalp / m[i].amant;
}
std::sort(m, m + n, cmp);
double total = 0;
for (int i = 0; i < n; i++)
{
if (d >= m[i].amant)
{
d -= m[i].amant;
total += m[i].totalp;
}
else if (d < m[i].amant)
{
total += d * m[i].price;
d = 0;
}
if (d == 0)
break;
}
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << total;
return 0;
}