Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left as sort

import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
list = sorted(list)
for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      sort(temp,list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans += temp.pop()
print(ans)

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left as sort

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
list = sorted(list)
for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      sort(temp,list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans += temp.pop()
print(ans)

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
list = sorted(list)
for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      temp.append(list[j][1])
    else:
      a = j
      break
  ans += max(temp)
  l = int(len(temp) -1)
  if l >= 1:
    temp = sorted(temp)
    temp = temp[:l]
print(ans)

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
list = sorted(list)
for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      temp.append(list[j][1])
    else:
      a = j
      break
  ans += max(temp)
  l = int(len(temp) -1)
  if l >= 1:
    temp = sorted(temp)
    temp = temp[:l]
print(ans)

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0

for i in range(1,1+m):
  for j in list:
    if j[0] == i:
      temp.append(j[1])
  ans += max(temp)
  l = int(len(temp) -1)
  if l >= 1:
    temp = sorted(temp)
    temp = temp[:l]
print(ans)

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
list = sorted(list)
dp = [ [0 for i in range(m+1)] for j in range(n+1)]

for i in range(1,n+1):
  for j in range(1,m+1):
    if list[i-1][0] <= j:
      dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]+list[i-1][1])
    else:
      dp[i][j] = dp[i-1][j]
print(dp[n][m])

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
list = sorted(list)
dp = [ [0 for i in range(m+1)] for j in range(n+1)]

for i in range(1,n+1):
  for j in range(1,m+1):
    if list[i-1][0] <= j:
      dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]+list[i-1][1])
    else:
      dp[i][j] = dp[i-1][j]
print(dp[n][m])

Fixed submission:
import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)