fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<pair<int,int>> a;
  25.  
  26. bool isPossible(int n, double mid){
  27.  
  28. double s = -1, e = -1;
  29. for(int i=0; i<n; i++){
  30. double x = a[i].first;
  31. double v = a[i].second;
  32.  
  33. double l = x-mid*v;
  34. double r = x+mid*v;
  35.  
  36. if(s==-1 && e==-1){
  37. s = l;
  38. e = r;
  39. }
  40. else if(l <= e){
  41. s = max(s, l);
  42. e = min(e, r);
  43. }
  44. else return false;
  45. }
  46.  
  47. return true;
  48. }
  49.  
  50. double consistency(int n){
  51.  
  52. sort(begin(a), end(a));
  53.  
  54.  
  55. double s = 0;
  56. double e = 2e9;
  57. double precision = 1e-7;
  58.  
  59. int iterations = 100;
  60. for(int i=1; i<=iterations; i++){
  61. double mid = (e+s)/2;
  62.  
  63. if(isPossible(n, mid)){
  64. e = mid;
  65. }
  66. else s = mid;
  67. }
  68.  
  69. return e;
  70.  
  71. }
  72.  
  73. void solve() {
  74.  
  75. int n;
  76. cin>>n;
  77.  
  78. a.resize(n);
  79. for(int i=0; i<n; i++){
  80. int x, y;
  81. cin>>x>>y;
  82. a[i] = {x,y};
  83. }
  84.  
  85. cout << fixed << setprecision(7) << consistency(n) << endl;
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. int32_t main() {
  95. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  96.  
  97. int t = 1;
  98. // cin >> t;
  99. while (t--) {
  100. solve();
  101. }
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 0.01s 5308KB
stdin
5
-1 5
10 3
4 2
7 10
8 1
stdout
1.5000000