第二题没有思路,打算用贪心蒙一下,结果AC了,请问为什么可以用贪心?
n = int(input()) total_score = 0 score = [] for i in range(n): (s, g) = list(map(int, input().split())) if g == 0: total_score += s else: score.append(s) score.sort(reverse=True) for s in score: total_score = max(total_score*2, total_score+s) print(total_score)
全部评论
(6) 回帖