Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long double ld;
- const ld EPS = 1e-7;
- int T;
- int n;
- vector<ld> x, t;
- ld cost(ld pos){
- ld mx = 0;
- for(int i=0; i<n; i++){
- // cout << "x[i]: " << x[i] << ", t[i]: " << t[i] << '\n';
- mx = max(mx, t[i]+abs(x[i]-pos));
- }
- return mx;
- }
- int main(){
- // freopen("meetonline.in", "r", stdin);
- // freopen("meetonline1.out", "w", stdout);
- cin >> T;
- while(T--){
- cin >> n;
- // vector<ld> x(n), t(n);
- x.resize(n, 0);
- t.resize(n, 0);
- for(int i=0; i<n; i++){
- cin >> x[i];
- // cout << x[i] << " ";
- }
- // cout << '\n';
- for(int i=0; i<n; i++){
- cin >> t[i];
- // cout << t[i] << " ";
- }
- // cout << '\n';
- ld lo = 0, hi = 1e8;
- for(int v=0; v<100; v++){
- ld m1 = lo+(hi-lo)/3;
- ld m2 = hi-(hi-lo)/3;
- // cout << "v: " << v << ", lo: " << lo << ", hi: " << hi << ", m1: " << m1 << ", m2: " << m2 << '\n';
- // cout << "cm1: " << cost(m1) << ", cm2: " << cost(m2) << '\n';
- if(cost(m1)<cost(m2)){
- hi = m2;
- }else{
- lo = m1;
- }
- }
- cout << fixed << setprecision(10) << (lo+hi)/2 << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement