#C14522. Key with Maximum Sum
Key with Maximum Sum
Key with Maximum Sum
Given a dictionary mapping string keys to lists of integers, your task is to identify the key whose associated list has the maximum sum of its elements and output this key along with the computed sum.
If the input dictionary is empty, output None -inf
(i.e. the key is None and the sum is negative infinity). In the case of lists, note that an empty list has a sum of 0. In case of ties, the key encountered first with the maximum sum should be chosen.
The input is provided in a custom format as described below. Your solution should read from standard input (stdin) and write the answer to standard output (stdout).
Note: All formulas (if any) are formatted in \(\LaTeX\)
. For example, the sum for a given list \(L\) is defined as \(\sum_{x \in L} x\).
inputFormat
The input begins with an integer \(N\) representing the number of key-value pairs. Each of the next \(N\) lines describes one pair in the following format:
key L a1 a2 ... aL
Here, key
is a string, L
is a non-negative integer representing the number of integers in the list, and a1, a2, ..., aL
are the integers. If \(N = 0\), the dictionary is considered empty.
outputFormat
Output the key with the maximum sum of the list elements and the computed sum separated by a space. For an empty dictionary, output exactly:
None -inf## sample
3
a 3 1 2 3
b 2 4 5
c 4 6 7 8 9
c 30