#K9481. Greatest Distance and Longest Leg

    ID: 38724 Type: Default 1000ms 256MiB

Greatest Distance and Longest Leg

Greatest Distance and Longest Leg

You are given T test cases. Each test case describes a race with several participants. For each participant, you are provided with a list of distances they ran in each leg of the race.

For each test case, calculate:

  • The participant with the greatest total distance traveled. Let \(S_i = \sum_{j=1}^{k_i} d_{ij}\) be the total distance for participant \(i\).
  • The participant with the longest single leg. That is, \(L_i = \max_{1 \leq j \leq k_i} d_{ij}\) for participant \(i\).

If a participant achieves the maximum in their respective category, choose the first one encountered in case of a tie.

Output the names of these two participants for each test case on a single line, where the first name corresponds to the participant with the greatest total distance and the second name corresponds to the participant with the longest single leg.

inputFormat

The input is read from standard input (stdin) with the following format:

T
N
name_1
K1
d11 d12 ... d1K1
name_2
K2
d21 d22 ... d2K2
... (for N participants)
... (repeat the above for each test case)

Here, T is the number of test cases, and for each test case, N is the number of participants. For each participant, the first line contains the participant's name, the second line contains an integer K representing the number of legs, followed by a line of K space-separated integers indicating the distances for each leg.

outputFormat

For each test case, print on a new line two names separated by a space. The first name is the participant with the greatest total distance and the second name is the participant with the longest single leg.

## sample
3
3
Alice
3
5 10 7
Bob
2
9 4
Charlie
4
6 7 8 9
2
David
2
8 15
Eve
3
14 5 9
2
John
2
15 20
Doe
2
12 25
Charlie Alice

Eve David Doe Doe

</p>