Under construction

Still being built. Things may change

Competitive Arcade Basketball

Interview

Time limit3sMemory limit1024 MB

Summary
Add up each player's points in input order and print the players who first reach at least p points, in the order they reach it, or "No winner!" if none do.
Level

Easy3 of 10

Topics
Hash map, Simulation
Solved
No attempts yet

Problem

You are attending an arcade basketball competition. The goal is to score as many points as possible before time runs out. The announcer has said the scoreboard is broken, so nobody can track the scores. As an experienced programmer, you decide to write a program that records each player's name and points, then announces the winner or winners at the end of the contest.

Input

The first line contains three integers: the number of participants nn (1≤n≤100 0001 \le n \le 100\,000), the minimum number of points pp required to win (10≤p≤10 00110 \le p \le 10\,001), and mm, the number of lines with player names and points (1≤m≤200 0001 \le m \le 200\,000). The next nn lines contain the names of the participants, each mentioned exactly once. Each name consists of at most 20 alphanumeric characters. The remaining mm lines each contain the name of a participant, followed by the number of points they scored (1, 2, or 3).

Output

Output the names of the participants who reached the minimum required score, one per line. Output "<Winner> wins!" for each winner. Output the winners in the order in which they reached the required score. If nobody reaches the minimum required score, output "No winner!" (including the exclamation mark).

Examples3

  1. Example 1

    Input
    3 10 13
    John
    Kelly
    George
    Kelly 1
    George 2
    Kelly 1
    John 2
    George 1
    John 3
    Kelly 3
    Kelly 1
    George 3
    George 1
    John 3
    George 3
    Kelly 1
    
    Expected output
    George wins!
    
  2. Example 2

    Input
    4 10 13
    Bob
    Nina
    Jess
    Tim
    Nina 2
    Bob 2
    Nina 1
    Jess 3
    Bob 2
    Jess 2
    Nina 1
    Jess 2
    Nina 3
    Bob 1
    Nina 3
    Jess 3
    Bob 2
    
    Expected output
    Nina wins!
    Jess wins!
    
  3. Example 3

    Input
    4 15 13
    Bob
    Nina
    Jess
    Tim
    Nina 2
    Bob 2
    Nina 1
    Jess 3
    Bob 2
    Jess 2
    Nina 1
    Jess 2
    Nina 3
    Bob 1
    Nina 3
    Jess 3
    Bob 2
    
    Expected output
    No winner!