Buggy python submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)


Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy python submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
works = [list(map(int, input().split())) for _ in range(N)]
works.sort(key=lambda x:(-x[1], -x[0]))
days = [0] * (M+1)
ans = 0
max_day = M+1
for work in works:
  if work[0] >= max_day:
    continue
  full = True
  for day in range(work[0], max_day):
    if days[day] == 0:
      days[day] = 1
      ans += work[1]
      full = False
      break
  if full:
    max_day = work[0]
print(ans)


Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
works = [list(map(int, input().split())) for _ in range(N)]
works.sort(key=lambda x:(-x[1], -x[0]))
days = [0] * (M+1)
ans = 0
max_day = M+1
for work in works:
  if work[0] > M or work[0] >= max_day:
    continue
  full = True
  for day in range(work[0], max_day):
    if days[day] == 0:
      days[day] = 1
      ans += work[1]
      full = False
      break
  if full:
    max_day = work[0]
print(ans)


Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
works = [list(map(int, input().split())) for _ in range(N)]
works.sort(key=lambda x:(-x[1], -x[0]))
days = [0] * (M+1)
ans = 0
for work in works:
  if work[0] > M:
    continue
  for day in range(work[0], M+1):
    if days[day] == 0:
      days[day] = 1
      ans += work[1]
      full = False
      break
print(ans)


Fixed submission:
import heapq

MAX = 10**5+1
N, M = map(int, input().split())
works = [[] for _ in range(MAX)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)