#K6231. Maximum Score in Rounds

    ID: 31503 Type: Default 1000ms 256MiB

Maximum Score in Rounds

Maximum Score in Rounds

You are given a competition with r rounds. In each round, there are several problems and each problem has an associated score. A participant must choose exactly one problem from each round. Your task is to compute the maximum total score by selecting one problem per round such that the sum of the chosen problem scores is maximized.

Note: Although the problem statement mentions selecting a subset of problems (i.e. at least one from each round), the optimal strategy is to pick the problem with the highest score in each round.

Formally, if the number of rounds is \(r\), and for each round \(i\) (\(1 \leq i \leq r\)) there are \(n_i\) problems with scores given in an array \(s\) (where the problems for round 1 come first, followed by round 2, and so on), you must compute:

[ \text{answer} = \sum_{i=1}^{r} \max_{j=1}^{n_i} s_{\text{round}_i[j]}]

Input and output are handled via standard input and output respectively.

inputFormat

The input is given in the following format via stdin:

r
n1 n2 ... nr
s1 s2 ... s_{n1+n2+...+nr}

Where:

  • r is the number of rounds.
  • The second line contains r space-separated integers. The \(i\)-th integer represents the number of problems in the \(i\)-th round.
  • The third line contains a total of \(n_1+n_2+...+n_r\) integers, representing the scores of the problems in order.
  • </p>

    outputFormat

    Output a single integer to stdout — the maximum total score possible by selecting the highest scoring problem from each round.

    ## sample
    3
    2 3 2
    4 2 3 8 -1 0 7
    19