Marathoner
InterviewTime limit2sMemory limit64 MB
Count the listed students who finished within 6 hours and report the fastest one, breaking ties by race result order.
- Level
Easy2 of 10
- Topics
- Implementation, Hash map
- Solved
- No attempts yet
Problem
Sanggeun runs a marathon academy. Its students are training for an upcoming marathon.
Once the race ends, every runner whose time is 6 hours or less receives a completion certificate. Sanggeun gives a special award to the student with the best time among those who received a certificate.
Given the results of the race, write a program that finds how many students receive a certificate and which student receives the special award.
Input
The first line contains the number of test cases . ()
The first line of each test case contains the number of students . () The second line contains the entry numbers of the students, separated by spaces. An entry number is a positive integer no greater than 1,000,000, and no two students share one. The third line contains the number of runners in the race, . () Each of the next lines contains three integers about one runner. The first integer is the entry number, and the second and third integers are the hours and the minutes of that runner's time. The hours are a nonnegative integer at most 23, and the minutes are a nonnegative integer at most 59. A runner who dropped out during the race has both the hours and the minutes given as -1.
At least one student receives a certificate in every test case.
Output
For each test case, print the entry number of the student with the best time and the number of students who received a certificate on one line, separated by a space.
If several students share the best time, print the one that appears earlier in the race results.