-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinflation.cpp
More file actions
48 lines (38 loc) · 940 Bytes
/
inflation.cpp
File metadata and controls
48 lines (38 loc) · 940 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
/*
* Author: Maanas Karwa
* It is ok to share my code anonymously for educational purposes
* */
#include <bits/stdc++.h>
#define ld long double
#define PRECISION(n) fixed << setprecision((n))
using namespace std;
int n;
int helium[200001];//store helium in each canister
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin.exceptions(std::istream::failbit);
ld ans = 1;
cin >> n;
for (int i = 1, tmp; i <= n; i++) {
cin >> tmp;
// if a canister is empty, a balloon will never be filled
if (tmp==0) {
ans = 0;
}
helium[i]=tmp;
}
sort(helium+1, helium + n+1);
for (int i = n; i>=1;i--) {
auto b = helium[i];
if (b > i) { // more in canister than corresponding balloon
cout << "impossible";
return 0;
} else if (b < i) {
ans = min(ans, (ld) b/(i) ); //fraction filled up
}
}
cout << PRECISION(10)<<ans;
}
#undef ld
#undef PRECISION