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 bisect
from collections import deque

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""

#######################################
n,m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)

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

done_list =[]
money = 0
for i in range(m):
  best_idx = np.argmax(b[a<=(i+1)])
  money += b[best_idx]
  b[best_idx] = 0

print(int(money))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
import bisect
N,M = map(int,input().split(' '))
AB = [[] for i in [0]*(M+1)]
for i in [0]*N:
	a,b = map(int,input().split(' '))
	if a <= M:
		AB[a].append(b)

ans = 0
cand = deque([])
for i in range(1,M+1):
	for b in AB[i]:
		bisect.insort_right(cand,b)
	if cand:
		ans += cand.pop()
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
l.append([0,0])
ans=0
k=[]
j=0
for i in range(1,m+1):
  while j<=n and l[j][0]<=i:
    k.append(l[j][1])
    j+=1
  ans+=max(k)
  k.remove(max(k))
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in [0]*n]
l.sort(key=lambda x:x[1])
ans = 0
tmpl = []
d = 1
flag = True

while len(l)>=1 and d<=m:
  while l[0][0] <= d and len(l)>=1:
    tmpl.append(l[0][i])
    del l[0]
  maxindex = tmpl.index(max(tmpl))
  ans += tmpl[maxindex]
  del tmpl[maxindex]
print(tmp)

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]))
day = 0
cnt = 0
a, b = AB[0]
for i in range(M):
  if a > M:
    break
  if day + pre > M:
    break
  cnt += b
  day += 1
  AB.remove([a, b])
  if not AB:
    break
  a, b = max(AB, key = lambda x: (-x[0], x[1]))
print(cnt)

Submission status: Runtime Error

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

work = []
for i in range(N):
    A,B = map(int,input().split())
    work.append([A,B])

work.append([10**8,0])
work = np.array(work)
sorted_work = work[np.argsort(work[:,0])]

l = []
ans = 0
index = 0
for i in range(1,M+1):
    while sorted_work[index,0] <= i:
        l.append(sorted_work[index,1])
        index += 1
        
    ans += max(l)
    l.remove(max(l))

print(ans)

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]))
day = 0
cnt = 0
a, b = AB[0]
for i in range(M):
  if a > M:
    break
  if day + pre > M:
    break
  cnt += b
  day += 1
  AB.remove([a, b])
  a, b = max(AB, key = lambda x: (-x[0], x[1]))
print(cnt)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop

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

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        if len(q) < a + 1 :
            heappush(q, b)
        else :
            heappop(q)
            heappush(q, b)
            
print(sum(q))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int n, m;
multiset<int> available;
vector<int> job[N];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    job[a].push_back(b);
  }

  int ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int x : job[m - i])
      available.insert(x);
    if (!available.empty()) {
      ans += *prev(available.end());
      available.erase(prev(available.end()));
    }
  }
  printf("%d\n", ans);
  return 0;
}

Submission status: Runtime Error

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

a_list = []
ab_list = []
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    ab_list.append((a, b))
    a_list.append(a)

if len(a_list) == 0:
    print(0)
else:
    ab_list = sorted(ab_list, key=lambda x: -x[1])
    sorted(a_list)
    c = 0
    for i in range(1, m+1):
        if a_list[0] > i:
            continue
        for j, (a, b) in enumerate(ab_list):
            if a <= i:
                c += b
                ab_list.pop(j)
                a_list.pop(0)
                break

    print(c)

Submission status: Runtime Error

Solution code:
from Lib import heapq
Heappop=heapq.heappop
Heappush=heapq.heappush
N,M=map(int,input().split())
L=[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
q=[0]*10**5
ans=0
d=1
memo=0
while d<=M:
    while memo<=N-1:
        a,b=L[memo]
        if d<a:
            break
        else:
            Heappush(q,b)
            memo+=1
    ans-=Heappop(q)
    d+=1
print(ans)

Submission status: Runtime Error

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

a_list = []
ab_list = []
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    ab_list.append((a, b))
    a_list.append(a)

ab_list = sorted(ab_list, key=lambda x: -x[1])
a_list = sorted(a_list)

c = 0
for i in range(1, m+1):
    if a_list[0] > i:
        continue
    for j, (a, b) in enumerate(ab_list):
        if a <= i:
            c += b
            ab_list.pop(j)
            a_list.pop(0)
            break

print(c)

Submission status: Runtime Error

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

a_list = []
ab_list = []
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
	continue
    ab_list.append((a, b))
    a_list.append(a)

ab_list = sorted(ab_list, key=lambda x: -x[1])
a_list = sorted(a_list)

c = 0
for i in range(1, m+1):
    if a_list[0] > i:
        continue

    for j, (a, b) in enumerate(ab_list):
        if a <= i:
            c += b
            ab_list.pop(j)
            a_list.pop(0)
            break

print(c)

Submission status: Runtime Error

Solution code:
import heapq
from collections import deque

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

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

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappop(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
c = {}
for i in range(n):
  a,b = map(int, input().split())
  if c.get(b, -1) == -1:
    c[b] = a
  else:
    c[b] = min(c]b], a)
k = c.keys()
k.sorted()
k.reverse()
ans = 0
for i in k:
  if m - i >= 0:
    ans += c[i] * int(m / i)
    m = m - i
print(ans)

Submission status: Runtime Error

Solution code:
n, m = [int(x) for x in input().split()]
xs   = []

for i in range(0, n):
	xs.append(tuple(int(x) for x in input().split()))

xs.sort(key = lambda t: t[1], reverse = True)
xs.sort(key = lambda t: t[0], reverse = True)

def calc(i, r, c):
	if i == n or r == 0:
		return c
	elif r < xs[i][0]:
		return calc(i + 1, r, c)
	else:
		return max(calc(i + 1, r, c), calc(i + 1, r - 1, c + xs[i][1]))
	
print(calc(0, m, 0))

Submission status: Runtime Error

Solution code:
n,day=map(int,input().split())
daylist=[0 for i in range(n)]
money=[0 for i in range(n)]
hima=[0 for i in range(day)]
su=0
for i in range(n):
  d,m=map(int,input().split())
  daylist[i]=d
  money[i]=m
for j in range(n):
  a=hima.count(1)
  if(a==day):
    break
  which=money.index(max(money))
  howlong=daylist[which]
  when=day-howlong
  while((hima[when]==1)and(when>=0)):
    when-=1
  if(when!=-1):
    hima[when]=1
    su+=max(money)
    money[which]=0
print(su)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

summation = [[] for i in range(10 ** 5 + 10 ** 4 + 1)]
for i in range(N):
    a, b = map(int, input().split())
    summation[a + b].append((a, b))

lst = []
for i in range(10 ** 5 + 10 ** 4):
    summation[i].sort()
    if summation[i] != []:
        for v in summation[i]:
            lst.append(v)

ans = 0
for i in range(M):
    remain = M - i
    if lst != []:
        while True:
            a, b = lst.pop()
            if a > remain:
                continue
            else:
                ans += b
                break
    else:
        break

print(ans)

Submission status: Runtime Error

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


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

day = {}
for i in range(1,m+1):
    day[i] = m - i + 1

h = 0
while m > 0:
    mh = max(d)
    if d[mh] == []:
        del d[mh]
    else:
        md = max(d[mh])
        if day[md] > 0:
            day[md] -= 1
            m -= 1
            h += mh
            d[mh].remove(md)
        else:
            d[mh].remove(md)


print(h)

Submission status: Runtime Error

Solution code:

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
import heapq
AB.sort()
heap = []
heapq.heapify(heap)
ans = 0
i = 0
day = 1
while i < N and day <= M:
    while AB[i][0] <= day:
        heapq.heappush(heap,-AB[i][1])
        i += 1
    day += 1
    if not(heap):continue
    ans -= heapq.heappop(heap)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from bisect import insort

n, m = map(int, input().split())
d = [[] for _ in range(m+1)]
for i in range(n):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    d[a].append(b)

res = 0
resList = []
for i in range(1, m+1):
    sub = d[i]
    if len(sub) > 0:
        for j in range(len(sub)):
            insort(resList, sub[j])
    if len(resList) > 0:
        res += resList.pop()

print(res)

Submission status: Runtime Error

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

# print(N, M)
# print(A, B)

count = 0

hosyu = list(set(B))
hosyu.sort()
hosyu.reverse()
day_min = {}

for i in range(len(B)):
	if B[i] not in day_min.keys():
		day_min[B[i]] = A[i]

	else:
		if A[i] < day_min[i]:
			day_min[B[i]] = A[i]

# print(hosyu, day_min)

days_left = M

for h in hosyu:
	if day_min[h] <= days_left:
		count += h * (days_left - day_min[h] + 1)
		days_left = day_min[h] - 1

	if days_left < 1:
		break

print(count)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(N)]
L = sorted(L,key = lambda x: (-x[1],-x[0]))

ans = 0
c = 0
D = [1 for k in range(M+2)]
D[M+1] = 0
for k in range(N):
    if D[L[k][0]] == 1:
        D[M-c] = 0
        c += 1
        ans += L[k][1]
    if c == M:
        break
print(ans)

Submission status: Runtime Error

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

w = [[] for _ in range(10001)]

for i in range(n):
  a, b = map(int, input().split())
  if a == 0:
    continue
  w[a-1].append(b)

money = 0
l = []
for i in range(m):
  l += w[i]
  if len(l) == 0:
    continue

  x = max(l)
  l.remove(x)
  money += x

print(money)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
print(grid)
grid.sort()
AA = [i[0] for i in grid]
BB = [i[1] for i in grid]
var = 0
for k in range(M-1):
  i = k+1
  BBB = [x for x in BB if AA[x] >= i]
  if len(BBB) > 0:
    var = var + max(BB)
    del BB[BB.index(max(BB))]
    del AA[BB.index(max(BB))]
print(var)

Submission status: Runtime Error

Solution code:
def main():
    N, M = [int(n) for n in input().split()]
    B = [(0, 0)]*N
    for i in range(N):
        a, b = [int(n) for n in input().split()]
        B[i] = (a, b)
    B = sorted(B, key= lambda x: -x[1])

    result = [0] * M

    for i in range(N):
        a, b = B[i][0], B[i][1]
        while True:
            if result[M-a] == 0:
                result[M-a] = b
                break
            else:
                a += 1
                if a > N:
                    break
    print(sum(result))
main()

Submission status: Runtime Error

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

ba = [ [] for _ in range(1001)]

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

for x in ba:
  x.sort(reverse=True)

cnt = m
ans = 0

for i in range(1000, -1, -1):
  if ba != []:
    for e in ba[i]:
      if cnt != 0 and e <= cnt:
        ans += i
        cnt -= 1
  if cnt == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
import heapq

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

# delay, reword
jobs = [list(map(int, input().split())) for i in range(n)]
jobs_days = [[] for i in range(m + 10)]
for job in jobs:
    jobs_days[job[0]].append(-job[1])

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

for i in range(m):
    for j in jobs_days[i + 1]:
        heapq.heappush(h, j)
    if(len(h)>0):
        reward += heapq.heappop(h)

print(-reward)

Submission status: Runtime Error

Solution code:

N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
import heapq
AB.sort()
heap = []
heapq.heapify(heap)
ans = 0
i = 0
day = 1
while i < N and day <= M:
    while AB[i][0] <= day:
        heapq.heappush(heap,-AB[i][1])
        i += 1
    
    ans -= heapq.heappush(heap)

print(ans)

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

N, M = map(int, input().strip().split(' '))
ABs = [tuple(map(int, input().strip.split(' '))) for _ in range(N)]
ABs.sort(key=lambda x : x[1], reverse=True)
day=0
r = 0
for a, b in ABs:
    if day+a <=M:
        r += b
        day+=a
print(r)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
print(grid)
grid.sort()
AA = [i[0] for i in grid]
BB = [i[1] for i in grid]
var = 0
for k in range M-1:
  i = k+1
  BBB = [x for x in BB if AA[x] >= i]
  if len(BBB) > 0:
    var = var + max(BBB)
    del BB[BB.index(max(BBB))]
    del AA[BB.index(max(BBB))]
print(var)

Submission status: Runtime Error

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

jobs = [(a, -b) for a, b in ab]
jobs.sort()

ans = 0
job_index = 0
for i in range(m):
    while job_index < len(jobs):
        if jobs[job_index] + i < m:
            ans -= jobs[job_index][1]
        else:
            job_index += 1
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a = [list(map(int,input().split())) for i in range(N)]
a.sort()
b = 0
print(a)
while M > 0:
    for j in range(len(a)):
        if 
    a.pop()
    M -= 1 
print(b)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(b)
        else:
            work[a] = [b]

    cand = []
    prev_max = 0
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            y = max(work[i])
            if(prev_max<y):
                x = y
            else:
                x = prev_max
            cand += work[i]
        if(len(cand)==0):
            continue
        cand.remove(x)
        cnt += x
        prev_max = max(cand)

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(n)]
#i件目までのアルバイトでj日目までに得られる最大値
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n):
    a, b = ab[i]#a日後に報酬bを得られる
    num = m+1-a
    for j in range(num):
        if j-1 >= 0:
            dp[i+1][j] = max(dp[i][j], dp[i][j-1]+b)
        else:
            dp[i+1][j] = max(dp[i][j], b)
    for j in range(a):
        dp[i+1][j+num] = dp[i+1][j+num-1]

print(max(dp[-1]))

Submission status: Runtime Error

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

l = M
result = 0
while l > 0:
    index_lis = [i for i, v in enumerate(X) if v[1] == max(X, key=lambda xx: xx[1])[1]]
    if len(index_lis) >= 2:
        a = max(X, key=lambda xx: xx[index_lis][0])
    else:
        a = X[index_lis[0]]
    if a[0] > l:
        X.remove(a)
    elif a[0] <= l:
        result += a[1]
        l -= 1
        X.remove(a)
print(result)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

class BIT:
    def __init__(self, N):
        self.N = N
        self.bit = [0 for _ in range(N+1)]
    def add(self, x, a):
        while x <= self.N:
            self.bit[x] += a
            x += x & -x
    def sum(self, x):
        ret = 0
        while x != 0:
            ret += self.bit[x]
            x -= x & -x
        return ret

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key = lambda x: -x[0])
ab.sort(key = lambda x: -x[1])
f = [0] * M
cnt, ans = 0, 0
bit = BIT(M+1)
for a, b in ab:
    if M-a >= 0 and bit.sum(M-a+1) - bit.sum(0, 1) <= M-a:
        ans += b
        cnt += 1
        if cnt == M:
            break
        bit.add(M-a+1, 1)
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
se = sorted(e,key=lambda l:l[1],reverse=True)
sse = sorted(se,key=lambda l:l[0])
ans = 0
for day in range(m):
  max = 0
  for i in range(len(sse)):
    if sse[i][1]>sse[max][1]:
      max = i
    if sse[i][0] > day+1:
      break
  ans+=sse[max][1]
  del sse[max]
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())

A = [0]*N
B = [0]*N

for n in range(N):
  B[n],A[n] = map(int,input().split())
  
CA = CA
CB = CB
CN = N

#F = [True]*N
sr = 0
for m in range(M):
  cr = 0
#  ci = -1
  CN = 0
  for n in range(CN):
    if CB[n] <= m+1  and cr<CA[n]:
      #ci = n
      cr = A[n]
    else:
      CA[CN] = A[n]
      CB[CN] = B[n]
      CN += 1
    sr += cr
#  if ci!=-1:
#    sr += cr
#    F[ci] = False
print(sr)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
work_list = [list(map(int, input().split())) for i in range(n)]
work_list.sort()
ans = 0
max_f = []
p = 0
for i in range(1, m+1):
  while p<len(work_list) and work_list[p][0]<=i:
    max_f.append(max(max_f[-1], work_list[p][1])
    p += 1
  if max_f:
    ans += max_f[-1]
    _ = max_f.pop(-1)
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
dic = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a > M:
        pass
    else:
        if a in dic.keys():
            dic[a].append(b)
        else:
            dic[a] = [b]
#print(dic)
lis = [[]] * M
for p in dic.keys():
    lis[p-1] = dic[p]
#print('lis:',lis)
g = 0
for i in range(M):
    if lis[i] == []:
        pass
    else:
        #print('sublis:',lis[i])
        mx = max(lis[i])
        g += mx
        lis[i].remove(mx)
        if i+1 < M:
            if len(lis[i])>0:
                lis[i+1].extend()
    #print(lis)
print(g)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    ab = defaultdict(list)
    for a, b in AB:
        ab[a].append(b * -1)

    ans = 0
    flag = 1
    for i in range(1, M + 1):
        if flag:
            reward = heapify(ab[1])
            flag = 0
        if ab[i]:
            for n in ab[i]:
                heappush(reward, n * -1)
            ans += heappop(reward) * -1
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None
N, M =LI()
AB = []
for i in range(N):
    AB.append(LI())
AB.sort(key=lambda x: x[0])
perr(AB)
#  AB_dict = {}
#  for ab in AB:
#      if ab[0] not in AB_dict.keys():
#          AB_dict[ab[0]] = [ab[1]]
#      else:
#          AB_dict[ab[0]].append(ab[1])
#  for k in AB_dict.keys():
#      AB_dict[k].sort()
#  perr(AB_dict)

tmp = []
day = 1
ans = 0
for ab in AB:
    if ab[0] > day:
        tmp.sort()
        ans += tmp.pop()
        day += 1
        continue
    else:
        tmp.append(ab[1])
print(ans)
#  ans = 0
#  tmp = []
#  crr = 0
#  for i in range(1, M+1):
#      if crr < N:
#          if AB[crr][0] == i:
#              while True:
#                  if crr == N:
#                      break
#                  if AB[crr][0] != i:
#                      break
#                  tmp.append(AB[crr][1])
#                  crr += 1

#      perr('tmp')
#      perr(tmp)
#      if len(tmp) == 0:
#          continue

#      max_v = max(tmp)
#      ans += max_v
#      tmp.remove(max_v)
#      #  tmp.sort()
#      #  ans+=tmp.pop()

#  """
#  貪欲か？
#  日が長くて報酬の高いものから選んでいく
#  そうすると
#  10 1
#  9 10
#  みたいなときに10 1のほうから選んでしまうからだめ
#  残り日数を意識
#  残ってる中で最も報酬の高いものから？
#  2 10
#  1 11
#  のパターンで、先に1をやってしまうためだめ
#  2 10
#  1 11
#  1 15
#  のパターンで、1 1をやるのが正解
#  """

#  #  ans = 0
#  #  tmp = []
#  #  for i in range(1, M+1):
#  #      # 残りi日
#  #      if i in AB_dict.keys():
#  #          tmp += AB_dict[i]
#  #      perr('tmp')
#  #      perr(tmp)
#  #      if len(tmp) == 0:
#  #          continue
#  #      tmp.sort()
#  #      #  max_v = max(tmp)
#  #      #  ans += max_v
#  #      ans += tmp.pop()
#  print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
AB, mx = [], [0] * (10 ** 1 + 1)
for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))
    mx[A] = max(mx[A], B)

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

ans, idx, lAB = 0, 0, len(AB)
for i in range(1, M + 1):
    if AB[idx][0] <= i:
        while AB[idx][1] < mx[AB[idx][0] + 1]:
            tmp = AB[idx][0] + 1
            while not AB[idx][0] == tmp:
                idx += 1
        ans, idx = ans + AB[idx][1], idx + 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = list(map(int, input().split()))
info = np.asarray([list(map(int, input().split())) for i in range(N)])
#info = sorted(info, key=lambda x:(-x[1], x[0]))
#print(info[:M])

result = 0
for i in range(M, -1, -1):
  max_index = np.argmax(info[info.T[0]<=i].T[1])
  result += info[max_index][1]
  info[max_index][0] = M+1
print(result)

Submission status: Runtime Error

Solution code:
def calc(N, M, AB):
    day2pay = {
        a: sorted(
            [ab[1] for ab in AB if ab[0] == a],
            key=lambda b: -b)
        for a in range(1, M + 1)
    }
    for a in range(1, M + 1):
        if (not (day2pay[a])):
            day2pay.pop(a)
    result = 0
    for m in range(M):
        if (not (day2pay)):
            break
        i = max(day2pay.keys())
        dp = day2pay.pop(i) if (i == M - m or not (day2pay[i])) else day2pay[i]
        if (day2pay):
            j = max(day2pay.keys())
            if (len(day2pay[j]) > 1 and day2pay[j][1] > dp[0]):
                result += day2pay[j].pop(0)
            else:
                result += dp.pop(0)
        else:
            result += dp.pop(0)
    return result


(N, M) = tuple([int(s) for s in input().split(' ')])
AB = [tuple([int(s) for s in input().split(' ')]) for _ in range(N)]
print(calc(N, M, AB))

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[1])
day = 0
pre = 0
cnt = 0
for a, b in AB:
  if a > M:
    break
  if a == pre:
    AB.append(AB.pop([a, b]))
    continue
  if day + pre > M:
    break
  cnt += b
  day += 1
  pre = a
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
red = []
blue = []
for _ in range(n):
    a, b = map(int, input().split())
    red.append([a, b])
for i in range(n):
    c, d = [i, 0]
    blue.append([c, d])
blue.sort()
red.sort(key=lambda x: x[1], reverse=True)
ans = 0
for b in blue:
    for i, r in enumerate(red):
        if (r[0] < b[0]) & (r[1] < b[1]):
            ans += 1
            red.pop(i)
            break
print(ans)

Submission status: Runtime Error

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

works = []
awards = []

for i in range(n):
	work, award = map(int,input().split())
	works.append(work)
	awards.append(award)

res = zip(works, awards)
Z = sorted(res, key=lambda x:x[0])

ans = 0
for j in range(m-1):
	abc = []
	if Z[j][0] == j+1:
		abc.append(Z[j][1])
		ans += max(abc)

print(ans)

Submission status: Runtime Error

Solution code:

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

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

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

scadule = [0]*M

m=len(BA)
i=0
while i < m:
    work = BA[i]
    i+=1
    try:
        day = scadule[work[0]-1:].index(0)
        scadule[day+work[0]-1] = work[1]
    except:
        BA = BA[:i+1]+[x for x in BA[i+1:] if x[0] >= work[0]]
        m=len(BA)
        continue

ans=sum(scadule)

print(str(ans))

Submission status: Runtime Error

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

works = []
awards = []

for i in range(n):
	work, award = map(int,input().split())
	works.append(work)
	awards.append(award)

res = zip(works, awards)
Z = sorted(res, key=lambda x:x[0])

ans = 0
for j in range(m-1):
	abc = []
	if Z[j][0] == j+1:
	abc.append(Z[j][1])
	ans += max(abc)

print(ans)