-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1070.cpp
More file actions
37 lines (36 loc) · 672 Bytes
/
1070.cpp
File metadata and controls
37 lines (36 loc) · 672 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
#include <bits/stdc++.h>
using namespace std;
struct mooncake{
double weight, tprice, price;
friend bool operator<(const mooncake &a, const mooncake &b){
return a.price > b.price;
}
};
int main(){
ios::sync_with_stdio(false);
int n, d;
cin>>n>>d;
vector<mooncake> v(n);
for(int i=0; i<n; i++){
cin>>v[i].weight;
}
for(int i=0; i<n; i++){
cin>>v[i].tprice;
v[i].price = v[i].tprice / v[i].weight;
}
sort(v.begin(), v.end());
double sell = 0;
int i = 0;
while(d && i<n){
if(v[i].weight <= d){
sell += v[i].tprice;
d -= v[i].weight;
}else{
sell += v[i].price * d;
d = 0;
}
i++;
}
cout<<fixed<<setprecision(2)<<sell;
return 0;
}