viligen

truck_tour

Jan 14th, 2022 (edited)
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from collections import deque
  2.  
  3. pumps_number = int(input())
  4. fuel = 0
  5. pumps_que = deque()
  6. start_position = 0
  7.  
  8. for _ in range(pumps_number):
  9.     current_fuel, distance = input().split()
  10.     pumps_que.append((int(current_fuel), int(distance)))
  11.  
  12. current_position = 0
  13. while current_position <= pumps_number - 1:
  14.     is_successful = False
  15.     fuel = 0
  16.     for i in range(pumps_number):
  17.         if pumps_que[i][0] + fuel >= pumps_que[i][1]:
  18.             fuel += pumps_que[i][0]
  19.             fuel -= pumps_que[i][1]
  20.             is_successful = True
  21.         else:
  22.             start_position += 1
  23.             fuel = 0
  24.             is_successful = False
  25.             break
  26.     if not is_successful:
  27.         pumps_que.rotate(-1)
  28.         current_position += 1
  29.     else:
  30.         break
  31.  
  32. print(start_position)
Add Comment
Please, Sign In to add comment