-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1020.cpp
49 lines (45 loc) · 855 Bytes
/
1020.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
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
int N, D;
struct T
{
int a, b;
float c;
};
bool cmp(const T &a, const T &b)
{
return a.c > b.c;
}
int main()
{
// freopen("1020.in", "r", stdin);
cin >> N >> D;
T a[N];
for (int i = 0; i < N; ++i)
cin >> a[i].a;
for (int i = 0; i < N; ++i)
cin >> a[i].b;
for (int i = 0; i < N; ++i)
a[i].c = a[i].b * 1.0 / a[i].a;
sort(a, a + N, cmp);
float total = 0;
for (int i = 0; i < N; ++i)
{
if (D >= a[i].a)
{
total += a[i].b;
D -= a[i].a;
}
else if (D < a[i].a && D > 0)
{
total += D * a[i].c;
D = 0;
}
else
break;
}
cout << fixed << setprecision(2) << total;
return 0;
}