Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = [int(a) for a in input().split()]

AB = []

for _ in range(N):
    a, b = input().split()
    AB.append((int(a), int(b)))

AB = sorted(AB, key=lambda x: x[0])

used_ind = []
sum = 0

for remained_days in range(M+1):
    max_B = 0
    max_ind = -1

    for i in range(N):
        if i in used_ind:
            continue
        if AB[i][0] > remained_days:
            break
        if AB[i][1] > max_B:
            max_ind = i
            max_B = AB[i][1]
    remained_days -= AB[max_ind][0]
    sum += max_B
    used_ind.append(max_ind)

print(sum)

Fixed submission:
import heapq
import numpy as np

N, M = [int(a) for a in input().split()]

jobs = [[] for _ in range(M)]

for _ in range(N):
    a, b = map(lambda x: int(x), input().split())
    if a > M:
      continue
    jobs[M-a].append(b)

heap = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        # 降順にするためにマイナスをつけて入れる
        heapq.heappush(heap, -b)
    if len(heap) != 0:
        # 取り出した値にマイナスをつけて元に戻す
        ans += -heapq.heappop(heap)
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = [int(a) for a in input().split()]

A = []
B = []

for _ in range(N):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))

used_ind = []
sum = 0

for remained_days in range(M+1):
    max_B = 0
    max_ind = -1

    for i in range(N):
        if i in used_ind:
            continue
        if A[i] > remained_days:
            continue
        if B[i] > max_B:
            max_ind = i
            max_B = B[i]
    remained_days -= A[max_ind]
    sum += max_B
    used_ind.append(max_ind)

print(sum)

Fixed submission:
import heapq
import numpy as np

N, M = [int(a) for a in input().split()]

jobs = [[] for _ in range(M)]

for _ in range(N):
    a, b = map(lambda x: int(x), input().split())
    if a > M:
      continue
    jobs[M-a].append(b)

heap = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        # 降順にするためにマイナスをつけて入れる
        heapq.heappush(heap, -b)
    if len(heap) != 0:
        # 取り出した値にマイナスをつけて元に戻す
        ans += -heapq.heappop(heap)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = [int(a) for a in input().split()]

A = []
B = []

for _ in range(N):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))

used_ind = []
sum = 0

for remained_days in range(M+1):
    max_B = 0
    max_ind = -1

    for i in range(N):
        if i in used_ind:
            continue
        if A[i] > remained_days:
            continue
        if B[i] > max_B:
            max_ind = i
            max_B = B[i]
    remained_days -= A[max_ind]
    sum += max_B
    used_ind.append(max_ind)

print(sum)

Fixed submission:
import heapq
import numpy as np

N, M = [int(a) for a in input().split()]

jobs = [[] for _ in range(M)]

for _ in range(N):
    a, b = map(lambda x: int(x), input().split())
    if a > M:
      continue
    jobs[M-a].append(b)

heap = []
ans = 0
for i in range(M-1, -1, -1):
    for b in jobs[i]:
        # 降順にするためにマイナスをつけて入れる
        heapq.heappush(heap, -b)
    if len(heap) != 0:
        # 取り出した値にマイナスをつけて元に戻す
        ans += -heapq.heappop(heap)
print(ans)