Problem:


Score : 400 points

Problem Statement

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.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i \leq 10^5

1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the maximum total reward that you can earn no later than M days from today.

Sample Input 1

3 4
4 3
4 1
2 2

Sample Output 1

5

You can earn the total reward of 5 by taking the jobs as follows:

Take and complete the first job today. You will earn the reward of 3 after four days from today.

Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.

Sample Input 2

5 3
1 2
1 3
1 4
2 1
2 3

Sample Output 2

10

Sample Input 3

1 1
2 1

Sample Output 3

0



Sample input:
3 4
4 3
4 1
2 2


Sample output:
5

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    
    ans += heapq.heappop(hq)
print(-ans)

Submission status: Runtime Error

Solution code:
import heapq

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

ans=0
p=[]
heapq.heapify(p)
for i in range(m):
    if len(p)==0 and len(X[i])==0:
        continue
    for j in range(len(X[i])):
        heapq.heappush(p,X[i][j])
    a=heapq.heappop(p)
    ans+=a*-1
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs.sort()

i = 0
works = []
reward = 0
for d in range(m):
  while i < n and jobs[i][0] <= d + 1:
    heapq.heappush(works, -jobs[i][1])
    i += 1
  if works:
    reward -= heapq.heappop(words)
print(reward)

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N, M = LI()
    jobsavailable = [[] for _ in range(10**5+1)]
    for _ in range(N):
        a, b = LI()
        if a > M:
            continue
        jobsavailable[M-a].append(b)
    cur_jobs = []
    cnt = 0
    for i in range(1, M+1):
        # a <= iのなかで最大のbがあるものをとりだす
        jobs = jobsavailable[M-i]
        cur_jobs.extend(jobs)
        heapq._heapify_max(cur_jobs)
        if cur_jobs != []:
            j = heapq._heappop_max(cur_jobs)
            cnt += j
    print(cnt)

main()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N, M = LI()
    jobsavailable = [[] for _ in range(10**5+1)]
    for _ in range(N):
        a, b = LI()
        if a > M:
            continue
        jobsavailable[M-a].append(b)
    cur_jobs = []
    cnt = 0
    for i in range(1, M+1):
        # a <= iのなかで最大のbがあるものをとりだす
        jobs = jobsavailable[M-i]
        cur_jobs.extend(jobs)
        heapq._heapify_max(cur_jobs)
        if cur_jobs != []:
            j = heapq._heappop_max(cur_jobs)
            cnt += j
    print(cnt)


'''
def main():
    N, M = LI()
    ab = []
    for _ in range(N):
        a, b = LI()
        ab.append((a, b))
    ab = sorted(ab, key=lambda x: (x[1], x[0]))[::-1]
    i = 0
    cnt = 0
    print(ab)
    while 0 < M and i < N:
        day, money = ab[i]
        if day > M:
            pass
        else:
            cnt += money
            M -= 1
        i += 1
    print(cnt)
'''

main()

Submission status: Runtime Error

Solution code:
import heapq

n,m=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
Y=sorted(X,key=lambda x:(x[0]))
ans=0
c=0
x=[0]*n
heapq.heapify(x)
flag=True
for i in range(1,m+1):
    if flag:
        while Y[c][0]<=i:
            heapq.heappush(x,Y[c][1])
            c+=1
            if c==len(Y):
                flag=False
                break
    ans+=heapq.heappop(x)*(-1)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n, m = map(int, input().split())
data = getSomeInputListInt(n)

data_list = [[0] for _ in range(m)]

for i in range(n):
    if data[i][0]-1 < n:
        data_list[data[i][0]-1].append(-data[i][1])

heap_list = []
heapq.heapify(heap_list)

ans = 0
for i in range(0, m):
    heap_list.extend(data_list[i])
    heapq.heapify(heap_list)
    a = heapq.heappop(heap_list)
    ans += a

print(-ans)

Submission status: Runtime Error

Solution code:
import heapq
n,m=map(int,input().split())
ab=[[] for _ in range(m+1)]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    a[i].append(-b)

cand=[]
heapq.heapify(cand)
ans=0
for i in range(1,m+1):
  for j in range(len(ab[i])):
    heapq.heappush(cand,ab[i][j])
  if len(cand)>0:
    ans-=heapq.heappop(cand)

print(ans)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#Binary Indexed Tree (1-indexなので注意！！！！！！！！)
class BinaryIndexedTree():
    def __init__(self, size):
        self.__node=[0]*(size+1)
        self.size = size

    #node[index]にvalueを足して、BITを更新
    def add(self, index, value):
        while index <= self.size:
            self.__node[index] += value
            index += index&-index    
    
    #indexまでの和を返す
    def sum(self, index):
        ret = 0 #零元・単位元
        while index > 0:
            ret += self.__node[index]
            index -= index&-index    
        return ret

    def update_max(self, index, value):
        while index <= self.size:
            self.__node[index] = max(self.__node[index], value)
            index += index & -index


    #indexまでの最大値を返す
    def query_max(self, index):
        ret = 0
        while index > 0:
            ret = max(ret, self.__node[index])
            index -= index & -index
        return ret
        
        

    #0-indexでの添字を受け取って、1-indexでの添字での値を返す
    def get_node(self, index):
        return self.__node[index]
def main():
    N,M=MI()
    AB=LLIN(N)
    AB.sort(reverse=True)

    B = BIT()
    ans = 0
    for a,b in AB:
        if M<=b:
            continue
        lim = M-b
        if B.sum(lim)<lim:
            ans += a
            B.add(lim,1)
    print(ans)
            


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    
import numpy as np
dp = np.zeros([N+1, max(max(A), M)+1])
    
for i in range(1, N+1):
    for j in range(min(A[i-1], M+1), M+1):
        dp[i][j] = B[i-1]

ans = 0
for j in range(1, M+1):
    i = np.argmax(dp[:, j])
    ans += dp[i, j]
    dp[i, :] = 0
print(int(ans))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    
import numpy as np
dp = np.zeros([N+1, max(max(A), M)+1])
    
for i in range(1, N+1):
    for j in range(A[i-1], M+1):
        dp[i][j] = B[i-1]

ans = 0
for j in range(1, M+1):
    i = np.argmax(dp[:, j])
    ans += dp[i, j]
    dp[i, :] = 0
print(int(ans))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

import numpy as np
dp = np.zeros([N+1, M+1])
    
for i in range(1, N+1):
    for j in range(A[i-1], M+1):
        dp[i][j] = B[i-1]

ans = 0
for j in range(1, M+1):
    i = np.argmax(dp[:, j])
    ans += dp[i, j]
    dp[i, :] = 0
print(int(ans))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
AB = [None] * n
maxa = 0
for i in range(n):
    AB[i] = tuple(map(int, input().split()))
    if AB[i][0] > maxa:
        maxa = AB[i][0]
AB.sort(key=lambda ab: -ab[1])
cands = [AB[i][1] for i in range(m - maxa)]
counts = [0] * m
for i in range(m - maxa, n):
    if AB[i][0] <= m and sum(counts[AB[i][0] - 1:]) <= m - AB[i][0]:
        cands.append(AB[i][1])
        counts[AB[i][0] - 1] += 1
print(sum(cands[:m]))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cands = [[] for _ in range(m)]
counts = [0] * m
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        cands[a - 1].append(b)
        counts[a - 1] += 1
for i in range(m):
    if cands[i]:
        cands[i].sort()
score = 0
total = 0
for i in range(m):
    maxv = 0
    idx = -1
    for j in range(i + 1):
        if counts[j] and maxv < cands[counts[j] - 1]:
            maxv = cands[counts[j] - 1]
            idx = j
    if idx >= 0:
        score += maxv
        counts[idx] -= 1
    total += 1
    if total >= n:
        break
print(score)

Submission status: Runtime Error

Solution code:
ab = sorted(ab, key= lambda x:(x[0]))

from heapq import heappush,heappop

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

hq = []
j = 0
ans = 0

for i in range(m):
  while j<n and ab[j][0] <= i+1:
    heappush(hq,-ab[j][1])
    j+=1
  if len(hq)>0:
    ans += -heappop(hq)
    
print(ans)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline
 
import heapq
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
heap = []
ans = 0
j = 0
 
for i in range(1, M+1): # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i): # 支払いがi日以内
        heapq.heappush(heap, -X[j][1]) # 候補の追加。最大の値が欲しいためマイナスに
        j += 1
    if len(heap):
        ans += - heapq.heappop(heap) # 候補があるとき、候補から最大値を取り出す
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

#日数ごとの集合を作る
jobs = {m: [] for m in range(1, M + 1)}
for ab in A_B:
  if a in jobs:
    jobs[ab[0]].append(ab[1])
#print(jobs)

#日数の少ない仕事からループして最適解を見つける
import heapq
q = []
ans = 0
#仕事にかかる日数のループであって経過日のループではない
for m in range(1, M + 1):
    for b in jobs[m]:
      #qには小さい順で格納される
      heapq.heappush(q, -b)
    #print(q)
    #qが空でないとき
    if len(q) > 0:
      #現時点での日数以下の仕事で一番稼げるものを取り出す
      neg_b = heapq.heappop(q)
      ans += -neg_b

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
A_B = [list(map(int, input().split())) for i in range(N)]

#日数ごとの集合を作る
jobs = {m: [] for m in range(1, M + 1)}
for ab in A_B:
  jobs[ab[0]].append(ab[1])
#print(jobs)

#日数の少ない仕事からループして最適解を見つける
import heapq
q = []
ans = 0
#仕事にかかる日数のループであって経過日のループではない
for m in range(1, M + 1):
    for b in jobs[m]:
      #qには小さい順で格納される
      heapq.heappush(q, -b)
    #print(q)
    #qが空でないとき
    if len(q) != 0:
      #現時点での日数以下の仕事で一番稼げるものを取り出す
      neg_b = heapq.heappop(q)
      ans += -neg_b

print(ans)

Submission status: Runtime Error

Solution code:
import heapq
N, M = map(int, input().split())
jobs = {m:[] for m in range(1,M+1) }

for i in range(N):
  hi,yen = map(int, input().split())
  jobs[hi].append(yen)
  
q = []
ans = 0
for i in range(1,M+1):
  for j in jobs[i]:
    heapq.heappush(q, -j)
  if len(q) > 0:
    a = heapq.heappop(q)
    ans += -a  
print(ans)

Submission status: Runtime Error

Solution code:
import heapq
N,M = map(int,input().split())
AB = [[] for i in range(M+1)]
for i in range(N):
    a,b = list(map(int,input().split()))
    AB[a].append(-b)
work = 0
AB2 = []
for i in range(1,M+1):
    AB2 += AB[i]
    heapq.heapify(AB2)
    if not AB2:
        continue
    b = heapq.heappop(AB2)
    work += -b
print(work)

Submission status: Runtime Error

Solution code:
import heapq

N,M = (int(x) for x in input().split())
AB = []
sum = 0

for i in range(N):
    a,b = (int(x) for x in input().split())
    AB.append([a,b])

AB = sorted(AB , key = lambda x : x[1])

for i in range(M):
    if AB[N-i-1][0] <= M-i:
        sum += AB[N-i-1][1]
        AB.pop(N-i-1)

print(sum)

Submission status: Runtime Error

Solution code:
import heapq
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()

j = 0
b = [0]
heapq.heapify(b)
ans = 0
for i in range(1,m+1):
    # m日からi日前で出来る仕事を抽出
    while j < n and a[j][0] == i:
        heapq.heappush(b, -1*a[j][1])
        j += 1
    ans += -1*heapq.heappop(b)
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import heapq as hq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
ls = []
hq.heapify(ls)
k = max([a[0] for a in ab])
daylist = [0]*(k+1)
for i in range(n):
  daylist[ab[i][0]] += 1
daylistsum = list(accumulate(daylist))
ans = 0
for i in range(1,m+1):
  for j in range(daylistsum[i-1],daylistsum[i]):
    hq.heappush(ls,-ab[j][1])
  if ls:
    ans -= hq.heappop(ls)
print(ans)

Submission status: Runtime Error

Solution code:
nm=list(map(int,input().split()))
ab=[]
for i in range(nm[0]):
    ab.append(tuple(map(int,input().split())))
    if ab[-1][0]>nm[1]:
        del ab[-1]
ab=sorted(ab)
if ab==[]:
    print(0)
else:
    r=[]
    idx=0
    for i in range(nm[1]):
        r.append([])
        if ab[idx][0]==i+1:
            r[-1].append(ab[idx][1])
            while idx<nm[0]-1:
                idx+=1
                if ab[idx][0]==i+1:
                    r[-1].append(ab[idx][1])
                else:
                    break
    ans=0
    for i in range(nm[1]):
        if r[0]!=[]:
            ans+=max(r[0])
            r[0].pop(r[0].index(max(r[0])))
        if i!=nm[1]-1:
            t=r[0]+r[1]
            r=[t]+r[2:]
    print(ans)

Submission status: Runtime Error

Solution code:
nm=list(map(int,input().split()))
ab=[]
for i in range(nm[0]):
    ab.append(tuple(map(int,input().split())))
    if ab[-1][0]>nm[1]:
        del ab[-1]
ab=sorted(ab)
if ab==[]:
    print(0)
else:
    r=[]
    idx=0
    for i in range(nm[1]):
        r.append([])
        if ab[idx][0]==i+1:
            r[-1].append(ab[idx][1])
            while idx<nm[0]-1:
                idx+=1
                if ab[idx][0]==i+1:
                    r[-1].append(ab[idx][1])
                else:
                    break
        r[-1].sort(reverse=True)
    ans=0
    for i in range(nm[1]):
        if r[0]!=[]:
            ans+=r[0][0]
            r[0].pop(0)
        if i!=nm[1]-1:
            t=r[0]+r[1]
            r=[t]+r[2:]
            r[0].sort(reverse=True)
    print(ans)

Submission status: Runtime Error

Solution code:
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
        elif self.award==other.award and self.date<other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name>other.name:
            return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
        elif self.award==other.award and self.date>other.date:
            return True
        elif self.award==other.award and self.date=other.date and self.name<other.name:
            return False
        else:
            return False

jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            break
        
        
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import heapq

N,M = [int(k) for k in sys.stdin.readline().split()]

job=[]
for i in range(N):
    A,B = [int(k) for k in sys.stdin.readline().split()]
    job.append((A,-B))

job.sort(key=lambda t: -t[0])

heap=[]
heapq.heapify(heap)

ans=0

for i in range(1,M+1):
    if len(job)!=0:
      while job[-1][0]==i:
         heapq.heappush(heap,job.pop()[1])
          if len(job)==0:
             break
    if len(heap) == 0:
        continue
    ans -= heapq.heappop(heap)
    
print(ans)

Submission status: Runtime Error

Solution code:
import heapq
n, m = map(int, input().split())
day = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    day[a].append(b)
benefit = []
heapq.heapify(benefit)
ans = 0
for i in range(1, m+1):
    for j in day[i]:
        heapq.heappush(benefit, -j)
    if benefit:
        ans -= heapq.heappop(benefit)  # 最大値を加算
print(ans)

Submission status: Runtime Error

Solution code:
import heapq
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1): 
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1]) 
        j += 1
    if len(hq):
        ans += -heappop(hq)

print(ans)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop

N, M = map(int, input().split())
salary = [[] for i in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    salary[A].append(B)
queue = []
ans = 0

for i in range(1, M+1):
    for s in salary[i]:
        heappush(queue, -s)
    if queue:
        ans += -heappop(queue)

print(ans)

Submission status: Runtime Error

Solution code:
import copy
n, m = map(int, input().split())
ab_lis = []
for i in range(n):
    ab_lis.append(list(map(int, input().split())))
def rec(ab_lis, path, rew, r_day, m_ans):
    if r_day == 0:
        m_ans[0] = max(m_ans[0], rew)
        return
    for t_lis in ab_lis:
        if t_lis in path:
            continue
        elif t_lis[0] > r_day:
            m_ans[0] = max(m_ans[0], rew)
            continue
        path_c = copy.copy(path)
        path_c.append(t_lis)
        rec(ab_lis, path_c, rew + t_lis[1], r_day - 1, ans)    
m_ans = [0]
rec(ab_lis, [], 0, m, m_ans)        
print(m_ans[0])

Submission status: Runtime Error

Solution code:
import sys
import bisect
import numpy as np

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()
A = [MAP() for _ in range(N)]

A.sort()
A_day = [a[0] for a in A]
A_salary = [a[1] for a in A]

salary = 0
for i in range(M):
	print(A_day, M-i+1)
	idx = bisect.bisect_left(A_day, M-i+1)
	if idx == 0: continue
	todo = np.argmax(A_salary[:idx])
	print(i, idx, todo, A[todo], A_day[todo], A_salary[todo])
	salary += A_salary[todo]
	A_day.pop(todo)
	A_salary.pop(todo)

print(salary)

Submission status: Runtime Error

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

def calculate(N,M,arr):
    ret = 0

    j = 0

    res = []

    # 1,2,3,4,5
    #         ↑
    # 4,3,2,1

    # M = 4
    # range(1,5) => 1,2,3,4

    for i in range(1,M+1):
        # i = 1,2,3
        # 比如M=4的话，第三天(最多1天),第二天(最多2天),第一天(最多3天)

        # 记下来循环打工信息资源,以j为标记
        # j为资源编号
        # arr[j][0]为该编号资源的天数


        # 候补的资源，满足所有天数，因为是满足后续的天数来算的

        while (j < N) and (arr[j][0] <= i):

                heappush(res, -arr[j][1])
                j = j + 1 #j找到的话就往上顶一格，一共这一天，或者前一天寻找的时候以下一个资源天为开始

        if len(res) > 0:
            ret -= heappop(res)

    return ret


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


# 后面的逻辑是基于前面的从小到大的排序的
list = [list(map(int,input().split())) for i in range(N)]

arr = sorted(list,key=lambda x:x[0])

result = calculate(5,3,arr)

print(result)

Submission status: Runtime Error

Solution code:
from heapq import heappop, heappush


def calculate(N,M,arr):
    ret = 0

    j = 0

    res = []

    # 1,2,3,4,5
    #         ↑
    # 4,3,2,1

    # M = 4
    # range(1,5) => 1,2,3,4

    for i in range(1,M+1):
        # i = 1,2,3
        # 比如M=4的话，第三天(最多1天),第二天(最多2天),第一天(最多3天)

        # 记下来循环打工信息资源,以j为标记
        # j为资源编号
        # arr[j][0]为该编号资源的天数


        # 候补的资源，满足所有天数，因为是满足后续的天数来算的

        while (j < N) and (arr[j][0] <= i):

                heappush(res, -arr[j][1])
                j = j + 1 #j找到的话就往上顶一格，一共这一天，或者前一天寻找的时候以下一个资源天为开始

        if len(res) > 0:
            ret -= heappop(res)

    return ret


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


# 后面的逻辑是基于前面的从小到大的排序的
list = [list(map(int,input().split())) for i in range(N)]

arr = sorted(list,key=lambda x:x[0])

result = calculate(5,3,arr)

print(result)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + 1
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                # if arr[j][1] > value:
                #     index = j
                #     value = arr[j][1]
                # 
                # if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                #         index = j
                #         value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

N, M = map(int, input().split())
arr = []
for i in range(N):
    day, mount = map(int, input().split())
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):

            if len(arr) == 0:
                arr[j] = [0,0]
            if len(arr) == 1:
                arr[j][1] = 0

            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if arr[j][1] == value:
                    if arr[index][0] < arr[j][0]:
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

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


arr = []
for i in range(N):
    day, mount = map(int, input().split())
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum

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


arr = []
for i in range(N):
    day, mount = map(int, input().split())
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:
import heapq
n,m=map(int,input().split())
ab=[[0]*2 for _ in range(n)]


for i in range(n):
    ab[i]=list(map(int,input().split()))
ab.sort()
hq=[]
tmp=0
ans=0
for i in range(1,m+1):
    while tmp<n and ab[tmp][0]<=i:
        heapq.heappush(hq,-ab[tmp][1])
        tmq+=1
    if hq:
        ans-=heapq.heappop(hq)
print(ans)

Submission status: Runtime Error

Solution code:
def calculate(arr,M):
    sum = 0
    for i in range(M):
        index = 0
        value = 0
        for j in range(len(arr)):
            lastDay = i + arr[j][0]
            if lastDay <= M:
                if arr[j][1] > value:
                    index = j
                    value = arr[j][1]

                if (arr[j][1] == value) and (arr[index][0] < arr[j][0]):
                        index = j
                        value = arr[j][i]

        if len(arr) > 0:
            sum += value
            arr.pop(index)

        if len(arr) == 0:
            break

    return sum


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


arr = []
for i in range(N):
    day,mount = input().split()
    day = int(day)
    mount = int(mount)
    arr.append([day,mount])
result = calculate(arr,M)
print(result)

Submission status: Runtime Error

Solution code:

import bisect

N,M = map(int,input().split())
lis = [[int(i) for i in input().split()]for _ in range(N)]
day = [[] for _ in range(M)]
for li in lis:
    if li[0] <= M:
        day[li[0]].append(li[1])

ans = 0
joblis = []
for li in day:
    for i in li:
        joblis.insert(bisect.bisect_left(joblis,i),i)
    if len(joblis)!=0:
        ans += joblis.pop(-1)
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

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

L=[]
for i in range(M+1):
    L.append([])

for i in range(N):
    if AB[i][0]<=M:
        L[AB[i][0]].append(AB[i][1])

for i in range(N):
    if len(L[i])!=0:
        L[i].sort(reverse=True)
        break

LL=[]
money=0

for i in range(1,M+1):
    LL+=[-k for k in L[i]]
    if len(LL)==0:
        continue
    money+=heapq.heappop(LL)

print(-money)