Yanam

club_party

Feb 14th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. capacity = int(input())
  2. halls_reservations = input().split()
  3. reservation_sum = 0
  4. hall = []
  5. reservations = []
  6. while halls_reservations:
  7.     if halls_reservations[-1].isdigit():
  8.         if hall:
  9.             reservations.append(halls_reservations.pop())
  10.             reservation_sum += int(reservations[-1])
  11.             if reservation_sum > capacity:
  12.                 next_hall_reservation = int(reservations.pop())
  13.                 reservation_sum -= next_hall_reservation
  14.                 print(f'{hall.pop(0)} -> {", ".join(map(str, reservations))}')
  15.                 if hall:
  16.                     reservations = [next_hall_reservation]
  17.                     reservation_sum = next_hall_reservation
  18.                 else:
  19.                     reservations = []
  20.                     reservation_sum = 0
  21.         else:
  22.             halls_reservations.pop()
  23.     elif halls_reservations[-1].isalpha():
  24.         hall.append(halls_reservations.pop())
Advertisement
Add Comment
Please, Sign In to add comment