Buggy python submission (verdict: Time Limit Exceeded):
#解説の方法
N,M = map(int,input().split())
AB = [[] for _ in range(10**5+1)]#報酬振り込み日数ごとに報酬を格納
for _ in range(N):
    a,b = map(int,input().split())
    AB[a].append(b)
q = []
ans =0
for i in range(1,M+1):
    q += AB[i]#後ろから見るイメージ　残りi日で請けれる仕事をリストに追加する
    if len(q)>0:
        q.sort()
        ans += q.pop()
print(ans)



Fixed submission:

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

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#解説の方法
N,M = map(int,input().split())
AB = [[] for _ in range(10**5+1)]#報酬振り込み日数ごとに報酬を格納
for _ in range(N):
    a,b = map(int,input().split())
    AB[a].append(b)
q = []
ans =0
for i in range(1,M+1):
    q += AB[i]#後ろから見るイメージ　残りi日で請けれる仕事をリストに追加する
    if len(q)>0:
        q.sort()
        ans += q.pop()
print(ans)



Fixed submission:

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

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

max_SumA = (M*(M+1))//2
AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の数
noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(M-a,-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                break
        if flag ==1:
            noMore = a
    
print(ans)
    


Fixed submission:

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

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

max_SumA = (M*(M+1))//2
AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の数
ans = 0
for a,b in AB:
    for idx in range(M-a,-1,-1):
        if memo[idx] == 0:#仕事が請けられる
            ans += b
            memo[idx]=1
            break
print(ans)
    


Fixed submission:

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

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

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

max_SumA = (M*(M+1))//2
AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の数
ans = 0
for a,b in AB:
    for idx in range(M-a,-1,-1):
        if memo[idx] == 0:#仕事が請けられる
            ans += b
            memo[idx]=1
            break
print(ans)
    


Fixed submission:

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

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)