#K94297. Top K Heroes

    ID: 38610 Type: Default 1000ms 256MiB

Top K Heroes

Top K Heroes

You are given the scores of m heroes in n different events. Each hero's total score is the sum of the scores from all events. In order to determine which heroes will advance to the next stage, you need to select the top k heroes based on their total scores.

The total score for a hero is calculated as follows:

$$ S = \sum_{i=1}^{n} s_i $$

In case of a tie (i.e. if two heroes have the same total score), the hero with the lower original index (i.e., the one who appears first in the input) has a higher rank.

Your task is to output the total scores of the top k heroes in descending order.

inputFormat

The first line of input contains three integers n, k, and m where:

  • n (1 ≤ n ≤ 100): the number of events.
  • k (1 ≤ k ≤ m): the number of top heroes to select.
  • m (1 ≤ m ≤ 1000): the total number of heroes.

Each of the following m lines contains n integers (each between 0 and 10000) representing the scores of a hero in each event. The heroes are indexed from 0 based on their order in the input.

outputFormat

Output the total scores of the top k heroes in descending order. The scores should be separated by a space.

## sample
3 2 4
10 20 30
50 60 70
30 40 50
60 20 10
180 120