Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- def boarding_passengers(capacity, *args):
- guests = {}
- boarding_queue = deque(args)
- total_passengers = sum(int(group[0]) for group in args)
- while capacity > 0 and boarding_queue:
- passengers, benefit_plan = boarding_queue.popleft()
- passengers = int(passengers)
- if passengers <= capacity:
- if benefit_plan not in guests:
- guests[benefit_plan] = 0
- guests[benefit_plan] += passengers
- capacity -= passengers
- result = ["Boarding details by benefit plan:"]
- for group, guests_num in sorted(guests.items(), key=lambda item: (-item[1], item[0])):
- result.append(f"## {group}: {guests_num} guests")
- if sum(guests.values()) == total_passengers:
- result.append("All passengers are successfully boarded!")
- elif capacity == 0:
- result.append("Boarding unsuccessful. Cruise ship at full capacity.")
- else:
- result.append(f"Partial boarding completed. Available capacity: {capacity}.")
- return "\n".join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement