A parade organizer has linked n floats together into a single chain, one after another, where n is guaranteed to be even. Each float has an applause score. The organizer pairs floats by mirroring their position in the chain: the 1st float from the front is paired with the 1st float from the back, the 2nd float from the front with the 2nd float from the back, and so on, until every float belongs to exactly one mirrored pair. The mirror bonus of a pair is the sum of the two floats' applause scores. Find the maximum mirror bonus among all n/2 mirrored pairs.
The first line contains a single even integer n — the number of floats in the chain. The second line contains n integers applause[0], applause[1], ..., applause[n-1] — the applause scores of the floats in chain order, from the front of the parade to the back.
Print a single integer: the maximum mirror bonus over all n/2 mirrored pairs.
Example 1
Input
4 5 4 2 1
Expected
6
Explanation
The floats are [5,4,2,1]. The mirrored pairs are (front 1st=5, back 1st=1) summing to 6, and (front 2nd=4, back 2nd=2) also summing to 6. The maximum mirror bonus is 6.
Example 2
Input
6 4 2 2 3 1 3
Expected
7
Explanation
The floats are [4,2,2,3,1,3]. The mirrored pairs are (4,3)=7, (2,1)=3, and (2,3)=5. The maximum mirror bonus is 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →