Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort()
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[0][0]<=dayleft:
		a,b=works.pop(0)
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort()
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[0][0]<=dayleft:
		a,b=works.pop(0)
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
val =[[]for _ in range(10**5+1)]
for _ in range(n):
	a,b=map(int,input().split())
	val[a].append(b)
mval = [0]*(10**5
+1)
for i in range(1,m+1):
	val[i].sort(reverse=True)
	mval[i] = val[i][0] if val[i] else 0
ans = 0
for dayleft in range(1,m+1):
	cidx = mval.index(max(mval[1:dayleft+1]))
	if cidx == 0:
		continue
	ans += mval[cidx]
	del val[cidx][0]
	mval[cidx] = 0 if val[cidx]==[] else val[cidx][0]

print(ans)

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
val =[[]for _ in range(10**5+1)]
for _ in range(n):
	a,b=map(int,input().split())
	val[a].append(b)
mval = [0]*(10**5
+1)
for i in range(1,m+1):
	val[i].sort(reverse=True)
	mval[i] = val[i][0] if val[i] else 0
ans = 0
for dayleft in range(1,m+1):
	cidx = mval.index(max(mval[1:dayleft+1]))
	if cidx == 0:
		continue
	ans += mval[cidx]
	del val[cidx][0]
	mval[cidx] = 0 if val[cidx]==[] else val[cidx][0]

print(ans)

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
val =[[]for _ in range(m+1)]
for _ in range(n):
	a,b=map(int,input().split())
	val[a].append(b)
mval = [0]*(m+1)
for i in range(1,m+1):
	val[i].sort(reverse=True)
	mval[i] = val[i][0] if val[i] else 0
ans = 0
for dayleft in range(1,m+1):
	cidx = mval.index(max(mval[1:dayleft+1]))
	if cidx == 0:
		continue
	ans += mval[cidx]
	del val[cidx][0]
	mval[cidx] = 0 if val[cidx]==[] else val[cidx][0]

print(ans)

Fixed submission:
from heapq import heappush, heappop
n,m=map(int,input().split())
works = []
for _ in range(n):
	a,b=map(int,input().split())
	if a>m:
		continue
	works.append((a,b))
works.sort(reverse=True)
q=[]
ans=0

for dayleft in range(1,m+1):
	while works and works[-1][0]<=dayleft:
		a,b=works.pop()
		heappush(q,-b)
	if q:
		b = -heappop(q)
		ans+=b
print(ans)