Deleting
시간 제한4초메모리 제한512 MB
배열 [1..n]에서 인접한 두 원소를 짝지어 모두 지울 때, 각 짝의 비용 중 최댓값을 최소로 만드는 값을 구한다.
문제
You are given an array , where the number of elements is even.
In one operation, you can delete two adjacent elements of the array. If these elements are and , the cost of this operation is .
In operations, all elements will be deleted. The cost of deleting the whole array is defined as the largest cost among all the operations.
What is the smallest possible cost of deleting the whole array?
입력
The first line of the input contains a single integer (, is even).
We are kind today. So we won't provide unnecessary input. It can be shown that it's impossible for two numbers of the same parity to be adjacent at any point, so we won't provide costs for those pairs.
The -th of the next lines contains integers. If is even, these integers are . Otherwise, they are .
It is guaranteed that the costs form a permutation of numbers from to .
출력
Output a single integer: the smallest possible cost of deleting the whole array.
힌트
In the first example, the array is , and . So, the only way to delete the array has the total cost of .
In the second example, one of the ways to delete the array is:
- , deleting pair with cost .
- , deleting pair with cost .
- And then deleting pair with cost .
The total cost is therefore .