Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(b)
        else:
            work[a] = [b]

    cand = []
    prev_max = 0
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            y = max(work[i])
            if(prev_max<y):
                x = y
            else:
                x = prev_max
            cand += work[i]
        if(len(cand)==0):
            continue
        cand.remove(x)
        cnt += x
        prev_max = max(cand)

    print(cnt)

if __name__ == '__main__':
    main()


Fixed submission:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(b)
        else:
            work[a] = [b]

    cand = []
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            cand += work[i]
        if(len(cand)==0):
            continue
        x = max(cand)
        cand.remove(x)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()


Fixed submission:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect
import heapq
N,M = [int(x) for x in input().split()]
work = {}
for _ in range(N):
    a,b = [int(x) for x in input().split()]
    if(a in work):
        work[a].append(-b)
    else:
        work[a] = [-b]

#%%
cand = []
cnt = 0
for i in range(1,M+1):
    if(i in work):
        cand += work[i]
    heapq.heapify(cand)
    if(len(cand)==0):
        continue
    x = heapq.heappop(cand)
    cnt += -x

print(cnt)


Fixed submission:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
import bisect
N,M = [int(x) for x in input().split()]

work = [[int(x) for x in input().split()]for _ in range(N)]
#%%
dp = [0]*(M+1)
work.sort(key=itemgetter(0))
work.sort(key=itemgetter(1))
#%%
days = [i[0] for i in work]
seen = set()
cnt = 0
for i in range(1,M+1):
    nonused = []
    while(len(work)>0):
        x = work.pop()
        if(x[0]>i):
            nonused.insert(0,x)
        else:
            break
    #print(i,x)
    if(x[0]<=i):
        cnt += x[1]
    work += nonused

print(cnt)


Fixed submission:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

if __name__ == '__main__':
    main()