fork download
  1. /******************************************
  2. * AUTHOR : kevin_007 *
  3. ******************************************/
  4. #include <bits/stdc++.h>
  5. #include <ext/pb_ds/assoc_container.hpp>
  6. #include <ext/pb_ds/tree_policy.hpp>
  7. using namespace std;
  8. using namespace __gnu_pbds;
  9. #define Speed_UP ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  10. clock_t clk=clock();
  11. typedef long long ll;
  12. typedef long double ld;
  13. typedef pair<ld, ld> pt;
  14. #define vi vector<int>
  15. #define vll vector<ll>
  16. #define N 100005
  17. #define MOD 1000000007
  18. #define dd double
  19. #define rep(i, n) for(int i = 0; i < n; i++)
  20. #define repe(i,a,b) for(int i=a;i<b;i++)
  21. #define rep1(i,b) for(int i=1;i<=b;i++)
  22. #define pb push_back
  23. #define sz(x) ((int)(x).size())
  24. #define F first
  25. #define S second
  26. template<class T> using ordered_set = tree<T, null_type, less_equal<T>,
  27. rb_tree_tag,tree_order_statistics_node_update> ;
  28. // order_of_key (k) : Number of items strictly smaller than k .
  29. // find_by_order(k) : K-th element in a set (counting from zero).
  30.  
  31. pt func(pt a, pt b) {
  32. if(b.F>a.S or b.S<a.F) return {-1,-1};
  33.  
  34. return {max(a.F,b.F), min(a.S, b.S)};
  35. }
  36.  
  37. int solve(){
  38.  
  39. int n; cin>>n;
  40.  
  41. vll x(n), t(n); rep(i,n) cin>>x[i];
  42.  
  43. rep(i,n) cin>>t[i];
  44.  
  45. ld low=0, hi=MOD;
  46. ld mid;
  47. ll itr=30;
  48.  
  49. ld ans=0;
  50.  
  51. while(itr-- and low<=hi) {
  52. mid=(low+hi)/2;
  53.  
  54. bool ok=1;
  55.  
  56. pt full = {0, MOD};
  57.  
  58. rep(i,n) {
  59. if(mid<t[i]) {
  60. ok=0; break;
  61. }
  62.  
  63. // Here Changing ld to ll gives correct answer
  64. ld diff = mid - t[i];
  65.  
  66. pt temp = {x[i] - diff, x[i] + diff};
  67.  
  68. full = func(temp, full);
  69.  
  70. if(full.F==-1) {
  71. ok=0; break;
  72. }
  73. }
  74.  
  75. if(!ok) {
  76. low=mid;
  77. }
  78. else {
  79. hi=mid;
  80. ans = (full.F+full.S)/2.0;
  81. }
  82. }
  83.  
  84. cout<<setprecision(12) << fixed << ans<<"\n";
  85.  
  86. return 0;
  87. }
  88.  
  89. int main() {
  90. #ifndef ONLINE_JUDGE
  91. freopen("input.txt", "r", stdin);
  92. // freopen("output.txt", "w", stdout);
  93. #endif
  94. Speed_UP
  95.  
  96.  
  97. int t;
  98. cin>>t;
  99.  
  100. while(t--){
  101. solve();
  102. }
  103.  
  104. return 0;
  105.  
  106. }
Success #stdin #stdout 0.01s 5496KB
stdin
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
stdout
0.362645162269
2.000000000000
2.500000000000
2.000000000000
1.000000000000
3.000000000000
6.000000000000