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:
class Work:
    count=0
    def __init__(self,payday,money):
        Work.count+=1
        self.count=count
        self.payday=payday
        self.money=money
 #moneyが大きい方、同じなら早くもらえる方、それも同じなら最初に書いてある方が強い方
    def __gt__(self,other):
        if self.money>other.money:
            return True
        if self.money==other.money:
            if self.payday<other.payday:
                return True
            if self.payday==other.payday:
                if self.count<other.count:
                    return True
        return False

    def __ft__(self,other):
        if self.money<other.money:
            return True
        if self.money==other.money:
            if self.payday>other.payday:
                return True
            if self.payday==other.payday:
                if self.count>other.count:
                    return True
        return False

#     def __eq__(self,other):
#         if self.money==other.money and self.payday==other.payday:
#             return True
#         return False
#     def __fe__(self,other):
#         return self.__ft__(other) or self.__eq__(other)
#     def __ge__(self,other):
#         return self.__gt__(other) or self.__eq__(other)

#バイトの数、いつまでに稼ぐのか 
n,limit=[int(i) for i in input().split()]

#バイトのリストを作り、クラスを入れる O(n)
baitolist=[]
for i in range(n):
    payday,money=[int(i) for i in input().split()]
    work=Work(payday,money)
    baitolist.append(work)

#日数でランク付け　O(n)
summoney=0    
rank=[[] for i in range(limit+1)]
for baito in baitolist:
    if baito.payday<=limit:
        rank[baito.payday].append(baito)

accessible=[]
count=1
while baitolist and count<=limit:#最悪O(limit)
    for baito in rank[count]:
        accessible.append(baito)
    accessible.sort()
    if accessible!=[]:
        dowork=accessible.pop()
        summoney+=dowork.money
    count+=1
    
    
print(summoney)

Submission status: Runtime Error

Solution code:
NM = input().split()
N = NM[0]
M = NM[1]

taskDict = {}

for i in range(N):
  task = input().split()
  taskDict[task[0]].append(task[1])

print()

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
# /usr/bin/python3

from bisect import insort
from collections import deque

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = sorted([tuple(map(int, input().strip().split(' '))) for _ in range(n)], key=lambda x:x[0])

  k = 1
  top = deque()
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      for i in range(len(top)):
        if i < a-k:
          s += top[-1]
          del top[-1]
      k = a

    insort(top, b)


  s += top[-1]
  for i in range(m - k):
    s += top[-(i+1)]

  print(s)
  
  pass

if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
# /usr/bin/python3

from collections import defaultdict
from bisect import insort
from collections import deque

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = sorted([tuple(map(int, input().strip().split(' '))) for _ in range(n)], 
                key=lambda x:x[0])

  k = 1
  top = deque()
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      for i in range(len(top)):
        if i < a-k:
          s += top[-1]
          del top[-1]
      k = a

    insort(top, b)


  s += top[-1]
  for i in range(m - k):
    s += top[-(i+1)]

  print(s)
  
  pass

if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
import heapq
N , M = map(int , input().split())
jobs = [list(map(int , input().split())) for _ in range(N)]
jobs.sort()

q = []
index = 0
ans = 0
for limit in range(1 , M + 1):
    while index < N:
        time =jobs[index][0]
        reward = jobs[index][1]
        if limit >= time:
            heapq.heappush(q , -reward)
            index += 1
        else:
            break
    print(q)
    if len(q) != 0:
        tmp = heapq.heappop(q)
        ans -= tmp

print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)

inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

ans = 0
candidates = []
for reversed_day in range(1, m + 1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

ans = 0
candidates = []
for reversed_day in range(1, m+1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
inputs = [int(x) for x in input().split()]
n, m = inputs[0], inputs[1]
conditions = {}
for i in range(n):
  inputs = [int(x) for x in input().split()]
  if inputs[0] in conditions.keys():
    conditions[inputs[0]].append(inputs[1])
  else:
    conditions[inputs[0]] = [inputs[1]]

for day in conditions.keys():
  conditions[day].sort(reverse=True)

print(conditions)

ans = 0
candidates = []
for reversed_day in range(1, m+1):
  if reversed_day in conditions.keys():
    candidates.append(conditions[reversed_day])

  cand_len = len(candidates)
  if cand_len == 0:
    continue
  maxval, maxidx = 0, 0
  for i in range(cand_len):
    if candidates[i][0] > maxval:
      maxval = candidates[i][0]
      maxidx = i
  ans += candidates[maxidx].pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = [None] * (m + 1)
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if d1[a] is None:
      d1[a] = [b]
    else:
      d1[a].append(b)
  result = 0
  d2 = {}
  maxb = -1
  for i in _range(1, m + 1):
    if d1[i] is None:
      if _len(d2) == 0:
        continue
    else:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 1
        else:
          d2[j] += 1
        if j > maxb:
          maxb = j
    result += maxb
    d2[maxb] -= 1
    if d2[maxb] == 0:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        maxb = _max(d2.keys())
  print(result)
main()

Submission status: Runtime Error

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = [None] * (m + 1)
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if d1[a] is None:
      d1[a] = [b]
    else:
      d1[a].append(b)
  result = 0
  d2 = {}
  maxb = -1
  for i in _range(1, m + 1):
    if d1[i] is None:
      if _len(d2) == 0:
        continue
    else:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 1
        else:
          d2[j] += 1
        if j > maxb:
          maxb = j
    else:
    result += maxb
    d2[maxb] -= 1
    if d2[maxb] == 0:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        maxb = _max(d2.keys())
  print(result)
main()

Submission status: Runtime Error

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

q = []
idx = 0
ans = 0
for i in range(1, M+1):
    while idx < N:
        a, b = AB[idx]
        if a <= i:
            heapq.heappush(q, -b)
            idx += 1
        else:
            break
    if len(q) > 0:
        b = heapq.heappop(q)
        ans -= b

print(ans)

Submission status: Runtime Error

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  maxbn = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
        if j > maxb:
          maxbn = maxb
          maxb = j
        elif j > maxbn:
          maxbn = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
        maxbn = -1
      else:
        if maxbn != -1:
          maxb = maxbn
          maxbn = -1
        else:
          maxb = _max(d2.keys())
    else:
      d2[maxb] -= 1
  print(result)
main()

Submission status: Runtime Error

Solution code:
def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = {}
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if a in d1:
      d1[a].append(b)
    else:
      d1[a] = [b]
  result = 0
  d2 = {}
  maxb = -1
  maxbn = -1
  for i in _range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
        if j > maxb:
          maxbn = maxb
          maxb = j
        elif j > maxbn
          maxbn = j
    else:
      if _len(d2) == 0:
        continue
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
        maxbn = -1
      else:
        if maxbn != -1:
          maxb = maxbn
          maxbn = -1
        else:
          maxb = _max(d2.keys())
    else:
      d2[maxb] -= 1
  print(result)
main()

Submission status: Runtime Error

Solution code:
import bisect
import time


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


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

# 日数でソート
ind_sorted = sorted(range(N), key = lambda x:A[x])

tmp_a = 0
tmp_b_ls = [0]
money = 0
tmp_ind = 0
for i in range(N):
    if A[ind_sorted[i]] > M:
        break
    if tmp_a != A[ind_sorted[i]]:
        d = A[ind_sorted[i]]-tmp_a
        tmp_money = sum(tmp_b_ls[-d:])
        money += tmp_money
        # 最大値以外を取り除く
        tmp_b_ls = tmp_b_ls[max(0,(M-1)-(len(tmp_b_ls)-d)):-d]
        tmp_a = A[ind_sorted[i]]
    bisect.insort(tmp_b_ls[],B[ind_sorted[i]])

d = M+1-tmp_a
tmp_money = sum(tmp_b_ls[-d:])
money += tmp_money

print(money)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
dic = {i:[] for i in range(1,M+1)}
for i in range(N):
  A, B = map(int, input().split())
  if A<=M:
    dic[A] += [B]
key = list(dic.keys())
key.sort()
ans = 0
ls = []
pm = 0
m = 0
for i in range(1,M+1):
  if dic[i]:
    x = max(dic[i])
    if m < x:
      ans += x
      dic[i].remove(x)
      ls += dic[i]
    else:
      ans += m
      ls.remove(m)
      ls += dic[i]
  else:
    ans += m
    ls.remove(m)
  m = max(ls)
  
  
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

# initialize
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
hiyatoi = np.array(hiyatoi)
day = m
salary = 0

for index in range(day):
  # delete the job passed deadline
  if hiyatoi[:,0].max() > day:
    delete_job_index = np.where(hiyatoi[:,0]==hiyatoi[:,0].max().max())[0]
    hiyatoi[delete_job_index] = [0,0]
  # search max salary job
  max_salary_index = np.where(hiyatoi[:,1]==hiyatoi[:,1].max())[0]
  # the number of jobs > 1
  if len(max_salary_index) > 1:
    # search max day job
    max_day_index = np.where(hiyatoi[:,0]==hiyatoi[:,0].max())[0]
    # select max salary & day job
    selected_work = np.where(max_salary_index==max_day_index)[0]
    # obtain the salary
    salary += hiyatoi[max_salary_index[selected_work]][0][1]
    # delete the job
    hiyatoi[max_salary_index[selected_work]] = [0,0]
  # the number of jobs == 1
  else:
    # obtain the salary
    salary += hiyatoi[max_salary_index][0][1]
    # delete the job
    hiyatoi[max_salary_index] = [0,0]
  day -= 1

print(salary)

Submission status: Runtime Error

Solution code:
import numpy as np

# initialize
n,m = list(map(int,input().split()))
hiyatoi = [list(map(int,input().split())) for index in range(n)]
hiyatoi = np.array(hiyatoi)
day = m
salary = 0

for index in range(int(len(hiyatoi))-2):
  # delete the job passed deadline
  if hiyatoi[index][0] >= day:
    hiyatoi[index] = [0,0]
  # search max salary job
  max_salary_index = np.where(hiyatoi[:,1]==hiyatoi[:,1].max())[0]
  # the number of jobs > 1
  if len(max_salary_index) > 1:
    # search max day job
    max_day_index = np.where(hiyatoi[:,0]==hiyatoi[:,0].max())[0]
    # select max salary & day job
    selected_work = np.where(max_salary_index==max_day_index)[0]
    # obtain the salary
    salary += hiyatoi[max_salary_index[selected_work]][0][1]
    # delete the job
    hiyatoi[max_salary_index[selected_work]] = [0,0]
  # the number of jobs == 1
  else:
    # obtain the salary
    salary += hiyatoi[max_salary_index][0][1]
    # delete the job
    hiyatoi[max_salary_index] = [0,0]
  day -= 1

print(salary)

Submission status: Runtime Error

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

total = 0
for i in range(m):
  max=0
  max_j=0
  max_day=0
  #残り日数 m-iより支払い日が短いもので最大の値をとる
  for j in range(len(w)):
    if w[j][0] <= m-i and w[j][1] > max: # 最大値が来たときは置き換え
      max = w[j][1]
      max_j=j
      max_day=w[j][0]
    elif w[j][0] <= m-i and w[j][1] == max:#最大値と同じ値のときは、日数が長いものを採用
      if w[j][0] > max_day:
        max = w[j][1]
        max_j=j
        max_day=w[j][0]
        
  total = total+max
  if(len(w)>0):
    w.remove(max_j)

print(total)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
data = [[int(e) for e in input().split()] for _ in range(n)]
d1 = {}
for i in range(n):
  a, b = data[i]
  if a not in d1:
    d1[a] = []
  d1[a].append(b)
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)

Submission status: Runtime Error

Solution code:
def hoge():
  n, m = map(int, input().split())
  data = [[int(e) for e in input().split()] for _ in range(n)]
  d1 = {}
  for i in range(n):
    a, b = data[i]
    if a not in d1:
      d1[a] = []
    d1[a].append(b)
  result = 0
  d2 = {}
  maxb = -1
  for i in range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
        if j > maxb:
          maxb = j
    else:
      if len(d2) == 0:
        continue
    if maxb == -1:
      maxb = max(d2.keys())
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
      maxb = -1
    else:
      d2[maxb] -= 1
  print(result)
main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
data = [[int(e) for e in input().split()] for _ in range(n)]
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j in d2:
        d2[j] += 1
      else:
        d2[j] = 1
  if len(d2.keys()) == 0:
    continue
  maxb = max(d2.keys())
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
  else:
    d2[maxb] -= 1
print(result)

Submission status: Runtime Error

Solution code:
import heapq
 
 
 
n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))


t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m+1):
    while t_r_list[l][0] == j:
        heapq.heappush(que, -t_r_list[l][1])
        l += 1
        if l >= n:
            break
        
 
    if que:
        total -= heapq.heappop(que)
      
      
print(total)

Submission status: Runtime Error

Solution code:
import heapq
 
 
 
n, m = map(int, input().split())
t_r_list = []
for i in range(n):
    t_r_list.append(list(map(int, input().split())))


t_r_list.sort()
que = []
total = 0
l = 0
for j in range(1, m+1):
    while j < m and t_r_list[l][0] == j:
        heapq.heappush(que, -t_r_list[l][1])
        l += 1
        if l >= n:
            break
        
 
    if que:
        total -= heapq.heappop(que)
      
      
print(total)

Submission status: Runtime Error

Solution code:
import heapq
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
jobs = []

for i in range(N):
	a, b = map(int, input().split())
	if a <= M:
		jobs.append((a, b))
	
jobs.sort()
index = 0
ans = 0
myheap = []

for day in range(M - 1, -1, -1):
	for i in range(index, N):
		if (day + jobs[i][0]) < (M + 1):
			heapq.heappush(myheap, -jobs[i][1])
		else:
			index = i
			break
			
	if len(myheap) > 0:
		ans -= heapq.heappop(myheap)
		
print(ans)

Submission status: Runtime Error

Solution code:
import  heapq

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

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

day = M
reward = 0

# d日前
q = []
i = 0
for d in range(1, M + 1):
    for t in range(i, N):
        if data[t][0] > d:
            break
        i += 1
        heapq.heappush(q, -1 * data[t][1])
    reward += heapq.heappop(q)

print(-1 * reward)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
from collections import defaultdict
dic = defaultdict(list)
l = []
for i in range(n):
    a,b=map(int,input().split())
    dic[a].append(b)
s = 0
t = [0,0,0,0,0,0,0,0,0,0,0]
for i in range(m):
    t += dic[i+1]
    M = max(t)
    s +=M
    t.remove(M)
print(s)

Submission status: Runtime Error

Solution code:
import heapq
from collections import defaultdict

read = lambda: map(int, raw_input())
n, m = read()
jobs = [read() for _ in xrange(n)]
jobs_by_time = defaultdict(list)
for (a, b) in jobs:
  jobs_by_time[a].append(b)

ans = 0
q = [] # heapq
for t in xrange(0, m):
  day = t+1
  for job in jobs_by_time[day]:
    heapq.heappush(q, -job)
  
  if q:
    val = -heapq.heappushpop(q)
    ans += val
print ans

Submission status: Runtime Error

Solution code:
import heapq
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
for _ in range(N):
    A, B = map(int, input().split())

hq = []
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
from heapq import heappop,heappush
from collections import defaultdict
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab_sort = sorted(ab,key=lambda x:x[0])
h_queue = []
j = 0
ans = 0
for i in range(1,m+1):
    while (j < n) and (ab_sort[j] <= i):
        heappush(h_queue,ab_sort[j])
        j += 1
    if len(h_queue):
        ans -= heappop(h_queue)
print(ans)

Submission status: Runtime Error

Solution code:
N_baito,M_days = map(int,input().split())
baitoList = np.array([list(map(int,input().split())) for i in range(N_baito)])
workList = []
hosyu = 0
for day in range(M_days+1):
    workList.extend(baitoList[baitoList[:,0]==day][:,1].tolist())
    workList.sort(reverse=True)
    if workList:
        hosyu += workList[0]
        del workList[0]
print(hosyu)

Submission status: Runtime Error

Solution code:
Copy
# -*- coding: utf-8 -*-
 
 
def main():
    # ヒープキューをインポート
    from heapq import heappush, heappop
 
    n, m = map(int, input().split())
    jobs = [[] for _ in range(m)]  # 締め切り別に，報酬を管理
 
    # See:
    # https://www.youtube.com/watch?v=1Z6ofKN03_Y
    for i in range(n):
        ai, bi = map(int, input().split())
 
        # 報酬が振り込まれる日がM日よりも後になる場合は除外
        if ai > m:
            continue
 
        # i件目のアルバイトを遅くてもいつまでに始める必要があるかを計算
        # heappopは最小値を返す．biを-1倍することで，最大値が取り出せる
        deadline = m - ai
        jobs[deadline].append(-bi)
 
    ans = 0
    reward = []
 
    # M-1日に始める必要があるアルバイトのうち，最も報酬の高いものを選択
    # 以降，今日始める必要があるアルバイトまで，順番に調べる
    # ある時点で得られる報酬の大小に着目
    for i in range(m - 1, -1, -1):
        for job in jobs[i]:
            # ヒープキューに，報酬の候補を追加
            heappush(reward, job)
 
        # 条件を満たすもののうち，最大の報酬を選択
        if reward:
            ans += heappop(reward)
 
    # ヒープキューに追加するときに，-1倍した分を元に戻す
    print(-ans)
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
  n, m = map(int, input().split())
  data = [[int(e) for e in input().split()] for _ in range(n)]
  d1 = {}
  for i in range(n):
    a, b = data[i]
    if a not in d1:
      d1[a] = []
    d1[a].appned(b)
  result = 0
  d2 = {}
  for i in range(1, m + 1):
    if i in d1:
      for j not in d1[i]:
        if j in d2:
          d2[j] = 0
        d2[j] += 1
    if len(d2.keys()) == 0:
      continue
    maxb = max(d2.keys())
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
main()

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,m = map(int,input().split())
	ab = [list(map(int,input().split())) for _ in range(n)]
	#unti = sorted(ab, key = lambda x:x[0])
	#ab_sorted = sorted(unti, key =  lambda x:x[1])
	ans = 0
	for i  in range(1,m+1):
		for j in reversed(ab_sorted):
			if(j[0] <= i):
				ans += j[1]
				ab_sorted.remove(j)
				break
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Runtime Error

Solution code:
import heapq
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
jobs = [[] for i in range(m)]

for i in range(n):
    tmp,tmp2 = map(int,stdin.readline().rstrip().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
print(jobs)
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,-b)
    print(h)
    if(len(h)!=0):
        a = -heapq.heappop(h)
        ans += a
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import heapq

N, M = map(int, input().split())
Wlist = []
for i in range(N):
    A, B = map(int, input().split())
    Wlist.append([A,B])
Wlist.sort(key=lambda x:x[0])

h = []
Ans = 0
Index = 0
for day in range(1,M+1):
    while Index < N:
        if Wlist[Index][0] <= day:
            heapq.heappush(h, -Wlist[Index][1])
            Index += 1
        else:
            break
    Ans += -heapq.heappop(h)

print(Ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int N, M;
vector<vector<int> > jobs;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N >> M;
	jobs.resize(M);
	for(int n=0; n<N; n++) {
		int a,b;
		cin >> a >> b;
		if (M-a<0) {
			continue;
		}
		jobs[M-a].push_back(b);
	}

	int ans = 0;
	priority_queue<int> q;
	for(int m=M-1; m>=0; m--) {
		for(vector<int>::iterator it=jobs[m].begin();
				it!=jobs[m].end(); it++) {
			q.push(*it);
		}
		if (!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
import heapq

n,m = (int(i) for i in input().split())
jobs = [[] for i in range(m)]
for i in range(n):
    tmp,tmp2 = (int(i) for i in input().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
    
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,b)
        heapq._heapify_max(h)
        
    if(len(h)!=0):
        ans += heapq._heappop_max(h)
        print(h)

print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    temp = list(map(int,input().split()))
    if temp[0] <= M:
        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
print(sum(work_schedule))

Submission status: Runtime Error

Solution code:
n,m = (int(i) for i in input().split())
a=[]
b=[]
jobs = [[] for i in range(m)]
for i in range(n):
    tmp,tmp2 = (int(i) for i in input().split())
    if(tmp>m):
        continue
    a.append(tmp)
    b.append(tmp2)
    jobs[m-tmp].append(tmp2)
    
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,b)
        heapq._heapify_max(h)
        
    if(len(h)!=0):
        ans += heapq._heappop_max(h)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = [[0, 0] for i in range(n)]
for i in range(n):
  a[i][0], a[i][1] = map(int, input().split())
a.sort(reverse=True, key=lambda x:x[1], x[0])

i = 0
b = 0
ans = 0
while(i == n or m < 1):
  if m >= b + a[i][0]:
    ans += a[i][1] 
    b += a[i][0]
    m -= 1
  i += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq
N, M =map(int, input().split())
A = [[] for i in range(10**5+1)]
 
for i in range(N):
    a, b = map(int,input().split())
    if a > m:
        continue
    A[a].append(-b)
 
work_cand = []
sum = 0
 
for i in range(M+1):
    add_jobs = A[i]
    if len(add_jobs) != 0:
        for j in add_jobs:
            heapq.heappush(work_cand, j)
    if len(work_cand) == 0:
        continue
    sum += heapq.heappop(work_cand)
ans = -(sum)
print(ans)