Advertisement
Guest User

Club Party

a guest
Feb 14th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. from collections import deque
  2.  
  3. halls_maximum_capacity = int(input())
  4.  
  5. line = [x for x in input().split()]
  6. party = deque([])
  7. taken_guests = []
  8.  
  9. while line:
  10.     x = line.pop()
  11.     if x.isalpha():
  12.         party.append(x)
  13.         continue
  14.     if not party:
  15.         continue
  16.     new_guests = int(x)
  17.     if halls_maximum_capacity >= sum(taken_guests) + new_guests:
  18.         taken_guests.append(new_guests)
  19.     else:
  20.         print(f"{party.popleft()} -> {', '.join([str(guests) for guests in taken_guests])}")
  21.         taken_guests = []
  22.         line.append(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement