题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int numOfStu = in.nextInt();
int[][] numAndCount = new int[numOfStu][2];
for (int i = 0; i < numOfStu; i++) {
numAndCount[i][0] = in.nextInt();
}
for (int i = 0; i < numOfStu - 1; i++) {
for(int j = 0; j < i; j++){
if(numAndCount[j][0] < numAndCount[i][0]){
numAndCount[i][1] = Math.max(numAndCount[j][1]+1, numAndCount[i][1]);
}
}
}
int[] reverse = new int[numOfStu];
for(int i = numOfStu -1; i > 0; i--){
for(int j = i; j <= numOfStu - 1; j++){
if(numAndCount[j][0] < numAndCount[i][0]){
reverse[i] = Math.max(reverse[j] + 1, reverse[i]);
}
}
}
int temp = 0;
for(int i = 1 ; i < numOfStu -1; i++){
if(temp < reverse[i] + numAndCount[i][1] + 1){
temp = reverse[i] + numAndCount[i][1] + 1;
}
}
System.out.println(numOfStu - temp);
}
}
}


