#K85267. Player Ranking Calculation

    ID: 36604 Type: Default 1000ms 256MiB

Player Ranking Calculation

Player Ranking Calculation

Given n players and r rounds, each player earns a certain number of points in every round. In each round, the scores for all players are provided in sequence. The total score for each player is the sum of the points they earn in all rounds. Your task is to compute the total score for each player and then rank the players in descending order by their total points. In case of a tie (i.e. when two players have the same total score), the player with the smaller player number should be ranked higher.

The problem can be mathematically described as follows:

\( \text{Let } n \text{ be the number of players and } r \text{ be the number of rounds.} \)

\( \text{Let } p_{ij} \text{ be the points earned by player } i \text{ in round } j. \)

Then, the total score for player \( i \) is given by:

[ S_i = \sum_{j=1}^{r} p_{ij} ]

Sort the players such that for any two players \( i \) and \( k \):

[ \text{if } S_i \neq S_k: \quad S_i > S_k \quad \text{or, if } S_i = S_k: \quad i < k ]

Print the player number along with their total score in the sorted order.

inputFormat

The input is read from standard input (stdin) and it has the following format:

  1. The first line contains two space-separated integers \( n \) and \( r \), where \( n \) is the number of players and \( r \) is the number of rounds.
  2. The second line contains \( n \times r \) space-separated integers, representing the points scored by each player in each round. The scores are given in order: the first \( n \) numbers correspond to the scores of players 1 to \( n \) in the first round, the next \( n \) numbers are for the second round, and so on.

outputFormat

The output should be written to standard output (stdout). It consists of \( n \) lines. Each line contains two space-separated integers: the player number and their total points after \( r \) rounds. The players must be listed in descending order of total points. In the case of a tie, the player with the smaller number should come first.

## sample
3 2
5 3 4 10 2 7
1 15

3 11 2 5

</p>