TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
N,M = map(int,input().split())
dic = {}
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    if dic[A]:
      dic[A].append(B)
    else:
      dic[A] = [B]
      
ans = 0
plan = heapq()
for i in range(1,M+1):
  for w in dic[i]:
    heapq.heappush(plan,-w)
  if len(plan) != 0:
    ans += heappop(plan)

print(-ans)
	

import heapq
N,M = map(int,input().split())
dic = {}
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    if A in dic.keys():
      dic[A].append(B)
    else:
      dic[A] = [B]
      
ans = 0
plan = []
for i in range(1,M+1):
  if i in dic.keys():
    for w in dic[i]:
        heapq.heappush(plan,-w)
  if len(plan) != 0:
    ans += heapq.heappop(plan)

print(-ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,reverse=True,key=lambda x:x[1])
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,reverse=True,key=lambda x:x[1])
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+1)]
arr.extend(arr2)
arr=sorted(arr,reverse=True,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,key=lambda x:x[0])
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
N, M = map(int, input().split())

reward = [[] for _ in range(M)]

for i in range(N):
    a, b = map(int, input().split())

    if a > M:
        continue
    c[m - a].append(b)

import heapq

h = []
heapq.heapify(h)
ans = 0

for i in range(M - 1, -1, -1):
    for b in c[i]:
        heapq.heappush(h, -b)
    if len(h) > 0:
        ans += -1 * heapq.heappop(h)

print(ans)

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

c = [[] for _ in range(M)]

for i in range(N):
    a, b = map(int, input().split())

    if a > M:
        continue
    c[M - a].append(b)

import heapq

h = []
heapq.heapify(h)
ans = 0

for i in range(M - 1, -1, -1):
    for b in c[i]:
        heapq.heappush(h, -b)
    if len(h) > 0:
        ans += -1 * heapq.heappop(h)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
n,m=map(int,input().split())
ab=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a-1].append(-b)
l=[]
heapq.heapify(l)
ans=0
for i in range(m):
  for j in ab[i]:
    heapq.heappush(l,j)
  if l:
    print(l)
    ans+=-heapq.heappop(l)
print(ans)

import heapq
n,m=map(int,input().split())
ab=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    ab[a-1].append(-b)
l=[]
ans=0
for i in range(m):
  for j in ab[i]:
    heapq.heappush(l,j)
  if l:
    ans+=-heapq.heappop(l)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n, m = map(int, input().split())
A = list(list(map(int, input().split())) for _ in range(n))
d = 0
for i in range(m):
    B = [0]
    for a, b in A:
        if a < m-i:
            B.append(b)
    d += max(B)
print(d)

import heapq
def main():
  N, M = list(map(int, input().split()))
  jobs = [[] for _ in range(M)]
  for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
      jobs[d-1].append(-r)

  m = 0
  heap = []
  for i in range(M):
    for a in jobs[i]:
      heapq.heappush(heap, a)
    if len(heap) > 0:
      b = heapq.heappop(heap)
      m += -b
  return m
if __name__ == '__main__':
  main()


import sys
input = sys.stdin.readline
import heapq
def main():
  N, M = list(map(int, input().split()))
  jobs = [[] for _ in range(M)]
  for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
      jobs[d-1].append(-r)

  m = 0
  heap = []
  for i in range(M):
    for a in jobs[i]:
      heapq.heappush(heap, a)
    if len(heap) > 0:
      b = heapq.heappop(heap)
      m += -b
  print(m)
if __name__ == '__main__':
  main()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)

print(jobs)

days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    days.append(max(money_list))
    money_list.remove(max(money_list))

print(sum(days))


import heapq

n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)


Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

N, M = map(int, input().split())
AB_list = []
[heapq.heappush(AB_list, list(map(int, input().split()))) for _ in range(N)]
ans = 0
kouho = []

for day in range(1, M + 1):
    while 1:
        if len(AB_list) != 0:
            i = heapq.heappop(AB_list)
            if i[0] > day:
                break
            else:
                heapq.heappush(kouho, i[1]*(-1))
        else:
            break
    if len(kouho) != 0:
        ans += heapq.heappop(kouho)

print(ans * (-1))

import heapq

N, M = map(int, input().split())
AB_list = []
[heapq.heappush(AB_list, list(map(int, input().split()))) for _ in range(N)]
ans = 0
kouho = []

for day in range(1, M + 1):
    if len(AB_list) != 0:
        while AB_list[0][0] <= day:           
            heapq.heappush(kouho, heapq.heappop(AB_list)[1]*(-1))
            if len(AB_list) == 0:
                break
    if len(kouho) != 0:
        ans += heapq.heappop(kouho)

print(ans * (-1))

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

n, m = map(int, input().split())
lis = []
for i in range(n + 1):
    lis.append([])

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
heapq.heapify(cnd)
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


import heapq

n, m = map(int, input().split())
lis = [[] for _ in range(m + 1)]

for i in range(n):
    a, b = map(int, input().split())
    if a <= m:
        lis[a].append(-b)

cnd = []
res = 0

for j in range(1, m + 1):
    for e in lis[j]:
        heapq.heappush(cnd, e)
    if cnd:
        res += -heapq.heappop(cnd)
print(res)


Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    L[A-1].append(-B)
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    ans -= heapq.heappop(Q)
    
print(ans)

import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    try:
        L[A-1].append(-B)
    except:
        pass
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
from heapq import heapify, heappop, heappush
N,M = map(int,input().split())
A = [[] for _ in range(M+1)]
#HQ = []
for i in range(N):
  a,b = map(int,input().split())
  if a < M:
    A[a].append(b)
#print(A)
ans = 0
L = []
for day in range(1,M+1):
  for t in A[day]:
    heappush(L,-t)
  #print(L)
  if not L:
    continue
  temp = heappop(L)
  ans += -temp
print(ans)  

from heapq import heapify, heappop, heappush
N,M = map(int,input().split())
A = [[] for _ in range(M+1)]
#HQ = []
for i in range(N):
  a,b = map(int,input().split())
  if a <= M:
    A[a].append(b)
#print(A)
ans = 0
L = []
for day in range(1,M+1):
  for t in A[day]:
    heappush(L,-t)
  #print(L)
  if not L:
    continue
  temp = heappop(L)
  ans += -temp
print(ans)  

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
N,M=map(int,input().split())

balist=[]
for i in range(N):
  A,B=map(int,input().split())
  balist.append((B,A))
  
balist.sort(reverse=True)
#print(balist)

answer=0
day=0
for (b,a) in balist:
  if day+a<=M:
    print(b,day+a)
    answer+=b
    day+=1
    
  if day>=M:
    break
    
print(answer)

import heapq
import sys
input=sys.stdin.readline

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

ablist=[]
for i in range(N):
  A,B=map(int,input().split())
  ablist.append((A,B))
ablist.sort(reverse=True)
  
hq=[]
answer=0
for i in reversed(range(M)):
  while ablist:
    a,b=ablist[-1]
    if i+a<=M:
      ablist.pop()
      heapq.heappush(hq,((-b,a)))
    else:
      break
  
  if hq:
    mb,a=heapq.heappop(hq)
    answer-=mb
    #print(i,a+i,-mb)
    
print(answer)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            available_works.append(baitos[baito_index])
        else:
            baitos = baitos[baito_index:]
            break

    #itibanniiyatu
    max_now = 0
    max_index = None

    for work_index in range(len(available_works)):
        if available_works[work_index][1] >= max_now:
            print("oke")
            max_index = work_index
            max_now = available_works[max_index][1]

    if max_index is not None:
        max += max_now
        available_works.pop(max_index)
        max_index = None

print(max)

n, m = map(int, input().split())
baitos = [list(map(int, (input().split()))) for _ in range(n)]
baitos = sorted(baitos, key=(lambda x: x[0]))

max = 0
available_works = []
for shigotobi in reversed(range(m)):
    nokori = m-shigotobi
    
    for baito_index in range(len(baitos)):
        if baitos[baito_index][0] <= nokori:
            available_works.append(baitos[baito_index])
        else:
            baitos = baitos[baito_index+1:]
            break
    #itibanniiyatu
    max_now = 0
    max_index = None

    for work_index in range(len(available_works)):
        if available_works[work_index][1] >= max_now:
            max_index = work_index
            max_now = available_works[max_index][1]

    if max_index:
        max += max_now
        available_works.pop(max_index)

print(max)

from collections import defaultdict
from heapq import heappush, heappop
n, m = map(int, input().split())
baito_dict = defaultdict(list)
for _ in range(n):
    day, weight = map(int, input().split())
    baito_dict[day].append(weight)


max = 0

available_works = []

for day in range(1, m+1):
    for weight in baito_dict[day]:
        heappush(available_works, -weight)
    if available_works:
        max += heappop(available_works)

print(-max)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
pab = [(i, k[0], k[1]) for i, k in enumerate(sorted(ab, key=lambda x: (-x[1], x[0])))]

from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import sys
input = sys.stdin.readline
from operator import itemgetter

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

#sort by hosyu
work_list.sort(key=itemgetter(1), reverse=True)
sum = 0
workdays = list(range(M+1))

for day, reward in work_list:
    latest = M - day

    
    k = workdays[:latest+1]

print(sum)


import sys
input = sys.stdin.readline

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

sum = 0
works = []

for i in work_list:
    for j in i:
        heappush(works, -1*j)
    if len(works) == 0:
        continue
    sum -= (heappop(works))

print(sum)


import sys
input = sys.stdin.readline
from operator import itemgetter

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

sum = 0
works = []

for i in work_list:
    for j in i:
        heappush(works, -1*j)
    if len(works) == 0:
        continue
    sum -= (heappop(Q))

print(sum)


import sys
input = sys.stdin.readline
from heapq import heappop, heappush

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

sum = 0
works = []

for i in work_list:
    for j in i:
        heappush(works, -1*j)
    if len(works) == 0:
        continue
    sum -= (heappop(works))

print(sum)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort()

q=[]
ans=0
for i in range(m):
    while j <= n-1:
        if ab[j][0]<=i+1:
            heapq.heappush(q,-ab[j][1])
        else:
            ans-=heapq.heappop(q)
            break
        j+=1
print(ans)

import heapq

n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort()

q=[]
ans=0
j=0
for i in range(m):
    while j <= n-1:
        if ab[j][0]<=i+1:
            heapq.heappush(q,-ab[j][1])
        else:
            break
        j+=1
    ans-=heapq.heappop(q)
print(ans)

import heapq

n,m=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort()

q=[]
ans=0
j=0
for i in range(m):
    while j <= n-1:
        if ab[j][0]<=i+1:
            heapq.heappush(q,-ab[j][1])
        else:
            break
        j+=1
    if len(q)!=0:
        ans-=heapq.heappop(q)
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
from heapq import*
L=lambda:list(map(int,input().split()))
n,m=L()
c=[]
h=[i+1for i in range(m)]
for i in range(n):
  a,b=L()
  c.append([b,a])
c.sort(key=lambda c:(c[0],c[1]),reverse=1)
a=0
for i in c:
  j=m
  b=True
  while j!=0:
    k=heappop(h)
    if i[1]<=k:
      b=False
      break
    heappush(h,k)
    j-=1
  if b:continue
  m-=1
  a+=i[0]
print(a)

n,m=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]+[[100000000,0]]
for i in range(m):ab.append([i+1,0])
ab.sort()
from heapq import heappop,heappush
h=[]
j=0
ans=0
for i in range(1,m+1):
  while ab[j][0]<=i:
    heappush(h,-ab[j][1])
    j+=1
  ans-=heappop(h)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
for i in ab:
    if i[0] < m:
        ans += i[1]
        m -= 1
print(ans)

n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
print(ab)
for i in ab:
    if i[0] <= m:
        ans += i[1]
        m -= 1
        if m < 0:
            break
print(ans)

n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split(' '))))
ab = list(filter(lambda x: x[0] <= m, ab))
ab = sorted(ab, key=lambda x: (-x[1], -x[0]))

ans = 0
while m > 0:
    ab = list(filter(lambda x: x[0] <= m, ab))
    if ab[0][0] <= m:
        ans += ab[0][1]
        ab.pop(0)
    else:
        break
    m -= 1
print(ans)


import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        if len(self.hq) == 0:
            return None
        if self.desc:
            return heapq.heappop(self.hq).val
        else:
            return heapq.heappop(self.hq)

    def push(self, a):
        if self.desc:
            heapq.heappush(self.hq, Reverse(a))
        else:
            heapq.heappush(self.hq, a)

    def top(self):
        if self.desc:
            return self.hq[0].val
        else:
            return self.hq[0]

    def __len__(self):
        return len(self.hq)


n, m = map(int, input().split(' '))
ab = []
for _ in range(n):
    a, b = map(int, input().split(' '))
    if a > m:
        continue
    ab.append((a, b))
ab.sort(reverse=True)

ans = 0
h = Heapq([], desc=True)
for i in range(1, m+1):
    while ab and ab[-1][0] <= i:
        a, b = ab.pop()
        h.push(b)
    if h:
        ans += h.pop()
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
print(c)
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
N, M = map(int, input().split())
md = [0]*N

for i in range(0,N):
  d, m = map(int, input().split())
  md[i] = {"m":m, "d":d}

md = sorted(md, key=lambda x:x["m"], reverse=True)
print(md)

def insertHeap(array, val):
    array.append(val)
    n = len(array)-1
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
        else:
            break
    return array

def desertHeap(array):
    if array == []:
      return None
    array[0], array[-1] = array[-1], array[0]
    res = array.pop(-1)
    n = len(array)
    if n == 0 or n == 1: 
      return res
    parent = 0
    while True:
        child = 2 * parent + 1
        if child >= n: break
        if (child + 1 < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]:
            array[child], array[parent] = array[parent], array[child]
            parent = child;
        else:
            break
    return res

n, m = map(int, input().split())
 
li = [[] for j in range(10**5+1)]
 
for _ in range(n):
  a, b = map(int, input().split())
  li[a].append(b)
 
ans = 0
jobsHeap = []
for i in range(1, m+1):
  for val in li[i]:
    jobsHeap = insertHeap(jobsHeap, val)
  
  if jobsHeap != []:
    res = desertHeap(jobsHeap)
    ans += res
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq

n, m = map(int, input().split())
num = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: x[0])

s = []
heapq.heapify(s)

for i in range(1, m + 1):
  for j in num:
    if(j[0] <= i):
       heapq.heappush(s, j[1])
    else:
      break

print(sum(s))


import heapq

n, m = map(int, input().split())
num = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: x[0])

s = []
j = 0
count = 0
heapq.heapify(s)

for i in range(1, m + 1):
  while (j < n and num[j][0] <= i):
    heapq.heappush(s, num[j][1] * (-1))
    j += 1
  if(len(s)):
    count += heapq.heappop(s) * (-1)

print(count)


Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    
    n, m = [int(x) for x in sys.stdin.readline().split()]

    job_list = dict((i, collections.deque()) for i in range(1, m+1))
    for _ in range(n):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        if a <= m:
            job_list[a].append(b)

    
    
    
    
    

    day_rewards = [0 for _ in range(m+1)] 

    for i in range(m, 0, -1):
        while job_list[i]:
            if i < m:
                mi = min(day_rewards[i:])
                if mi < max(job_list[i]):
                    day_rewards[day_rewards.index(mi, i)] = max(job_list[i])
                    job_list[i].remove(max(job_list[i]))
                else:
                    break
            else:
                break
                
    print(sum(day_rewards))


if __name__ == "__main__":
    main()


import sys
from heapq import heappush, heappop

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    res = [0] * m
    hq = []
    i = 0
    for j in range(1, m+1):
        while i < n:
            a, b = ab[i]
            if a <= j:
                heappush(hq, -b)
                i += 1
            else:
                break
        if not hq:
            continue
        res[-j] = -heappop(hq)
    
    return sum(res)
        
if __name__ == '__main__':
    ans = main()
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort()
# print(ab)
import heapq
heap = []
ans = 0
i = 0
for day in reversed(range(m)):
    while i<n and ab[i][0]==(m-day):
        heapq.heappush(heap,-ab[i][1])
        i += 1
    if len(heap) > 0:
        ans += -heapq.heappop(heap)
    # print(day,i,ans,heap)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    AB[n] = list(map(int,input().split()))
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
for work in sorted_AB:
    cnt = 0
    while True:
        if work[0]-1+cnt >= M:
            break
        elif work_schedule[work[0]-1+cnt] == 0:
            work_schedule[work[0]-1+cnt]  = work[1]
            break
        elif  work_schedule[work[0]-1+cnt] != 0:
            cnt+=1
sum(work_scuedule)

N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    AB[n] = list(map(int,input().split()))
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
for work in sorted_AB:
    cnt = 0
    while True:
        if work[0]-1+cnt >= M:
            break
        elif work_schedule[work[0]-1+cnt] == 0:
            work_schedule[work[0]-1+cnt]  = work[1]
            break
        elif  work_schedule[work[0]-1+cnt] != 0:
            cnt+=1
sum(work_schedule)

from collections import defaultdict
import heapq

n, m = map(int, input().split())
dct = defaultdict(list)

for i in range(n):
    a, b = map(int, input().split())
    dct[a].append(-b)

h = []
res = 0

for i in range(1, m + 1):
    if dct[i]:
        for item in dct[i]:
            heapq.heappush(h, item)
    if h:
        res += heapq.heappop(h)

print(-res)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
from collections import defaultdict
from heapq import heappush, heappop

N,M = map(int,input().split())
d = defaultdict(list)

for _ in range(N):
  a,b = map(int,input().split())
  d[a].append(b)
  
h = []
res = 0

for a in range(1,M + 1):
  for b in d[a]:
    heappush(h,-b)
  if h > 0:
    c = heappop(h)
    res -=c
    
print(res)

from collections import defaultdict
from heapq import heappush, heappop

N,M = map(int,input().split())
d = defaultdict(list)

for _ in range(N):
  a,b = map(int,input().split())
  d[a].append(b)
  
h = []
res = 0

for a in range(1,M + 1):
  for b in d[a]:
    heappush(h,-b)
  if len(h) > 0:
    c = heappop(h)
    res -=c
    
print(res)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    print(h)
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
P = []
n, m = map(int, input().split())
ans = 0
for _ in range(n):
    a,b = map(int, input().split())
    P.append([a,b])
P = sorted(P, key= lambda x: [x[0]*x[1],x[1]], reverse=True)
print(P)

for i,j in P:
    if i > m:
        continue
    ans += j
    m -= 1
    if m == 0:
        break
print(ans)

import heapq

def intoheap(l):
    for i in l:
        heapq.heappush(Q, -i)
        
n,m = map(int,input().split())
P = {i:[] for i in range(1,m+1)}
Q = []
ans = 0
for _ in range(n):
    a,b = map(int, input().split())
    if a > m:
        continue
    P[a].append(b)
        

for i in range(1,m+1):
    if i in P.keys():
        intoheap(P[i])
    if Q == []:
        continue
    ans += -heapq.heappop(Q)
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):

import heapq
from collections import defaultdict

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

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)


result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)

    while len(result) < i:
        if len(h) > 0:
            result.append(-1*heapq.heappop(h))
        else:
            break

print(sum(result))




import heapq
from collections import defaultdict

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

a_b_dict = defaultdict(list)
for _ in range(N):
    a, b = tuple(map(int, input().split()))
    a_b_dict[a].append(b)

result = []
h = []
num_days = 0
for i in range(1, 1+M):
    for b in a_b_dict.get(i, []):
        heapq.heappush(h, -b)
    if len(h) > 0:
        result.append(-1*heapq.heappop(h))
print(sum(result))



Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]
v=[[]for _ in q]
z=0
for a,b in t:
	if a<=M:v[a-1]+=[b]
for i in v:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*10**5
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]
for i in v[:M]:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import bisect
from collections import deque

n, m = map(int, input().split())
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst.sort(key=lambda x:(x[1]), reverse=True)
lst.sort(key=lambda x:(x[0]), reverse=False)

ans = 0
ind = 0
kouho = deque([])
for i in range(1, m+1):
    tugi = True
    while tugi:
        if ind >= n:
            break
        if lst[ind][0] == i:
            bisect.insort(kouho, lst[ind][1])
            ind += 1
        else:
            tugi = False
    if kouho != []:
        ans += kouho.pop()

print(ans)

import heapq

n, m = map(int, input().split())
dic = {}
for i in range(n):
    ai, bi = map(int, input().split())
    if ai in dic:
        dic[ai].append(bi)
    else:
        dic[ai] = [bi]

for key in dic.keys():
    dic[key] = sorted(dic[key])

ans = 0
hp = []
heapq.heapify(hp)
for i in range(1, m+1):
    if i in dic:
        heapq.heappush(hp, (-dic[i].pop(), i))
    if hp != []:
        maxi = heapq.heappop(hp)
        ans += -maxi[0]
        if dic[maxi[1]] != []:
            heapq.heappush(hp, (-dic[maxi[1]].pop(), maxi[1]))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]

jobs.sort()

money = []
ans = 0

i = 0

for limit in range(1, m + 1):
    
    while i < n and jobs[i][0] <= m:
        a = jobs[i][0]
        b = jobs[i][1]
        
        heapq.heappush(money, -b)
        i += 1
    
    if money != []:
        ans -= heapq.heappop(money)

print(ans)

import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]

jobs.sort()

money = []
ans = 0


for limit in range(1, m + 1):
    for a, b in jobs:
        
        if a == limit:
            
            heapq.heappush(money, -b)
            jobs.pop(0)
        elif a > limit:
            break
    
    if money != []:
        ans += heapq.heappop(money) * (-1)

print(ans)

import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]

jobs.sort()

money = []
ans = 0

i = 0

for limit in range(1, m + 1):
    
    while i < n and jobs[i][0] <= limit:
        a = jobs[i][0]
        b = jobs[i][1]
        
        heapq.heappush(money, -b)
        i += 1
    
    if money != []:
        ans -= heapq.heappop(money)

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
n , m = map(int,input().split())
kouho = [[] for i in range(m)]
hosyu = [0 for i in range(m)]
for i in range(n):
    a , b = map(int,input().split())
    if a < m:
        kouho[a-1].append(-b)
for i in range(m):
    now = i
    p = 0
    heapq.heapify(kouho[i])
    while kouho[i]:
        if now == m:
            break
        if p == 0:
            p = heapq.heappop(kouho[i])
        if hosyu[now] > p:
            hosyu[now] = p
            p = 0
        now += 1
print(abs(sum(hosyu)))

import heapq
n , m = map(int,input().split())
kouho = [[] for i in range(m)]
for i in range(n):
    a , b = map(int,input().split())
    if a <= m:
        kouho[a-1].append(-b)
ans = 0
p = []
heapq.heapify(p)

for i in range(m):

    for j in kouho[i]:
        heapq.heappush(p,j)
    if p:
        ans -= heapq.heappop(p)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
import heapq
n,m = map(int,input().split())
l = [0]*n
for i in range(n):
  l[i] = list(map(int,input().split()))
l.sort()

L = [[] for i in range(m+1)]
for i in range(n):
  if l[i][0] <= m:
    L[l[i][0]].append(l[i][1])

a = []
ans = 0
for i in range(m):
  key = i+1
  for j in L[key]:
    heapq.heappush(a, -L[i][j])
  if a != []:
    heapq.heapify(a)
    ans += heapq.heappop(a)
print(-ans)

from heapq import *
n,m = map(int,input().split())
l = [[] for i in range(m+1)]
for i in range(n):
  a,b = map(int,input().split())
  if a < m+1:
    l[a].append(b)

ans = 0
a = []
for i in range(1,m+1):
  for j in l[i]:
    heappush(a,-j)
  if a:
    ans -= heappop(a)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.  You can take and complete at most one of these jobs in a day.  However, you cannot retake a job that you have already done.  Find the maximum total reward that you can earn no later than M days from today.  You can already start working today.

Submission attempts (in order):
N, M = map(int, input().split())
memo = [0] * M
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    memo[a] = max(b, memo[a])
ans = sum(memo)
print(ans)

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * N
ans = 0
for a, b in AB:
    Ma = M - a + 1
    if 0 in memo[:Ma]:
        i = bisect.bisect_right(memo[:Ma], 0) - 1
        memo[i] = 1
        ans += b
print(ans)

import bisect
 
 
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [x for x in range(N)]
ans = 0
for a, b in AB:
    if M < a:
        continue
    Ma = M - a
    i = bisect.bisect_right(memo, Ma)
    if i > 0:
        del memo[i - 1]
        ans += b
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted