# Ratings and Rankings SOLUTIONS ELOMAX

Page Contents

### Ratings and Rankings SOLUTIONS ELOMAX

Gourmet expert composed a chess competition, which crossed over M months. There were N players, and player I was appraised Ri before the beginning of the competition. To see the improvement of the players, he noticed their rating changes toward the finish of every month.

After the competition, FIDE solicited Chef to locate the number from players whose pinnacle rating and pinnacle positioning didn’t happen in the very month. As it were, Chef was approached to discover the appraisals and positioning of every player after every one of the M months. At that point, utilizing this information, he should locate the quantity of players, with the end goal that the month where they accomplished their most noteworthy rating over all the months, was unique in relation to the month in which they accomplished their best position (in view of evaluations), over all the months. Note that we don’t think about the underlying rating/positioning, however just the rating and rankings after every one of the M months.

For a specific player, if there are different pinnacle rating or pinnacle positioning months, Chef was to consider the most punctual of them. In the event that different players had a similar rating toward the finish of some month, they were to be given a similar position. For instance, if there were 5 players, and their appraisals toward the finish of some month were (2600, 2590, 2600, 2600 and 2590), players 1, 3 and 4 were to be given the primary position, while players 2 and 5 ought to be given the fourth position.

As Chef loathes insights, he asks you, his companion, to assist him with discovering this. Would you be able to support Chef?

Info:

The main line contains a number T, the quantity of experiments.

The primary line of each experiment contains two space-isolated numbers N and M, the quantity of players and the quantity of months that the competition traversed over.

The second line of each experiment contains N space-isolated numbers, R1,R2,… ,RN signifying the underlying appraisals of the players, i.e., their evaluations before the beginning of the competition.

The following N lines each contain M space-isolated numbers. The jth number of the ith line, Ci,j signifies the rating change of the ith player after the jth month.

Yield:

For each experiment, print the quantity of players whose top appraisals didn’t happen in the exact month as their pinnacle positioning, in another line.

Limitations

1≤T≤10

1≤N,M≤500

1800≤Ri≤2800

−20≤Ci,j≤20

30 focuses : 1≤N,M≤50

70 focuses : Original limitations.

Test Input:

2500 2520

10 – 5 – 20

10 15 20

– 15 17 13

2 3

2125 2098

– 20 10 – 10

10 – 20

Test Output:

Clarification:

Experiment 1:

The appraisals for player 1 after every month are: (2510, 2505 and 2485), while his rankings are first, third and third, individually. In this way, his best appraising and best positioning happen after the very month, i.e., after the principal month.

The evaluations for player 2 after every month are: (2510, 2525 and 2545), while his rankings are first, first and first, separately. His best appraising happens after the third month, while his best positioning happens after the main month (we consider the principal month despite the fact that his pinnacle positioning is over all the months, since we consider just the most punctual month where he achieves the pinnacle positioning).

The evaluations for player 3 after every month are: (2505, 2522 and 2535), while his rankings are third, second and second, separately. His best evaluating happens after the third month, while his best positioning happens after the subsequent month.

So there are two players (2 and 3), whose top evaluations didn’t happen in the very month as their pinnacle positioning, and henceforth the appropriate response is 2.