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:
N, M = map(int, input().split())
valuesDict = {}
for _ in range(N):
  A, B = map(int, input().split())
  valuesDict[A] = B if valuesDict[A] >= B else valuesDict[A]

answer = 0
for i in range(M):
  today = i + 1
  answer += valuesDict.get(today) if valuesDict.get(today) is not None else 0

print(answer)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
valuesDict = {}
for i in range(N):
  today = i + 1
  A, B = map(int, input().split())
  valuesDict[today+A] += B
answer = 0
for i in range(M):
  today = i + 1
  answer += valuesDict[today]

print(answer)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
valuesDict = {}
for i in range(N):
  A, B = map(int, input().split())
  valuesDict[i+A] += B

print(valuesDict[M])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]
AB.sort(key=lambda x:(x[0],-x[1]))

cnt = 1
ans = 0
while cnt <= m:
  num_a = 0
  num_b = 0
  for i in range(n):
    if AB[i][0] <= cnt:
      if AB[i][1] >= num_a:
        num_a = AB[i][1]
        num_b = i
      
  ans += num_a
  AB.pop(num_b)
  cnt += 1
  n -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())

j = []
for _ in range(n):
    a,b = map(int, input().split())
    if a <= m :
        j.append([a,b])
j.sort(reverse=True)
p = 0
temp = []
for i in range(1, m+1):
    while j and j[-1][0] <= i:
        a,b = j.pop()
        temp.append(b)
    p+=max(temp)
    temp.remove(max(temp))
print(p)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())

j = []
for _ in range(n):
    a,b = map(int, input().split())
    if a <= m :
        j.append([a,b])
j.sort()
p = 0
temp = []
for i in range(1, m+1):
    while j and j[0][0] <= i:
        a,b = j.pop(0)
        temp.append(b)
    p+=max(temp)
    temp.remove(max(temp))
print(p)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())

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

j.sort()
p = 0
temp = []
for i in range(1, m+1):
  while j and j[0][0] <= i:
      a,b = j.pop(0)
      temp.append(b)
  p+=max(temp)
  temp.remove(max(temp))
print(p)

Submission status: Runtime Error

Solution code:
n_jobs, n_days = [int(x) for x in input().strip().split()]

job_pay_dur = []

for i in range(n_jobs):
    tup = *(int(x) for x in input().strip().split()),
    job_pay_dur.append(tup)

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

reward = 0
days_left = n_days

for dur, pay in job_pay_dur:
    if dur <= days_left:
        reward += pay
        days_left -= 1

print(reward)

Submission status: Runtime Error

Solution code:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    if i >=M:
        continue
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Submission status: Runtime Error

Solution code:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    if i <=M:
        continue
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Submission status: Runtime Error

Solution code:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Submission status: Runtime Error

Solution code:
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=heapq.heapify([])
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq

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

a = [[] for i in range(m)]
d = []
heapq.heapify(d)

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

#print(a)

ans = 0
for i in range(m):
    for j in range(len(a[i])):
        heapq.heappush(d,a[i][j])
    ans -= heapq.heappop(d)

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())

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

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

#print(a)

ans = 0
for i in range(m):
    if a[m - 1 - i] != []:
        ans += max(a[m - 1 - i])

print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int, input().split())
a_b_list = []
for i in range(N):
    a,b = map(int, input().split())
    a_b_list.append([a,b])

a_b_list.sort(key=lambda x:(x[1],x[0]))
a_b_list.reverse()
#print(a_b_list)
task_list = [0] * (M+1)


for a,b in a_b_list:
#    print(a, b)
    if task_list[a] == 0:
#        print("append")
        task_list[a] = b
    else:
#        print("NOT append")
        index = a + 1
        while index <= M:
            if task_list[index] == 0:
                task_list[index] = b
                break
            index += 1
print(sum(task_list))
#print(task_list)

Submission status: Runtime Error

Solution code:
import numpy as np
c=list(map(int,input().split()))
n,m=c[0],c[1]
c=np.array([list(map(int,input().split())) for i in range(n)])
boo=np.zeros(m)
one=np.ones(m)
c=c[c[:,1].argsort(), :]
index=n-1
value=0
maxM=m-1
j=m
while(j>0):
	if index<0 :break
	while(index>=0):
		k=c[index,0]
		if k<= maxM+1:
			if boo[i]<m-i:
				boo[:i+1]=boo[:i+1]+one[:i+1]
				value=value+c[index,1]
				j=j-1
			else:
				maxM=k-2
		index=index-1
print(value)

Submission status: Runtime Error

Solution code:
import heapq

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

c = [[]for i in range(10**5)]

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


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

for i in range(m):
    for x in c[i+1]:
        heapq.heappush(h,x)
    if h:
        ans += heapq.heappop(h)

print(-ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 21 23:12:22 2019

@author: Yamazaki Kenichi
"""
import heapq

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

AB.sort()

q = [0 for _ in range(N)]
j = 0
ans = 0
for i in range(1,M+1):
    while j < N and AB[j][0] == i:
        heapq.heappush(q,-AB[j][1])
        j += 1
    ans += (-heapq.heappop(q))
#    print(i,j,ans,q)
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

N, M = map(int, input().split())
works = [[] for _ in range(M+1)]
for _ in range(N):
  day, reward = map(int, input().split())
  works[day].append(reward)
hp = []
ans = 0
for day in range(1, M+1):
  if len(works[day]) > 0:
    for reward in works[day]:
      heapq.heappush(hp, -reward)
  if len(hp) > 0:
    ans += -heapq.heappop(hp)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from heapq import*
N,M=map(int,input().split())
t=[list(map(int,input().split())) for _ in range(N)]
q=[0]*M
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]
for i in v:
    for j in i:heappush(q,-j)
    z-=heappop(q)
print(z)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

    #find maximum day
    work_day = max(workdays[:latest+1])
    if work_day == -1:
        continue
    else:
        workdays[work_day] = -1
        sum += reward

print(sum)

Submission status: Runtime Error

Solution code:
from collections import deque
N,M=map(int,input().split())
l=[]
for i in range(N):
  l.append(list(map(int,input().split())))
l=deque(sorted(l))
ans=0
m=0
while m < M:
  if l[-1][0]<=M-m:
    ans+=l.pop()[1]
    m+=1
  else:
    l.pop()
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.array(A)

cnt = 0
for day in range(1,M+1):
    B = A[A[:,0]<=day,1]
    if B.size > 0:
        index = np.argmax(B)
        cnt += B[index]
        A = np.delete(A,index,0)

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.array(A)

cnt = 0
for day in range(1,M+1):
    B = A[A[:,0]<=day,1]
    if B.size > 0:
        index = np.argmax(B)
        cnt += B[index]
        A = np.delete(A,index,0)
print(cnt)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
jobs = [[] for i in range(100001)]
for i in range(n):
    a1,b1 = map(int,input().split())
    jobs[a1 - 1].append(b1)
result = 0
for i in range(m):
    jobs_1 = 0
    jobs_2 = 0
    reward = 0
    for j in range(i+1):
        if len(jobs[j]) != 0:
            reward = max(reward,max(jobs[j]))
            jobs_1 = j
            jobs_2 = jobs[j].index(max(jobs[j]))
    if reward != 0:
        result += reward
        del jobs[jobs_1][jobs_2]
print(result

Submission status: Runtime Error

Solution code:
# D - Summer Vacation

_input = list(map(int, input().split()))
n = _input[0]
m = _input[1]
jobs = dict()
for i in range(n):
    __input = list(map(int, input().split()))
    a = __input[0]
    b = __input[1]
    item = jobs[b] if b in jobs else list()
    item.append(a)
    item.sort(reverse=True)
    jobs[b] = item

sorted(jobs.items(), key=lambda j: -j[0])
reward = 0
while m > 0:
    for b, aList in jobs:
        if len(aList) > 0 and m >= aList[0]:
            reward += b
            aList.pop(0)
            jobs[b] = aList
            break
    m -= 1

print(reward)

Submission status: Runtime Error

Solution code:
from sys import stdin
def main()
  from builtins import int, map, range
  readline = stdin.readline
  from heapq import heappush, heappop
  n, m = map(int, readline().split())
  jobs = {}
  for _ in range(n):
    a, b = map(int, readline().split())
    if a > m:
      continue
    if a in jobs:
      jobs[a].append(b)
    else:
      jobs[a] = [b]
  result = 0
  candidates = []
  for a in range(1, m + 1):
    if a in jobs:
      for b in jobs[a]:
        heappush(candidates, -b)
    else:
      if len(candidates) == 0:
        continue
    result += -heappop(candidates)
  print(result)
main()

Submission status: Runtime Error

Solution code:
import bisect
n, m = map(int, input().split())
work = [list(map(int, input().split())) for i in range(n)]
dic = {}
for w in work:
    a, b = w[0], w[1]
    if a not in dic.keys():
        dic[a]=[b]
    else:
        index=bisect.bisect_right(dic[a], b)
        dic[a].insert(index, b)
dic_=sorted(dic.items(), key=lambda x:x[0])
res = 0
while m > 0:
    print(dic_)
    flag=True
    for i in range(len(dic_)):
        if dic_[i][0] >= m:
            flag=False
            if i==0:
                break
            res+=dic_[i][1].pop(-1)
    if flag:
        dic_[-1][1].pop(-1)
    m-=1

Submission status: Runtime Error

Solution code:
from itertools import bisect
n, m = map(int, input().split())
work = [map(int, input().split()) for i in range(n)]
dic = {}
for w in work:
  a, b = w[0], w[1]
  if a not in dic.keys():
    dic[a]=[b]
  else:
    index=bisect.bisect_right(dic[a], b)
    dic[a].insert(index, b)
res = 0
while m > 0:
  index=bisect.bisect_left(dic.keys(), m)
  res+=dic[index].pos(len(dic[index])-1)
print(res)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop

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

# works[i] : M-i日に報酬が得られるリスト
works = [[] for _ in range(10**5)]

for _ in range(N):
    A, B = map(int,input().split())
    # 報酬が得られる日付に応じて格納
    works[A].append(B)

hq = []
ans = 0

for i in range(1,M+1):
    # M-i日から降順に仕事の候補リストを作る
    for w in works[i]:
        # 大きいものから選びたいのでマイナスをかける
        heappush(hq, -w)
    # M-i日の時点で報酬が最大の仕事を選ぶ
    if hq:
        ans += -heappop(hq)

print(ans)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop

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

# works[i] : M-i日に報酬が得られるリスト
works = [[] for _ in range(10**4)]

for _ in range(N):
    A, B = map(int,input().split())
    A -= 1
    # 報酬が得られる日付に応じて格納
    works[A].append(B)

hq = []
ans = 0

for i in range(M):
    # M-i日から降順に仕事の候補リストを作る
    for w in works[i]:
        # 大きいものから選びたいのでマイナスをかける
        heappush(hq, -w)
    # M-i日の時点で報酬が最大の仕事を選ぶ
    if hq:
        ans += -heappop(hq)

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
works = [ tuple(map(int, input().split())) for _ in range(n) ]

candos = []
earned = 0
for i in range(1, m+1):  
  others = []
  for w in works:
    if w[0] <= i:
      candos.append(w)
    else:
      others.append(w)
  
  if len(candos)>0:
    t = max(candos, key=lambda x: x[1])
  earned += t[1]
  candos.remove(t)
  works = others

print(earned)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
works = [ tuple(map(int, input().split())) for _ in range(n) ]

candos = []
earned = 0
for i in range(1, m+1):  
  others = []
  for w in works:
    if w[0] <= i:
      candos.append(w)
    else:
      others.append(w)
  
  t = max(candos, key=lambda x: x[1])
  earned += t[1]
  candos.remove(t)
  works = others

print(earned)

Submission status: Runtime Error

Solution code:
N = int(input())
l = [input() for i in range(N)]
mydict = {}
count = 0
value = 1
for i in range(N):
    l[i] = ''.join(sorted(l[i]))
    if l[i] in mydict.keys():
        count += 1
    else:
        mydict[l[i]] = value
        value += 1
print(count)
print(mydict)

Submission status: Runtime Error

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

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

count = 0

li2 = []

for i in range(n):
    x = li[i][0]-1
    if x < m and len(li2) == 0:
        li2.append([x,x])
        count += li[i][1]
        continue
    elif x >= m:
        continue

    if li2[0][0] > x:
        li2[0:0] = [[x,x]]
        count += li[i][1]
        if li2[0][1]+1 == li2[1][0]:
                li2[0][1] = li2[1][0]
                del li2[1:2]
        continue
    elif li2[len(li2)-1][1] < x:
        li2[len(li2):len(li2)] = [[x,x]]
        count += li[i][1]
        if li2[len(li2)-1][1]+1 == li2[len(li2)][0]:
                li2[len(li2)-1][1] = li2[len(li2)][0]
                li2.pop()
        continue

    a = 0
    b = len(li2)-1
    while a!=b:
        c = int((a+b)/2)
        if li2[c][1] >= x:
            b = c
        else:
            a = c+1
    if li2[a][0] <= x and li2[a][1]==m-1:
        continue
    elif li2[a][0] <= x:
        li2[a][1] += 1
        count += li[i][1]
        if a != len(li2)-1:
            if li2[a][1]+1 == li2[a+1][0]:
                li2[a][1] = li2[a+1][0]
                del li2[a+1:a+2]
    else:
        li2[a:a] = [[x,x]]
        count += li[i][1]
        if li2[a-1][1]+1 == li2[a][0] and li2[a][1]+1 == li2[a+1][0]:
            li2[a-1][1] = li2[a+1][1]
            del li2[a:a+1]
            del li2[a:a+1]
        elif li2[a-1][1]+1 == li2[a][0]:
            del li2[a:a+1]
        elif li2[a][1]+1 == li2[a+1][0]:
            del li2[a+1:a+2]


print(count)

Submission status: Runtime Error

Solution code:
N= int(input())
s = []

for _ in range(N):
    s.append(input())

for i in range(N):
    s[i] = [*s[i]]
    s[i] = sorted(s[i])

counter = 0
for i in range(N):
    for j in range((i+1), N):
        if s[i] == s[j]:
            counter += 1

print(counter)

Submission status: Runtime Error

Solution code:
import heapq
job = list()
salary = list()
n,m = map(int,input().split())

for i in range(n):
    a,b = map(int,input().split())
    job.append(a,b)
    
job.sort(reverse = True)

for x in job:
    s,t = x
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    p = max(list1, key = lambda x:x[1])
    income += p[1]
    list1.pop(list1.index(p))
      
print(income)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
# A = [] # 日後
# B = [] # 報酬
X = []
for i in range(N):
  a, b = map(int, input().split())
  d = {0:a, 1: b, 2: False}
  X.append(d)

c = 0
for i in range(M):
  max_b = 0
  find = None
  id = None
  for w in X:
    if (w[1] > max_b and w[2] == False and (i + w[0] <= M + 1)):
      max_b = w[1]
      find = w
    id= id + 1

  if find != None:
    c = c + find[1]
    find[2] = True
    X.remove(id)

print(c)

Submission status: Runtime Error

Solution code:
n, m = [ int(v) for v in input().split() ]
work_list = [ [] for i in range(m)]
collect_list = [] 
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    if m-a >= 0:
        work_list[m-a].append(-b)


for i in range(m):
    for j in range(min(i+1,len(work_list[i]))):
        heapq.heappush(collect_list,heapq.heappop(work_list[i]))


ans = 0
for i in range(min(m,len(collect_list))):
    ans -= heapq.heappop(collect_list)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A = [] # 日後
B = [] # 報酬
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

c = 0
for i in range(M):
  if A[i] + i < M:
    c = c + B[i]
  
# 文字列の入力
# s = input()
# 出力
print(c)

Submission status: Runtime Error

Solution code:
import heapq
N,M=map(int,input().split())
l=[[] for i in range(M+1)]
#print(l)
for i in range(N):
  a,b=map(int,input().split())
  #print(a,b)
  #print(l[a])
  l[a].append(b)
#print(l)
ans=0
que=[]
for i in range(1,M+1):
  for j in l[i]:
    heapq.heappush(que,-j)
  if len(que)>0:
    #print(i,que)
    ans-=heapq.heappop(que)
    
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

import numpy as np

N, M = mi()
X = 2 * pow(10, 4)
job_matrix = np.zeros((X, X), dtype=int)

for _ in range(N):
  A, B = mi()
  job_matrix[A-1][np.where(job_matrix[A-1] == 0)[0][0]] = B

count = 0
for i in range(1, M+1):
    index = np.unravel_index(np.argmax(job_matrix[:i]), job_matrix[:i].shape)
    count += job_matrix[index]
    job_matrix[index] = 0

print(count)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

import numpy as np

N, M = mi()
X = pow(10, 5)
job_matrix = np.zeros((X, X), dtype=int)

for _ in range(N):
  A, B = mi()
  job_matrix[A-1][np.where(job_matrix[A-1] == 0)[0][0]] = B

count = 0
for i in range(1, M+1):
    index = np.unravel_index(np.argmax(job_matrix[:i]), job_matrix[:i].shape)
    count += job_matrix[index]
    job_matrix[index] = 0

print(count)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

import numpy as np

N, M = mi()
job_matrix = np.zeros((N, N), dtype=int)

for _ in range(N):
  A, B = mi()
  job_matrix[A-1][np.where(job_matrix[A-1] == 0)[0][0]] = B

count = 0
for i in range(1, M+1):
    index = np.unravel_index(np.argmax(job_matrix[:i]), job_matrix[:i].shape)
    count += job_matrix[index]
    job_matrix[index] = 0

print(count)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())

import numpy as np

N, M = mi()
job_matrix = np.zeros((N, N), dtype=int)

for _ in range(N):
  A, B = mi()
  job_matrix[A][np.where(job_matrix[A] == 0)[0][0]] = B

count = 0
for i in range(1, M+1):
    index = np.unravel_index(np.argmax(job_matrix[:i+1]), job_matrix[:i+1].shape)
    count += job_matrix[index]
    job_matrix[index] = 0

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())

X = []

i = 0
while i < N:
    X.append(list(map(int, input().split())))
    i += 1

X = np.asarray(X)

X_ind = np.lexsort((X[:,0], -X[:,1]), axis=0)[::-1]
X = X[X_ind]
# print(X)
least = M - 1
p = 0
while least >= 0:
    last, X = X[-1], X[:-1]
    # print(last, X)
    if (M - least) >= last[0]:
        p += last[1]
        least -= 1

print(p)

Submission status: Runtime Error

Solution code:
# coding: utf-8

if __name__ == "__main__":
    n, m = map(int, input().split(" "))
    ab = {}
    for i in range(n):
        a, b = map(int, input().split(" "))
        try:
            ab[a].append(b)
        except:
            ab[a] =[b]

    ans = 0
    for today in range(m):
        days = m - today
        l = {}
        for i in range(days+1)[::-1]:
            try:
                l[i] = max(ab[i])
            except:
                pass
        max_item = max(l.items(), key=lambda x: x[1])
        ans += max_item[1]
        ab[max_item[0]].remove(max_item[1])
    print(ans)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

n, m = list(map(int, input().split()))[0:]

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


@lru_cache(maxsize=None)
def reward(s):
    return sum(b[i] for i in s)


total = set(range(n))


@lru_cache(maxsize=None)
def renum(mm, selected):
    usable = total - selected
    max_reward = reward(selected)
    result = selected
    for i in usable:
        if mm < a[i]:
            continue
        s = renum(mm - 1, selected | {i})
        r = reward(s)
        if max_reward < r:
            max_reward = r
            result = s
    return result


if __name__ == '__main__':
    selected = renum(m, frozenset())
    print(reward(selected))

Submission status: Runtime Error

Solution code:
from functools import lru_cache

n, m = list(map(int, input().split()))[0:]

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


def reward(s):
    return sum(b[i] for i in s)


@lru_cache(maxsize=1000)
def renum(mm, selected):
    usable = set(range(n)) - selected
    m = reward(selected)
    new_selected = selected
    for i in usable:
        if mm < a[i]:
            continue
        s = renum(mm - 1, selected | {i})
        r = reward(s)
        if m < r:
            m = r
            new_selected = s
    return new_selected


if __name__ == '__main__':
    selected = renum(m, frozenset())
    print(reward(selected))

Submission status: Runtime Error

Solution code:
import heapq

N, M = map(int, input().split())
jobs = []
for _ in rangek(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs.append([day, value])

ans = 0
hq = []
for day in range(1, M+1):
    for job in list(jobs):
        if day == job[0]:
            heapq.heappush(hq, - job[1])
            jobs.remove(job)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Submission status: Runtime Error

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

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

done = [0 for _ in range(n)]
gain = 0

for i in reversed(range(1,m+1)): #i:残り日数
    for j in range(n): #j:候補から優先度順で探索
        if lst[j][0] <= i and done[j] == 0: #必要な日数>残り日数 かつ undone
            gain += lst[j][1]
            done[j] = 1　#undone:0,done:1として分類
            break #働いたら次の日へ

print(gain)

Submission status: Runtime Error

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

def schedule(reward, day, jobs):
    if day > M or not jobs:
        return reward
    else:
        results = []
        for job in jobs:
            if day + job[0] - 1 > M:
                jobs.remove(job)

        if not jobs:
            return reward

        for job in jobs:
            copied_jobs = list(jobs)
            copied_jobs.remove(job)
            result = schedule(reward + job[1], day + 1, copied_jobs)
            results.append(result)
        return max(results)

print(schedule(0, 1, jobs))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
sum = 0
for i in range(n):
  c = list(map(int,input().split()))
  if m >= c[0]:
    a.append(c[1])
    b.append(c[0])
if not b:
  print(0)
  exit()

c = zip(a,b)
d = sorted(c,reverse = True)
#print(d)
  
for i in range(m):
  for j in range(n):
    if d[0][1] <=m-i:
      sum += d[0][0]
      #print(d)
      d.pop(0)
      
      break
    else:
      d.pop(0)
      
print(sum)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
d = 100
sum = 0
for i in range(n):
  c = list(map(int,input().split()))
  if m >= c[0]:
    a.append(c[0])
    b.append(c[1])
if not b:
  print(0)
  exit()

c = zip(b,a)
d = sorted(c,reverse = True)
#print(d)
  
for i in range(m):
  for j in range(n):
    if d[0][1] <=m-i:
      sum += d[0][0]
      d.pop(0)
      break
    else:
      d.pop(0)
      
print(sum)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
d = 100
sum = 0
for i in range(n):
  c = list(map(int,input().split()))
  if m >= c[0]:
    a.append(c[0])
    b.append(c[1])
if not b:
  print(0)
  exit()

c = zip(b,a)
d = sorted(c,reverse = True)
print(d)
  
for i in range(m):
  for j in range(n):
    if d[0][1] <=m-i:
      sum += d[0][0]
      d.pop(0)
      break
    else:
      d.pop(0)
      
print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np

temp=list(map(int, input().split()))
N=temp[0]
M=temp[1]

AB=np.array([list(map(int, input().split())) for i in range(N)])
AB=np.c_[AB, np.zeros((AB.shape[0], 1))]

money=0
for i in range(1, M+1):
  temp=AB[AB[:, 0]<=i]
  temp=temp[temp[:, 2]==0]
  temp=temp[np.argmax(temp[:, 1])]
  money+=temp[1]
  
  x=0
  while x<AB.shape[0]:
    if sum(AB[x, :]==temp)==3:
      AB[x, 2]=1
      break
    x+=1
    
print(int(money))