시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 512 MB | 24 | 9 | 9 | 42.857% |
You are given an array $[1, 2, \ldots, n]$, where the number of elements $n$ is even.
In one operation, you can delete two adjacent elements of the array. If these elements are $i$ and $j$, the cost of this operation is $\mathit{cost}(i, j)$.
In $\frac{n}{2}$ operations, all elements will be deleted. The cost of deleting the whole array is defined as the largest cost among all the $\frac{n}{2}$ operations.
What is the smallest possible cost of deleting the whole array?
The first line of the input contains a single integer $n$ ($2 \le n \le 4000$, $n$ 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 $i$-th of the next $n - 1$ lines contains $\lfloor \frac{n-i+1}{2} \rfloor$ integers. If $i$ is even, these integers are $\mathit{cost}(i, i+1), \mathit{cost}(i, i+3), \ldots, \mathit{cost}(i, n-1)$. Otherwise, they are $\mathit{cost}(i, i+1), \mathit{cost}(i, i+3), \ldots, \mathit{cost}(i, n)$.
It is guaranteed that the costs form a permutation of numbers from $1$ to $(\frac{n}{2} )^2$.
Output a single integer: the smallest possible cost of deleting the whole array.
2 1
1
6 2 1 3 4 5 6 7 8 9
6
10 20 21 2 11 25 3 24 18 8 6 17 7 5 22 4 23 14 15 1 19 16 12 10 13 9
14
In the first example, the array is $[1, 2]$, and $\mathit{cost}(1, 2) = 1$. So, the only way to delete the array has the total cost of $1$.
In the second example, one of the ways to delete the array is:
The total cost is therefore $\max (6, 5, 3) = 6$.