题解 | #合唱队#
合唱队
http://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
int[] arr = new int[n];
int[] left = new int[n];
int[] right = new int[n];
for (int i = 0; i < n; i++) arr[i] = scan.nextInt();
//fill left
for (int i = 0; i < n; i++) {
left[i] = 1;
for (int j = 0; j < i; j++) {
if (arr[i] > arr[j]) {
left[i] = Math.max(left[i], left[j] + 1);
}
}
}
// fill right
for (int i = n - 1; i >= 0; i--) {
right[i] = 1;
for (int j = n - 1; j > i; j--) {
if (arr[j] < arr[i]) {
right[i] = Math.max(right[i], right[j] + 1);
}
}
}
int max = 1;
for (int i = 0; i < n; i++) {
max = Math.max(max, left[i] + right[i] - 1);
}
System.out.println(n - max);
}
}
}