Problem of the day
At the end of all M Participants completing the exam, the final correct answers get decided.
Based on these answers score of each candidate gets recalculated, and the one with the highest score is the TOPPER!!!
If more than one Participant gets the top score, then the one who attempted the exam first is treated as TOPPER.
The first line of the input contains a single integer ‘T’ representing the no. of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and ‘M’, denoting the number of questions and number of participants, respectively.
The second line of each test case contains ‘N’ space-separated integers representing the default answers.
The following ‘M’ lines of each test case contain ‘N’ space-separated integers, denoting answers given by each participant.
For each test case, print two lines.
The first line for each test case contains ‘M’ space-separated integers representing the instant results of every participant.
The second line of each test case contains a single integer representing the TOPPER.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer in the form of an array of length ‘M’+1. The first ‘M’ integers represent instant results, and the last element denotes the TOPPER.
1 ≤ T ≤ 10
1 ≤ M, N ≤ 1000
0 ≤ responses and default answer ≤ 4
Time limit: 1 Sec
2
10 2
1 2 3 4 1 2 3 4 1 2
1 2 4 4 3 2 3 1 1 3
2 3 4 4 1 2 3 1 1 2
4 3
1 2 3 4
2 1 4 3
4 1 2 3
1 3 2 1
6 6
1
0 2 0
1
For First Case -
Number of questions = 10
Number of Participants = 2
Default answers : 1 2 3 4 1 2 3 4 1 2
(Latest Key is same as Default answers)
First Participant answers : 1 2 4 4 3 2 3 1 1 3
Right answers : 6 (= Instant result of first Participant)
Latest Key : 1 2 4 4 3 2 3 1 1 3
Second Participant’s answers : 2 3 4 4 1 2 3 1 1 2
Right answers : 6 (= Instant result of second Participant)
Latest Key : 1 2 4 4 1 2 3 1 1 2
Final key : 1 2 4 4 1 2 3 1 1 2
(Final Key is same as Latest Key at the end of all Participants completing the exam)
Right answers of Participant1 = Right answers of Participant2 = 8.
So topper is the first Participant with a score of 8.
For the second case -
Number of questions = 4
Number of Participants = 3
Default answers : 1 2 3 4
(Latest Key is same as Default answers)
First Participant answers : 2 1 4 3
Right answers : 0 (= Instant result of first Participant)
Latest Key : 2 1 4 3
Second Participant’s answers : 4 1 2 3
We will continue similarly and get instant answers for all participants and find the TOPPER.
2
2 2
2 1
1 3
1 2
4 1
4 2 2 1
3 0 1 1
0 1
1
1
1