Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

L=[]
for i in range(M+1):
    L.append([])

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    LL+=[-k for k in L[i]]
    heapq.heapify(LL)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

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

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

L=[]
for i in range(M+1):
    L.append([])

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(AB[i][1])

for i in range(N):
    if len(L[i])!=0:
        L[i].sort(reverse=True)
        break

LL=[]
money=0

for i in range(1,M+1):
    LL+=[-k for k in L[i]]
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)


Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

L=[]
for i in range(M+1):
    L.append([])

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    LL+=[-k for k in L[i]]
    heapq.heapify(LL)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
AB= []
for i in range(N):
    AB.append([int(j) for j in input().split()])
 
AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, key=lambda x: x[1], reverse=True)
#お金が高い＞日にちがかからない　の順にソート
 
for i in range(N):  #同じ仕事があっても消せるようにIDを振る
    AB[i].append(i)
 
money = 0
 
def NdayOK(n):  #あとn日残されているときに選べる仕事のリスト
    nd = []
    for i in range(N):
        if AB[i][0] <= n:
            nd.append(AB[i][2])
    return(nd)
 
checker = []
for i in range(M+1):
    NOi = NdayOK(i)
    for j in NOi:
        if AB[j][2] not in checker:
            money += AB[j][1]
            checker.append(AB[j][2])
            break
 
print(money)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
AB= []
for i in range(N):
    AB.append([int(j) for j in input().split()])

AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, key=lambda x: x[1], reverse=True)
#お金が高い＞日にちがかからない　の順にソート

for i in range(N):  #同じ仕事があっても消せるようにIDを振る
    AB[i].append(i)

money = 0

def NdayOK(n):  #あとn日残されているときに選べる仕事のリスト
    nd = []
    for i in range(N):
        if AB[i][0] <= n:
            nd.append(AB[i][2])
    return(nd)

checker = []
for i in range(M+1):
    NOi = NdayOK(i)
    for j in NOi:
        if AB[j][2] not in checker:
            money += AB[j][1]
            checker.append(AB[j][2])
            break

print(money)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
AB= []
for i in range(N):
    AB.append([int(j) for j in input().split()])

AB = sorted(AB, key=lambda x: x[0], reverse=False)
AB = sorted(AB, key=lambda x: x[1], reverse=True)

for i in range(N):  #同じ仕事があっても消せるようにIDを振る
    AB[i].append(i)

money = 0

def NdayOK(n):  #あとn日残されているときに選べる仕事のリスト
    nd = []
    for i in range(N):
        if AB[i][0] <= n:
            nd.append(AB[i])
    return(nd)

checker = []
for i in range(M+1):
    NOi = NdayOK(i)
    for j in range(len(NOi)):
        if NOi[j][2] not in checker:
            money += NOi[j][1]
            checker.append(NOi[j][2])
            break

print(money)

Fixed submission:
import heapq

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
L=[[] for i in range(M+1)]

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(-AB[i][1])

LL=[]
money=0

for i in range(1,M+1):
    for j in L[i]:
        heapq.heappush(LL,j)
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)