luogu#P8067. [BalkanOI 2012] balls
[BalkanOI 2012] balls
Background
You are playing a physics line-drawing game.
Problem Description
There are balls and cups, numbered from left to right as . Initially, ball is aimed at cup (if nothing affects it, ball will fall into cup ). Cup has a score . When a ball falls into a cup, you gain that cup’s score (cup capacity is considered infinite). Scores can be negative.
You can draw two types of lines. Both endpoints of a line must be aimed at some cups, and the two endpoints cannot be the same cup.
-
From upper-left to lower-right. Let the cup aimed at by the upper-left endpoint be , and the cup aimed at by the lower-right endpoint be . Then all balls with indices will fall into cup .
-
From upper-right to lower-left. Let the cup aimed at by the lower-left endpoint be , and the cup aimed at by the upper-right endpoint be . Then all balls with indices will fall into cup .
Now you want to know the maximum score you can get using exactly one line of the first type, and the maximum score you can get using exactly one line of the second type, respectively.
Input Format
The first line contains an integer .
The next line contains integers, denoting .
Output Format
Output one integer on the first line: the maximum score when using only the first type of line.
Output one integer on the second line: the maximum score when using only the second type of line.
6
6 10 -7 2 5 -12
19
56
Hint
Constraints
Subtask #0 is the sample.
, .
Sample Explanation

The first picture shows the first type of line. Score: , and it can be proven to be the maximum.
The second picture shows the second type of line. Score: , and it can be proven to be the maximum.
Translated by ChatGPT 5