#C2002. Mountain Skyline Demolition

    ID: 45271 Type: Default 1000ms 256MiB

Mountain Skyline Demolition

Mountain Skyline Demolition

You are given an array of positive integers representing the heights of buildings in a skyline. Your task is to determine the minimum number of buildings to demolish so that the remaining buildings form a mountain-shaped skyline.

A mountain-shaped skyline is defined as an array where there exists an index i (with 1 \leq i \leq n) such that the values strictly increase up to i and then strictly decrease after i. In other words, if the remaining building heights are represented as \(h_1, h_2, \dots, h_n\), there must exist an index \(i\) such that:

[ h_1 < h_2 < \dots < h_i > h_{i+1} > \dots > h_n ]

If no valid mountain configuration exists, you must demolish all but one building.

inputFormat

The input is given via standard input (stdin). The first line contains an integer T denoting the number of test cases. Each test case consists of two lines:

  • The first line contains an integer n representing the number of buildings.
  • The second line contains n space-separated positive integers denoting the heights of the buildings.

outputFormat

For each test case, output a single integer on a new line—the minimum number of buildings that need to be demolished in order to obtain a mountain-shaped skyline, printed to standard output (stdout).

## sample
5
7
1 5 7 10 6 3 2
5
4 2 3 5 1
4
3 4 1 2
5
1 2 3 4 5
5
5 4 3 2 1
0

1 1 4 4

</p>