문제
https://www.acmicpc.net/problem/2109
풀이

코드
n = int(input())
pds = []
maxD = 0
for _ in range(n):
p, d = map(int ,input().split())
pds.append((p, d))
maxD = max(maxD, d)
def answer():
global pds, maxD
pds = sorted(pds, reverse=True)
memo = [0]*(maxD+1)
count, fullCount = (0, len(memo))
for i in range(len(pds)):
p, d = pds[i]
if memo[d] == 0:
memo[d] = p
count += 1
else:
for underD in range(d-1, 0, -1):
if memo[underD] == 0:
memo[underD] = p
count += 1
break
if count >= fullCount: break
return sum(memo)
print(answer())