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

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    
    ans += heapq.heappop(hq)
print(-ans)    


Fixed submission:
import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
finput = sys.stdin.readline
n,m = map(int, finput().split())

tasks = [0]*n
rewards = [0]*n
total = [0]*(m+1)

for i in range(n):
    tasks[i],rewards[i] = [int(j) for j in finput().split()]

que = [idx for idx, item in enumerate(rewards) if item == max(rewards)]

day = 0
minflag = [idx for idx, item in enumerate(tasks) if item == min(tasks)]

while que:
    subtasks = [tasks[i] for i in que]
    while subtasks:
        t = max(subtasks)
        idx = subtasks.index(t)
        if t+day <= m:
            total[t+day:m+1] = [total[i]+rewards[que[idx]] for i in range(t+day,m+1)]
            day += 1
        del subtasks[idx]
        del tasks[que[idx]]
        del rewards[que[idx]]
        if que[idx] in minflag:
            del minflag[minflag.index(que[idx])]
            if minflag==[]:
                minflag = [idx for idx, item in enumerate(tasks) if item == min(tasks)]
        del que[idx]
        
    if rewards==[]:
        break
    if day+min(tasks)>m:
        break
    que += [idx for idx, item in enumerate(rewards) if item == max(rewards)]

print(max(total))


Fixed submission:
import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
finput = sys.stdin.readline
n,m = map(int, finput().split())

tasks = [0]*n
rewards = [0]*n
total = [0]*(m+1)

for i in range(n):
    tasks[i],rewards[i] = [int(j) for j in finput().split()]

que = [idx for idx, item in enumerate(rewards) if item == max(rewards)]

day = 0

while que:
    subtasks = [tasks[i] for i in que]
    while subtasks:
        t = max(subtasks)
        idx = subtasks.index(t)
        if t+day <= m:
            total[t+day:m+1] = [total[i]+rewards[que[idx]] for i in range(t+day,m+1)]
            day += 1
        del subtasks[idx]
        del tasks[que[idx]]
        del rewards[que[idx]]
        del que[idx]
    if rewards==[]:
        break
    if day+min(tasks)>m:
        break
    que += [idx for idx, item in enumerate(rewards) if item == max(rewards)]

print(max(total))


Fixed submission:
import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
finput = sys.stdin.readline
n,m = map(int, finput().split())

tasks = [0]*n
rewards = [0]*n
total = [0]*(m+1)

for i in range(n):
    tasks[i],rewards[i] = [int(j) for j in finput().split()]

que = [idx for idx, item in enumerate(rewards) if item == max(rewards)]

day = 0

while que:
    subtasks = [tasks[i] for i in que]
    while subtasks:
        t = max(subtasks)
        idx = subtasks.index(t)
        if t+day <= m:
            total[t+day:m+1] = [total[i]+rewards[que[idx]] for i in range(t+day,m+1)]
            day += 1
        del subtasks[idx]
        del tasks[que[idx]]
        del rewards[que[idx]]
        del que[idx]
    if rewards==[]:
        break
    que += [idx for idx, item in enumerate(rewards) if item == max(rewards)]

print(max(total))


Fixed submission:
import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

print(-ans)