Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- start = int(input())
- olymp_coord = int(input())
- portals_qnt = int(input())
- lp_from_start: int = -10**8
- rp_from_start: int = 10**8
- lp_from_olymp: int = -10**8
- rp_from_olymp: int = 10**8
- for _ in range(portals_qnt):
- portal_coord: int = int(input())
- if portal_coord < olymp_coord:
- if portal_coord > lp_from_olymp:
- lp_from_olymp = portal_coord
- elif portal_coord >= olymp_coord:
- if portal_coord < rp_from_olymp:
- rp_from_olymp = portal_coord
- if portal_coord < start:
- if portal_coord > lp_from_start:
- lp_from_start = portal_coord
- elif portal_coord >= start:
- if portal_coord < rp_from_start:
- rp_from_start = portal_coord
- time_to_olymp_from_portal = min([abs(rp_from_olymp - olymp_coord), abs(olymp_coord - lp_from_olymp)])
- time_to_start_from_portal = min([abs(rp_from_start - start), abs(start - lp_from_start)])
- time_through_portal = time_to_olymp_from_portal + time_to_start_from_portal + 1
- time_to_olymp_from_start = abs(start - olymp_coord)
- print(min(time_through_portal, time_to_olymp_from_start))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement