题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
def max_len(ls): dp = [1] * len(ls) # 存放每个位置左边符合要求的子序列长度 for i in range(len(ls)): for j in range(i): if ls[i] > ls[j] and dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 return dp # 1, 1, 1, 2, 2, 1, 3, 4 N = int(input()) ls = list(map(int, input().split())) left = max_len(ls) right = max_len(ls[::-1])[::-1] max_length = 0 for i in range(N): if left[i] + right[i] - 1 > max_length: max_length = left[i] + right[i] - 1 print(N - max_length)