Airplane Seat Assignment
Time limit1sMemory limit1024 MB
Assign seats to n passengers on a 3-3-3 plane by picking the row behind an exit with the most empty seats, then the best seat by priority and side balance.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Croatia Airlines, a national treasure, is investing billions of euros in a sophisticated algorithm that assigns better airplane seats to passengers who bought their tickets earlier.
The seats span rows, where is even. There are three exit rows with no seats. The first exit row is at the very front of the plane (before the first seat row), the second is exactly in the middle, and the third is at the very back (after the last seat row). Rows are numbered with natural numbers from to from the front to the back. So rows , , and are exit rows, and every other row has seats.
The seat layout is 3-3-3. Each seat row has three groups of three seats, with an aisle between groups. Seats in each row are labeled with consecutive letters from left to right as ABC.DEF.GHI.
When a passenger buys a ticket, the algorithm assigns a seat by these rules:
- If a row directly behind an exit row has at least one empty seat, the rules below ignore all other rows that do not satisfy this condition.
- Pick the row with the most empty seats. If several rows tie, pick the row closest to an exit row, where the distance between rows and is . If there is still a tie, pick the row with the smallest number.
- Consider all empty seats in the chosen row and pick the one with the highest priority. The priority order from highest to lowest is:
- Seats next to the aisle in the middle group (
DandF) - Seats next to the aisle in the first and third groups (
CandG) - Window seats (
AandI) - Middle seat of the middle group (
E) - The remaining middle seats (
BandH)
- Seats next to the aisle in the middle group (
If two or more empty seats share the highest priority, consider the balance of the whole plane. Passengers on the left side sit in seats A, B, C, and D, and passengers on the right side sit in seats F, G, H, and I. The algorithm picks a seat on the side with more empty seats. If both sides have the same number of empty seats, it picks a seat on the left side.
Input
The first line contains natural numbers and (, ). The next lines describe the current seat state. Each line has exactly 11 characters. Exit rows and aisles are marked with '.', reserved seats with '#', and empty seats with '-'.
You may assume that the plane has at least empty seats.
Output
Print lines showing the seat state after assigning seats to the next passengers. The format is the same as the input, except that the seat assigned to passenger is marked with the -th lowercase letter of the English alphabet.