#K83932. Determine the Winner from Recent Activities
Determine the Winner from Recent Activities
Determine the Winner from Recent Activities
You are given a series of activities. Each activity is represented by two integers: a team identifier and the points scored in that activity. Only the last k activities are considered. The objective is to calculate the cumulative score for each team over these k activities and then determine the team with the highest total score.
Let \(S_i\) be the total score for team \(i\) computed over the last \(k\) activities. The winning team is defined as the team for which \(S_i\) is maximized. In the event of a tie (multiple teams achieving the same score), the team with the smallest team ID wins.
Input Format: The input is read from standard input (stdin).
Output Format: Output the winning team ID to standard output (stdout).
inputFormat
The first line of input contains an integer k, which represents the number of activities. Each of the following k lines contains two space-separated integers: the first is the team ID and the second is the points scored in that activity.
Example:
5 1 10 2 20 1 -5 2 5 3 15
outputFormat
Output a single integer which is the team ID of the winning team based on the highest cumulative score calculated from the last k activities. In case of ties, output the smallest team ID.
Example:
2## sample
5
1 10
2 20
1 -5
2 5
3 15
2