The Egyptian national football team is
getting ready to face Ghana this evening. The
players are putting in significant effort during training to deliver
their best performance in the upcoming match. Coaches have a unique
way of picking the best player a.k.a "man of AFCON" (Africa Cup of
Nations). A player is considered a "PRIMO" if the total
number of goals they've scored is a prime number. The coaches will
choose the highest PRIMO player as the man of
AFCON.
You are given N, the number of matches played so far,
followed by N match description.
Each match description starts with M, the number of players
who scored at the match, followed by M lines.
Each line consists of a string P, the player name, and
G, the number of goals scored by that player at this
match.
Then you will be asked K queries. Each query (line) consists
of a player name. For each query you have to calculate the
minimum number of goals the player needs to score in the next
match to be the man of the AFCON.
The players are busy with their training, and we've heard you're a
clever developer. Can you help the Egyptian players know how
many goals they need to score to become the man of AFCON?
(1 ≤ N ≤ 100) — The number of matches played.
(1 ≤ M ≤ 25) — The number of players who scored at the match.
(1 ≤ length(S) ≤ 100) — The name of the player. The name consists of uppercase and lowercase English letters only. (No spaces in the name)
(1 ≤ G ≤ 10) — The number of goals scored by a player at the match.
(1 ≤ K ≤ 15) — The number of queries.
The output should consist of K lines. Each line consists of the number of goals the player needs to score in the next match to be the man of AFCON.
3
2
Salah 2
Trezeguet 4
3
AliGabr 3
OmarMarmosh 1
Hegazi 2
2
Elneny 1
Salah 3
3
Trezeguet
Salah
AliGabr
3
0
4
We have 3 matches.
So the final scores are
Salah 5 goals | Trezeguet 4 goals | Ali Gabr 3 goals |
Omar Marmosh 1 goal | Hegazi 2 goals | Elneny 1 goal |
So far, Salah is the highest PRIMO and needs no more goals to be the man of AFCON. But what about other players?
Trezeguet scored 4 goals |
Needs 3 more goals to have 7 goals and exceed Salah |
Salah scored 5 goals |
Needs no more goals, He is the highest PRIMO |
Ali Gabr scored 3 goals |
Needs 4 more goals to have 7 goals and exceed Salah |
Made with
@Kerollos Magdy
UI was originally developed by
Amr Salama
for the
2019 AFCON challenge
The winners will be announced next Sunday