아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Deleting

시간 제한4초메모리 제한512 MB

요약
배열 [1..n]에서 인접한 두 원소를 짝지어 모두 지울 때, 각 짝의 비용 중 최댓값을 최소로 만드는 값을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 구간, 이분 탐색
정답자
아직 제출이 없습니다

문제

You are given an array \[1,2,…,n]\[1, 2, \ldots, n], where the number of elements nn is even. 

In one operation, you can delete two adjacent elements of the array. If these elements are ii and jj, the cost of this operation is cost(i,j)\mathit{cost}(i, j).

In n2\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 n2\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 nn (2≤n≤40002 \le n \le 4000, nn 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 ii-th of the next n−1n - 1 lines contains ⌊n−i+12⌋\lfloor \frac{n-i+1}{2} \rfloor integers. If ii is even, these integers are cost(i,i+1),cost(i,i+3),…,cost(i,n−1)\mathit{cost}(i, i+1), \mathit{cost}(i, i+3), \ldots, \mathit{cost}(i, n-1). Otherwise, they are cost(i,i+1),cost(i,i+3),…,cost(i,n)\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 11 to (n2)2(\frac{n}{2} )^2.

출력

Output a single integer: the smallest possible cost of deleting the whole array.

힌트

In the first example, the array is \[1,2]\[1, 2], and cost(1,2)=1\mathit{cost}(1, 2) = 1. So, the only way to delete the array has the total cost of 11.

In the second example, one of the ways to delete the array is:

  • \[1,2,3,4,5,6]→\[1,2,5,6]\[1, 2, 3, 4, 5, 6] \to \[1, 2, 5, 6], deleting pair (3,4)(3, 4) with cost 66.
  • \[1,2,5,6]→\[1,6]\[1, 2, 5, 6] \to \[1, 6], deleting pair (2,5)(2, 5) with cost 55.
  • And then deleting pair (1,6)(1, 6) with cost 33.

The total cost is therefore max⁡(6,5,3)=6\max (6, 5, 3) = 6.

예제3

  1. 예제 1

    입력
    2
    1
    
    예상 출력
    1
    
  2. 예제 2

    입력
    6
    2 1 3
    4 5
    6 7
    8
    9
    
    예상 출력
    6
    
  3. 예제 3

    입력
    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