Advertisement
Nenogzar

Truck Tour1

Apr 22nd, 2024
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. from collections import deque
  2.  
  3. gas_station = int(input())
  4. petrol_pumps = deque()
  5.  
  6. total_petrol = 0
  7. distance_to_next = 0
  8. start_index = 0
  9.  
  10. for i in range(gas_station):
  11.     petrol, distance = map(int, input().split())
  12.     petrol_pumps.append((petrol, distance))
  13.  
  14.     total_petrol += petrol
  15.     total_petrol -= distance
  16.     distance_to_next += distance
  17.  
  18.     if total_petrol < 0:
  19.         start_index = i + 1
  20.         total_petrol = 0
  21.         distance_to_next = 0
  22.  
  23. print(start_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement