题解 | #合唱队#
合唱队
http://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int sum = Integer.parseInt(br.readLine());
String[] heightStr = br.readLine().split(" ");
int[] heights = Arrays.asList(heightStr).stream().mapToInt(Integer::parseInt).toArray();
boolean tag = false;
int count = 0;
int ht = heights[0];
int[] left = new int[heights.length];
int[] right = new int[heights.length];
for (int i = 0,j = heights.length - 1; i < sum && j >= 0; i++,j--) {
left[i] = 1;
right[j] = 1;
for (int m=0,n=heights.length-1;m<i && n>j;m++,n--){
if (heights[i] > heights[m]){
left[i] = Math.max(left[m]+1,left[i]);
}
if (heights[j] > heights[n]){
right[j] = Math.max(right[n]+1,right[j]);
}
}
}
int max = left[0] + right[0] -1;
for (int i = 0; i < left.length; i++) {
if ((left[i] + right[i] -1) > max){
max = left[i] + right[i] -1;
}
}
System.out.println(heights.length - max);
}
}