Advertisement
am1x

pen001

Sep 3rd, 2024 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | Fixit | 0 0
  1. def main():
  2.     n = int(input())
  3.     assert 1 <= n <= 100000
  4.     ps = [0] * n
  5.     for i in range(n):
  6.         x, y = map(int, input().split())
  7.         assert abs(x) <= 1000000000
  8.         assert abs(y) <= 1000
  9.         ps[i] = (x, y)
  10.     ps.sort()
  11.    
  12.     sy1 = 0
  13.     sy2 = 0
  14.     for p in ps:
  15.         y = p[1]
  16.         sy1 += y
  17.         sy2 += y * y
  18.     res = (n * sy2 - sy1 * sy1) / n
  19.     resp = (ps[0][0] - 0.5, sy1 / n, sy1 / n)
  20.     sy1l, sy1r = 0, sy1
  21.     sy2l, sy2r = 0, sy2
  22.     k = 0
  23.     while True:
  24.         x0 = ps[k][0]
  25.         while k < n:
  26.             x, y = ps[k]
  27.             if x != x0:
  28.                 break
  29.             k += 1
  30.             sy1l += y
  31.             sy1r -= y
  32.             sy2l += y * y
  33.             sy2r -= y * y
  34.         if n <= k:
  35.             break
  36.         tres = (k * sy2l - sy1l * sy1l) / k + ((n - k) * sy2r - sy1r * sy1r) / (n - k)
  37.         tresp = (ps[k][0] - 0.5, sy1l / k, sy1r / (n - k))
  38.         if tres < res:
  39.             res = tres
  40.             resp = tresp
  41.     print(resp[1], resp[2], resp[0])
  42.  
  43. if __name__ == '__main__':
  44.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement