## Mock CCO '18 Contest 1 Problem 6 - A Combining Problem

View as PDF

Points: 15 (partial)
Time limit: 0.3s
Memory limit: 16M

Problem type

Given a list of integers, we can take two adjacent integers, remove both of them, and insert the larger of the two where the two integers originally were. This incurs cost equal to the larger of the two integers. Compute the minimum cost needed to reduce this list to having just one integer.

#### Constraints

For at most 30% of marks, .

For at most 50% of marks, .

#### Input Specification

The first line will contain a single integer, .

Each of the next lines will contain an integer , the integers of the list in order.

#### Output Specification

Output the minimum cost.

#### Sample Input

3
1
2
3

#### Sample Output

5