-
Notifications
You must be signed in to change notification settings - Fork 1
/
B.cpp
61 lines (44 loc) · 1.03 KB
/
B.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
50
51
52
53
54
55
56
57
58
59
60
61
// http://codeforces.com/contest/782/problem/B
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
typedef long double ld;
const ld EPS = 1e-9;
int cmp (ld x, ld y = 0, ld tol = EPS) {
return ( x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
bool f (ld t, vector<ld> &friends, vector<ld> &speed) {
ld L = -1, R = 1e100;
for (int i = 0; i < friends.size(); ++i) {
ld d = t * speed[i];
ld l = friends[i] - d;
ld r = friends[i] + d;
if (cmp(l, 0) < 0) l = 0;
if (cmp(l, L) > 0) L = l;
if (cmp(r, R) < 0) R = r;
}
return L <= R;
}
int main() {
int n;
cin >> n;
vector<ld> friends(n), speed(n);
for (int i = 0; i < n; ++i) cin >> friends[i];
for (int i = 0; i < n; ++i) cin >> speed[i];
ld lo = 0;
ld hi = 1e100;
ld mid;
while (cmp(lo, hi) < 0) {
mid = (lo + hi) / 2;
if (f(mid, friends, speed)) {
hi = mid;
}
else {
lo = mid;
}
}
cout << fixed << setprecision(20);
cout << hi << endl;
return 0;
}