#C7142. Minimum Energy Cost for a Full Lap
Minimum Energy Cost for a Full Lap
Minimum Energy Cost for a Full Lap
You are given n trees arranged in a circle, with a specified energy cost to move from one tree to the next. The task is to compute the minimum total energy cost required to complete a full lap around all trees. Note that since a full lap is required, the hero must traverse every segment exactly once.
The total energy cost is given by the formula: \( E = \sum_{i=1}^{n} cost_i \), where \( cost_i \) represents the energy cost between consecutive trees.
You need to read the input from stdin
and output the result to stdout
.
inputFormat
The input consists of two lines. The first line contains a single integer n (the number of trees). The second line contains n space-separated integers, where each integer represents the energy cost to move from one tree to the next in the circle.
outputFormat
Output a single integer – the minimum total energy cost to complete a full lap.
## sample5
3 1 4 2 5
15