-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathA1070.cpp
More file actions
40 lines (37 loc) · 750 Bytes
/
A1070.cpp
File metadata and controls
40 lines (37 loc) · 750 Bytes
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
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 1000 + 10;
int N;
double D;
struct Mooncake{
double amt, price, unit;
} mooncake[MAXN];
bool cmp(const Mooncake &m1, const Mooncake &m2){
return m1.unit > m2.unit;
}
int main(){
scanf("%d%lf", &N, &D);
for(int i = 0; i < N; ++i){
scanf("%lf", &mooncake[i].amt);
};
for(int i = 0; i < N; ++i){
scanf("%lf", &mooncake[i].price);
mooncake[i].unit = mooncake[i].price / mooncake[i].amt;
}
sort(mooncake, mooncake+N, cmp);
int idx = 0;
double ans = 0;
while(D > 0){
if(mooncake[idx].amt <= D){
ans += mooncake[idx].price;
D -= mooncake[idx].amt;
}else{
ans += mooncake[idx].unit * D;
D = 0;
}
++idx;
}
printf("%.2lf", ans);
return 0;
}