-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1020.cpp
More file actions
48 lines (39 loc) · 722 Bytes
/
1020.cpp
File metadata and controls
48 lines (39 loc) · 722 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
41
42
43
44
45
46
47
48
#include<iostream>
#include<algorithm>
using namespace std;
struct goods{
float num;
float price;
float dj;
};
bool cmp(goods a, goods b){ return a.dj > b.dj; }
int main(){
int n, max;
cin >> n >> max;
goods *cake = new goods[n];
for (int i = 0; i < n; i++){
cin >> cake[i].num;
}
for (int i = 0; i < n; i++){
cin >> cake[i].price;
}
for (int i = 0; i < n; i++){
cake[i].dj = cake[i].price / cake[i].num;
}
sort(cake, cake + n, cmp);
float earn=0;
for (int i = 0; i < n; i++){
if (cake[i].num <= max)
{
earn = earn + cake[i].num*cake[i].dj;
}
else{
earn = earn + max*cake[i].dj;
break;
}
max = max - cake[i].num;
}
printf("%.2f",earn);
system("pause");
return 0;
}