#C2580. Calculate Participant Scores

    ID: 45912 Type: Default 1000ms 256MiB

Calculate Participant Scores

Calculate Participant Scores

You are given m participants and n problems. Each problem has an associated weight. Each participant's score is calculated by summing up the weights of the problems they solved correctly. More formally, if participant i has a result vector s_i and the weight vector is w, then their score is computed as

$score_i = \sum_{j=1}^{n} w_j \times s_{i,j}$

After computing the scores, you must sort the participants primarily in descending order of score. In the event of a tie, the participant with the smaller index (1-indexed) should come first.

The program reads input from standard input and outputs the sorted scores to standard output.

inputFormat

The first line contains two integers m and n, representing the number of participants and problems, respectively.

The second line contains n integers, where the j-th integer represents the weight of the j-th problem.

This is followed by m lines, each containing n integers. The i-th of these lines represents the results of the i-th participant, where each integer is either 1 (problem solved correctly) or 0 (problem not solved).

outputFormat

Output m lines. Each line should contain two integers: the total score of the participant and their 1-indexed participant number. The lines must be printed such that participants with higher scores come first, and in case of a tie, the participant with the lower index appears first.

## sample
4 3
5 3 2
1 0 1
1 1 0
0 0 1
1 1 1
10 4

8 2 7 1 2 3

</p>