-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
46 lines (36 loc) · 1003 Bytes
/
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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const long double eps = 1e-6;
int main(){
fast;
ll n;
cin>>n;
ld coordinates[n], velocity[n];
for(ll i=0;i<n;i++)
cin>>coordinates[i];
for(ll i=0;i<n;i++)
cin>>velocity[i];
ld l=0, r=10000000000;
while((r-l)>eps){
ld t = (l+r)/2.0;
ld mx = coordinates[0] + velocity[0]*t;
ld mn = coordinates[0] - velocity[0]*t;
ll flag=0;
for(ll i=1;i<n;i++){
ld temp_mx = coordinates[i] + velocity[i]*t;
ld temp_mn = coordinates[i] - velocity[i]*t;
mx = min(mx, temp_mx);
mn = max(mn, temp_mn);
}
if(mn<=mx)
r = t;
else
l = t;
}
cout<<fixed<<setprecision(6)<<r<<endl;
return 0;
}