lynulx

Untitled

Oct 27th, 2021
539
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def main():
  2.     start = int(input())
  3.     olymp_coord = int(input())
  4.     portals_qnt = int(input())
  5.     lp_from_start: int = -10**8
  6.     rp_from_start: int = 10**8
  7.     lp_from_olymp: int = -10**8
  8.     rp_from_olymp: int = 10**8
  9.     for _ in range(portals_qnt):
  10.         portal_coord: int = int(input())
  11.         if portal_coord < olymp_coord:
  12.             if portal_coord > lp_from_olymp:
  13.                 lp_from_olymp = portal_coord
  14.         elif portal_coord >= olymp_coord:
  15.             if portal_coord < rp_from_olymp:
  16.                 rp_from_olymp = portal_coord
  17.         if portal_coord < start:
  18.             if portal_coord > lp_from_start:
  19.                 lp_from_start = portal_coord
  20.         elif portal_coord >= start:
  21.             if portal_coord < rp_from_start:
  22.                 rp_from_start = portal_coord
  23.     time_to_olymp_from_portal = min([abs(rp_from_olymp - olymp_coord), abs(olymp_coord - lp_from_olymp)])
  24.     time_to_start_from_portal = min([abs(rp_from_start - start), abs(start - lp_from_start)])
  25.     time_through_portal = time_to_olymp_from_portal + time_to_start_from_portal + 1
  26.     time_to_olymp_from_start = abs(start - olymp_coord)
  27.     print(min(time_through_portal, time_to_olymp_from_start))
  28.  
  29. main()
  30.  
RAW Paste Data