NOIP '04 P3 - Chorus Formation

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

N students stand in a row, and the music teacher asks NK students to leave so that the remaining K students form a chorus formation.

The chorus formation refers to such a formation: Suppose the K students left are numbered 1,2,,K from left to right, and their heights are T1,T2,,TK respectively, then their heights satisfy T1<<Ti>Ti+1>>TK (1iK).

Your task is, given the heights of all N students, calculate the minimum number of students who need to leave, so that the remaining students can form a chorus formation.

Input Specification

The first line of the input consists of an integer N (2N100) denoting the number of students. The second line consists of n integers separated by a single space denoting the height of the i-th student. The heights satisfy 130Ti230.

Output Specification

Output the minimum number of students that should leave to form a chorus formation.

Sample Input

Copy
8
186 186 150 200 160 130 197 220

Sample Output

Copy
4

Constraints

For 50% of test cases, n20.

For all test cases, n100.


Comments

There are no comments at the moment.