#C4185. Maximize Garden Beauty
Maximize Garden Beauty
Maximize Garden Beauty
You are given an integer n representing the number of sections in a garden, and n-1 space-separated integers representing the distances between adjacent sections. By adding an extra path, the overall beauty of the garden is doubled.
The beauty of the garden is computed by the formula:
\(Beauty = 2 \times \sum_{i=1}^{n-1} d_i\)
Your task is to calculate and output the maximum possible beauty of the garden.
inputFormat
The first line of input contains a single integer n (the number of garden sections). The second line contains n-1 space-separated integers, where each integer represents the distance between two adjacent sections.
outputFormat
Output a single integer representing the doubled sum of the distances, which is the maximum possible beauty of the garden.## sample
5
1 2 3 4
20
</p>