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

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0

for i in range(1, M + 1):
    while l[i][0] <= i:
        heapq.heappush(tmp, l[i])
    ans -= heapq.heappop(tmp)[1]
print(ans)

Fixed submission:
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
tmp = 1
for n in range(1, N+1):
    for m in range(tmp):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
            tmp += 1
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
print(max(dp[N]))


Fixed submission:
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
for n in range(1, N+1):
    for m in range(n):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
print(max(dp[N]))

Fixed submission:
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
for n in range(1, N+1):
    for m in range(n):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
print(max(dp[N]))

Fixed submission:
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)