Under construction

Still being built. Things may change

Ranked Matchmaking Queue

Interview

Time limit1sMemory limit256 MB

Summary
Simulate matchmaking: place each player into the earliest created room whose level range fits, filling rooms of capacity m and reporting each room's final state.
Level

Medium4 of 10

Topics
Simulation, Implementation, Sorting, Array
Solved
No attempts yet

Problem

Jongun is adding a ranked matchmaking feature to the game he runs. Since players can differ in skill, when a player requests to join, the system should match them with players of a similar level and start the game.

The matchmaking system works as follows.

  1. When a player requests to join and no room is available for matching, create a new room and put the player in it. This room accepts players whose level is within -10 to +10 of the level of the first player who entered it.
  2. If a room is available, put the player in it and have them wait until the room is full.
    1. If multiple rooms are available, enter the room that was created first.
  3. When a room is full, start the game.

Given the number of players p, each player's nickname n and level l, and the capacity of one room m, write a program that performs the matchmaking described above and prints the final state of the rooms and the players in them.

Input

The first line contains the number of players p (1 ≤ p ≤ 300) and the room capacity m (1 ≤ m ≤ 300).

Each of the next p lines contains a player's level l (1 ≤ l ≤ 500) and nickname n, separated by a space.

Games start in the order the players are given in the input.

Nicknames are unique, consist of lowercase English letters with no spaces, and are at most 16 characters long.

Output

For every room created, print whether the game has started and the levels and IDs of the players in the room. The start status and the player information are separated by line breaks, and each player's level and ID are separated by a space on one line.

Print the rooms in the order they were created.

Within a room, print the players in lexicographic order of nickname.

Print Started! if the room's game has started, and Waiting! if it is still waiting.

Examples1

  1. Example 1

    Input
    10 5
    10 a
    15 b
    20 c
    25 d
    30 e
    17 f
    18 g
    26 h
    24 i
    28 j
    
    Expected output
    Started!
    10 a
    15 b
    20 c
    17 f
    18 g
    Started!
    25 d
    30 e
    26 h
    24 i
    28 j