Nenogzar

Truck Tour

Apr 22nd, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. """ Truck Tour"""
  2. # judge
  3. # https://judge.softuni.org/Contests/Practice/Index/1831#4
  4.  
  5. from collections import deque
  6.  
  7. gas_station = int(input())
  8. liters, kilometers = deque(), deque()
  9. current_gas_station = 0
  10.  
  11. for i in range(gas_station):
  12.     liter, kilometer = map(int, input().split())
  13.     liters.append(liter)
  14.     kilometers.append(kilometer)
  15. if sum(kilometers) <= sum(liters):
  16.     while liters:
  17.         current_liter = liters.popleft()
  18.         current_kilometer = kilometers.popleft()
  19.  
  20.         if current_liter < current_kilometer:
  21.             current_gas_station += 1
  22.             liters.append(current_liter)
  23.             kilometers.append(current_kilometer)
  24.         else:
  25.             remaining_liters = current_liter - current_kilometer
  26.             if kilometers:
  27.                 liters[0] += remaining_liters
  28.             else:
  29.                 break
  30.  
  31. print(current_gas_station)
  32.  
  33.  
  34. """
  35. input:
  36.  
  37. 5
  38. 22 5
  39. 14 10
  40. 52 7
  41. 21 12
  42. 36 9
  43.  
  44. output:
  45. 0
  46.  
  47. """
Add Comment
Please, Sign In to add comment