#P1091. [NOIP 2004 提高组] 合唱队形

    ID: 91 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>动态规划,dp2004单调队列NOIp 提高组

[NOIP 2004 提高组] 合唱队形

Description

nn students stand in a row. The music teacher will ask nkn - k students to step out so that the remaining kk students form a "chorus formation."

A chorus formation is defined as follows: suppose the kk remaining students are numbered from left to right as 1,2,,k1, 2, \ldots, k, and their heights are t1,t2,,tkt_1, t_2, \ldots, t_k. They satisfy $t_1 < \cdots < t_i > t_{i+1} > \cdots > t_k \ (1 \le i \le k)$.

Your task is: given the heights of all nn students, compute the minimum number of students that must be removed so that the remaining students form a chorus formation.

Input Format

Two lines.

  • The first line contains an integer nn (2n1002 \le n \le 100), the total number of students.
  • The second line contains nn integers separated by spaces. The ii-th integer tit_i (130ti230130 \le t_i \le 230) is the height (in centimeters) of the ii-th student.

Output Format

Output a single integer: the minimum number of students who must be removed.

8
186 186 150 200 160 130 197 220

4

Hint

For 50% of the testdata, it is guaranteed that n20n \le 20.

For all the testdata, it is guaranteed that n100n \le 100.

Translated by ChatGPT 5