题解 | #合唱队#

合唱队

https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4

import bisect


def GetDP(ls):
    dp = [1 for _ in range(len(ls))]
    arr = [ls[0]]
    for i in range(1, len(ls)):
        if ls[i] > arr[-1]:
            arr.append(ls[i])
            dp[i] = len(arr)
        else:
            pos = bisect.bisect_left(arr, ls[i])
            arr[pos] = ls[i]
            dp[i] = pos + 1
    return dp


N = int(input())
ls = list(map(int, input().split()))
dp1 = GetDP(ls)
dp2 = GetDP(ls[::-1])[::-1]
dp = [dp1[i] + dp2[i] - 1 for i in range(N)]
print(N - max(dp))

全部评论

相关推荐

01-03 19:22
宁夏大学 运营
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务