贪心 + 排序
n, to = int(input()), [[] for _ in range(10)]
for _ in range(n):
a, b = map(int, input().split())
to[a].append(b)
print(sum(sum(sorted(nums)[:len(nums) - n // 10]) for nums in to if len(nums) > n // 10))
复杂度分析
- 时间复杂度:$O(nlogn)$
- 空间复杂度:$O(1)$