Buggy python submission (verdict: Time Limit Exceeded):


import collections
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])

temp = []
for i in allhiyatoi:
    temp.append(collections.deque(sorted(i)))

allhiyatoi = temp
 
reward = 0
for i in range(M+1):
    D = -1
    maxrw = -1
    for j,day in enumerate(allhiyatoi):
        if j > i:
            break
        if len(day) == 0:
            continue
        rw = max(day)
        if maxrw < rw:
            D = j
            maxrw = rw
    if D == -1:
        continue
    reward += allhiyatoi[D].pop()

print(reward)

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort()

reward = 0
for i in range(M+1):
    today_hiya_idx = -1
    today_reward = 0
    for j,hiya in enumerate(allhiyatoi):
        if hiya[0]>i:
            break
        if today_reward <= hiya[1]:
            today_hiya_idx = j
            today_reward = hiya[1]
    
    reward += today_reward
    if today_hiya_idx != -1:
        allhiyatoi[today_hiya_idx][1] = -1

print(reward)

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
finish = set([])
remain = set(range(M+1))
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    now = remain - finish
    if max(now)<hiya[0]:
        continue
    for i in remain:
        if i<hiya[0]:
            continue
        if reward[i] == 0:
            reward[i] = hiya[1]
            finish.add(i)
            break

print(sum(reward))

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
finish = set([])
remain = set(range(M+1))
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    if max(remain)<hiya[0]:
        continue
    now = remain - finish
    for i in remain:
        if i<hiya[0]:
            continue
        if reward[i] == 0:
            reward[i] = hiya[1]
            finish.add(i)
            break

print(sum(reward))

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
remain = list(range(M+1))
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    for i in remain:
        if i<hiya[0]:
            continue
        if reward[i] == 0:
            reward[i] = hiya[1]
            remain[i] = -1
            break

print(sum(reward))

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
# TLE

N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
remain = numpy.arange(M+1)
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    for i in (remain[ remain>=hiya[0] ]):
        if reward[i] == 0:
            reward[i] = hiya[1]
            numpy.delete(remain,i)
            break

print(sum(reward))

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
# TLE

N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort(key=lambda x: x[1], reverse = True)

reward = [0] * (M+1)
remain = numpy.arange(M+1)
for hiya in allhiyatoi:
    if hiya[0]>M:
        continue
    for i in (remain[ remain>=hiya[0] ]):
        if reward[i] == 0:
            reward[i] = hiya[1]
            remain[i] = -1
            break

print(sum(reward))

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())

allhiyatoi = []
for i in range(N):
    temp = list(map(int,input().split()))
    allhiyatoi.append(temp)

allhiyatoi.sort()

reward = 0
fin = []
for i in range(M+1):
    today = 0
    todaypos = -1
    for j,hiya in enumerate(allhiyatoi):
        if hiya[0]>i:
            break
        if j in fin:
            continue

        if today<hiya[1]:
            today = hiya[1]
            todaypos = j

    reward += today
    if todaypos!=-1:
        fin.append(todaypos)


print(reward)

Fixed submission:
from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)