MATCH_ALK - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: himanshu154
Tester: wasd2401
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

You’re given the runs scored and wickets taken of each player in a cricket match. Decide who the “Man of the Match” is.

EXPLANATION:

Let S_i denote the points earned by the i-th player.
As outlined in the statement, this is quite easy to calculate: it’s simply S_i = A_i + 20\times B_i, since each run is worth 1 point and each wicket is worth 20.

Now, compute M: the maximum element of the array S.
That is, M = \max(S_1, S_2, \ldots, S_{22}).
Finally, find the index i such that S_i = M.
The statement guarantees that such an index is unique, so just print this index.

TIME COMPLEXITY:

\mathcal{O}(N) per testcase (N being the number of players; here, 22).

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    mx, id = 0, 0
    for i in range(22):
        a, b = map(int, input().split())
        if a + 20*b > mx:
            mx = a + 20*b
            id = i+1
    print(id)