第二题用的贪心 if __name__ == "__main__": n, m = list(map(int, input().strip().split(' '))) T = list(map(int, input().strip().split(' '))) have = set(T) not_have = [] for i in range(1, n + 1): if i not in have: not_have.append(i) i, j = 0, 0 ans = [] while i < m and j < n - m: if T[i] < not_have[j]: ans.append(T[i]) i += 1 else: ans.append(not_have[j]) j += 1 while i < m: ans.append(T[i]) i += 1 while j < n - m: ans.append(not_have[j]) j += 1 s = ' '.join(map(str, ans)) print(s)

相关推荐

点赞 评论 收藏
分享
WillingLing:查看图片
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务