Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = []
taken = [0] * (M+1)
jappend = jobs.append
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jappend((B*(-1),A))
heapq.heapify(jobs)
for i in range(len(jobs)):
    temp = heapq.heappop(jobs)
    if taken[(M-temp[1]+1)//2:M-temp[1]+1].count(0) > 0:
        searching = M - temp[1]
    else:
        if temp[1] == M:
            searching = 0
        elif taken[0:(M-temp[1]+1)//2].count(0) > 0:
            searching = ((M-temp[1]+1)//2) - 1
        else:
            continue
    for i in range(searching+1):
        if taken[searching-i] == 0:
            taken[searching-i] = temp[0]
            break
print(sum(taken)*(-1))

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = [[] for i in range(M)]
count = 0
h = []
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jobs[A-1].append(B*(-1))
heapq.heapify(h)
for i in range(M):
    if jobs[i]:
        for job in jobs[i]:
            heapq.heappush(h,job)
    if h:
        count -= heapq.heappop(h)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = []
taken = [0] * (M+1)
jappend = jobs.append
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jappend((B*(-1),A))
heapq.heapify(jobs)
for i in range(len(jobs)):
    temp = heapq.heappop(jobs)
    if taken[(M-temp[1]+1)//2:M-temp[1]+1].count(0) > 0:
        searching = M - temp[1]
    else:
        if temp[1] == M:
            searching = 0
        elif taken[0:(M-temp[1]+1)//2].count(0) > 0:
            searching = ((M-temp[1]+1)//2) - 1
        else:
            continue
    for i in range(searching+1):
        if taken[searching-i] == 0:
            taken[searching-i] = temp[0]
            break
print(sum(taken)*(-1))

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = [[] for i in range(M)]
count = 0
h = []
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jobs[A-1].append(B*(-1))
heapq.heapify(h)
for i in range(M):
    if jobs[i]:
        for job in jobs[i]:
            heapq.heappush(h,job)
    if h:
        count -= heapq.heappop(h)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = []
taken = [0] * M
jappend = jobs.append
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jappend((B*(-1),A))
heapq.heapify(jobs)
for i in range(len(jobs)):
    temp = heapq.heappop(jobs)
    for i in range(M-temp[1]+1):
        if taken[M-temp[1]-i] == 0:
            taken[M-temp[1]-i] = temp[0]
            break
print(sum(taken)*(-1))

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = [[] for i in range(M)]
count = 0
h = []
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jobs[A-1].append(B*(-1))
heapq.heapify(h)
for i in range(M):
    if jobs[i]:
        for job in jobs[i]:
            heapq.heappush(h,job)
    if h:
        count -= heapq.heappop(h)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = []
taken = [0] * M
jappend = jobs.append
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jappend((B*(-1),A))
heapq.heapify(jobs)
while jobs:
    temp = heapq.heappop(jobs)
    for i in range(M-temp[1]+1):
        if taken[M-temp[1]-i] == 0:
            taken[M-temp[1]-i] = temp[0]
            break
print(sum(taken)*(-1))

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = [[] for i in range(M)]
count = 0
h = []
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jobs[A-1].append(B*(-1))
heapq.heapify(h)
for i in range(M):
    if jobs[i]:
        for job in jobs[i]:
            heapq.heappush(h,job)
    if h:
        count -= heapq.heappop(h)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = []
taken = [0] * M
jappend = jobs.append
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jappend((B*(-1),A))
heapq.heapify(jobs)
while jobs:
    temp = heapq.heappop(jobs)
    for i in range(M-temp[1]+1):
        if taken[M-temp[1]-i] == 0:
            taken[M-temp[1]-i] = temp[0]
            break
print(sum(taken)*(-1))

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N,M = (int(x) for x in input().split())
jobs = [[] for i in range(M)]
count = 0
h = []
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A <= M:
        jobs[A-1].append(B*(-1))
heapq.heapify(h)
for i in range(M):
    if jobs[i]:
        for job in jobs[i]:
            heapq.heappush(h,job)
    if h:
        count -= heapq.heappop(h)
print(count)