Cheap Tricks
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
10.0s
Python 3
10.0s
Memory limit:
1G
Author:
Problem type
The MAPS executives, the president, vice president, and treasurer, are coordinating an Olympic artistic gymnastics showcase after a workshop. To plan the balance beam routine, they place marks along the beam. Mark
is the start, and mark
is the finish.
For every destination mark with
, the judges assign a landing coefficient
.
A gymnast may move from any mark to any destination mark
. The mark
may be before or after
, since a routine is allowed to change direction. Landing at
costs:
Find the minimum total cost needed to reach mark .
Input
The first line contains one integer (
): the number of destination marks.
The second line contains integers
(
), where
is the landing coefficient of mark
.
Output
Print one integer: the minimum total cost.
Example 1
Input
3
5 4 5
Output
13
Example 2
Input
1
5
Output
5
Example 3
Input
4
1 1 1 1
Output
4
Example 4
Input
5
3 2 3 2 4
Output
12
Comments