fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define sz(st) int(st.size())
  5. #define all(st) st.begin(), st.end()
  6.  
  7. void Solve() {
  8. int n;
  9. cin >> n;
  10. vector<int> x(n), v(n);
  11. for (int i = 0; i < n; i++)
  12. cin >> x[i] >> v[i];
  13.  
  14. auto is_good = [&](double time) {
  15. double left = -1e9, right = 1e9;
  16. for (int i = 0;i<n;i++) {
  17. left = max(left, x[i] - v[i] * time);
  18. right = min(right, x[i] + v[i] * time);
  19. }
  20. return left <= right;
  21. };
  22.  
  23. double l = 0, r = 1e9, ans = 0;
  24. for (int i = 0; i < 100; i++) {
  25. double m = (l + r) / 2;
  26. if (is_good(m))
  27. r = m - 1, ans = m;
  28. else
  29. l = m + 1;
  30. }
  31. cout << fixed << setprecision(10) << ans;
  32. }
  33.  
  34. signed main() {
  35. ios_base::sync_with_stdio(false);
  36. cin.tie(nullptr);
  37. int t = 1;
  38. //cin >> t;
  39. for (int tc = 1; tc <= t; tc++) {
  40. Solve();
  41. cout << "\n";
  42. }
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5284KB
stdin
5
-1 5
10 3
4 2
7 10
8 1
stdout
1.5000000000