-
Notifications
You must be signed in to change notification settings - Fork 0
/
1070.cpp
57 lines (47 loc) · 828 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdio>
#include <algorithm>
using namespace std;
struct moonCake
{
double storage; // 库存量
double sell; // 总售价
double price;// 单价
};
moonCake cakes[1001];
bool cmp(moonCake &c1, moonCake &c2)
{
return c1.price > c2.price;
}
int main()
{
int n, d;
scanf("%d%d", &n, &d);
for (int i = 0; i < n; i++)
{
scanf("%lf",&cakes[i].storage);
}
for (int i = 0; i < n; i++)
{
scanf("%lf", &cakes[i].sell);
cakes[i].price = cakes[i].sell / cakes[i].storage;
}
sort(cakes, cakes + n, cmp);
double profit = 0;
for (int i = 0; i < n; i++)
{
if (cakes[i].storage <= d)
{
profit += cakes[i].sell;
d = d - cakes[i].storage;
//if (d == 0)
// break;
}
else //cakes[i].storage > d
{
profit += d*cakes[i].price;
break;
}
}
printf("%.2f", profit);
return 0;
}