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: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
ab = []
for i in range(N):
    A[i], B[i] = map(int, input().split())
    ab.append([A[i], B[i]])

ab.sort()
i = N
ans = 0
nums = []
while 1 <= i:
    if M <= 0:
        nums.sort()
        nums.reverse()
        if nums[-1] < ab[i-1][1]:
            nums.pop()
            nums.append(ab[i-1][1])
    if M >= 1:
        if ab[i-1][0] <= M:
            nums.append(ab[i-1][1])
            if i <= N - 1 and ab[i-1][0] < ab[i-1][1]:
                M -= 1
        else:
            while ab[i-1][0] > M:
                i -= 1
                if i - 1 < 0:
                    break
            if ab[i-1][0] <= M:
                nums.append(ab[i-1][1])
                if i <= N - 1 and ab[i-1][0] < ab[i-1][1]:
                    M -= 1
    i -= 1

if len(nums) == 0:
    nums.append(0)

print(sum(nums))

Submission status: Wrong Answer

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

ab = sorted(ab,key=lambda x : x[0],reverse=True)
ab = sorted(ab,key=lambda x : x[1],reverse=True)
ans = 0
day = 0
for i in range(N):
    if day + ab[i][0] > M:
        continue
    ans += ab[i][1]
    day += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def calc_total_reward(m, data):
    # day_to_rewardsをset
    day_to_rewards = {}
    for row in data:
        day = row['day']
        reward = row['reward']
        if day not in day_to_rewards:
            day_to_rewards[day] = []
        day_to_rewards[day].append(row['reward'])

    for day, reward_list in day_to_rewards.items():
        day_to_rewards[day] = sorted(reward_list)

    total_reward = 0
    reward_list = []
    
    # print(day_to_rewards)
    for day in range(1, m+1):
        # print(day)
        if day in day_to_rewards:
            print('add')
            reward_list.extend(day_to_rewards[day])
        sorted(reward_list)
        # print(reward_list)
        if len(reward_list) > 0:
            total_reward += reward_list.pop()
    return total_reward

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

data = []
for i in range(n):
    day, reward = map(int, input().split())
    data.append({
        'day': day,
        'reward': reward
    })

total_reward = calc_total_reward(m, data)    
print(total_reward)

Submission status: Wrong Answer

Solution code:
def calc_total_reward(m, data):
    # day_to_rewardsをset
    day_to_rewards = {}
    for row in data:
        day = row['day']
        reward = row['reward']
        if day not in day_to_rewards:
            day_to_rewards[day] = []
        day_to_rewards[day].append(row['reward'])

    for day, reward_list in day_to_rewards.items():
        day_to_rewards[day] = sorted(reward_list)

    total_reward = 0
    reward_list = []
    
    print(day_to_rewards)
    for day in range(1, m+1):
        print(day)
        if day in day_to_rewards:
            print('add')
            reward_list.extend(day_to_rewards[day])
        sorted(reward_list)
        print(reward_list)
        if len(reward_list) > 0:
            total_reward += reward_list.pop()
    return total_reward

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

data = []
for i in range(n):
    day, reward = map(int, input().split())
    data.append({
        'day': day,
        'reward': reward
    })

total_reward = calc_total_reward(m, data)    
print(total_reward)

Submission status: Wrong Answer

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()
    summation[i].reverse()
    if summation[i] != []:
        for v in summation[i]:
            lst.append(v)

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

Submission status: Wrong Answer

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

x=sorted(ab, key=lambda x :x[1])
x.reverse()

v=[i for i in range(1,m+1)]


for i in range(n):
    if v.count(0)==m:
        break
    if x[i][0]<=v[-1]:
        ans+=x[i][1]
    for j in range(x[i][0]-1,m):
            if v[j]>=x[i][0]:
                v[j]==0
                break
    else:
        continue
        
print(ans)

Submission status: Wrong Answer

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

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

lims = {}
for i in range(len(tasks)):
    arr = lims.get(tasks[i][1], [])
    arr.append(tasks[i][0])
    lims[tasks[i][1]] = arr

total = 0
for i in range(1, M + 1)[::-1]:
    task = None
    while True:
        if len(tasks) == 0:
            break
        task = tasks.pop()
        if task[0] <= i:
            break

    if len(tasks) > 0:
        days = lims[task[1]]
        if len(days) > 1:
            l = 10**6
            for j in range(len(days)):
                if l > i - days[j] and i - days[j] >= 0:
                    l = days[j]
            lims[task[1]].remove(l)
            if l <= i:
                total += task[1]
        else:
            if task[0] <= i:
                total += task[1]

print(total)

Submission status: Wrong Answer

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

ab.sort()
i = N
nums = []
while 1 <= i:
    if M <= 0:
        nums.sort(reverse = True)
        if nums[-1] < ab[i - 1][1]:
            nums.pop()
            nums.append(ab[i - 1][1])
    if  M >= 1:
        if ab[i -1][0] <= M:
            nums.append(ab[i - 1][1])
            M -= 1
        else:
            while ab[i - 1][0] > M:
                i -= 1
                if i - 1 < 0:
                    break
            if ab[i -1][0] <= M:
                nums.append(ab[i - 1][1])
                M -= 1
    i -= 1
    
if len(nums) == 0:
    nums.append(0)

print (sum(nums))

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split()]

dic = {}
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    if A <= M: dic.setdefault(A, []).append(B)

buf = []
for m in sorted(dic.keys(),reverse=True):
     buf.extend(sorted(dic[m],reverse=True)[:M-m+1])
print(sum(sorted(buf,reverse=True)[:M]))

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split()]

dic = {}
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    dic.setdefault(A, []).append(B)

buf = []
for m in sorted(dic.keys(),reverse=True):
     buf.extend(sorted(dic[m],reverse=True)[:M-m+1])
print(sum(sorted(buf,reverse=True)[:M]))

Submission status: Wrong Answer

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

n, m = input().split()
i, ans = 1, 0
for _ in range(int(n)):
  a, b = input().split()
  if (int(a) + (i - 1)) <= int(m):
    ans += int(b)
    i += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split()]

dic = {}
for _ in range(N):
    A,B = [int(x) for x in input().split()]
    dic.setdefault(A, []).append(B)

buf = []
for m in sorted(dic.keys(),reverse=True):
    buf.extend(dic[m][:M-m+1])
print(sum(sorted(buf,reverse=True)[:M]))

Submission status: Wrong Answer

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

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

total = 0
for i in range(1, M + 1)[::-1]:
    if len(tasks) > 0:
        task = tasks.pop()
        if task[0] <= i:
            total += task[1]

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def update(i, x):
    i += 1
    while i < m + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 2)
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], -x[0]))
cnt = 0
ans = 0
for a, b in ab:
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans += b
    if cnt == m: break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
choice = Counter()
ans = 0
for i in range(m):
    #choice += Counter(c[i])
    if choice:
        use = max(choice)
        ans += use
        choice[use] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
choice = Counter()
ans = 0
for i in range(m):
    choice += Counter(c[i])
    if choice:
        use = max(choice)
        ans += use
        #choice[use] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = []; b = []
for _ in range(n):
  _a, _b = map(int, input().split())
  a.append(_a)
  b.append(_b)

import numpy as np
a = np.array(a)
b = np.array(b)
 
r = 0
for i in range(1, m+1):
  b_tmp = b.copy()
  b_tmp[a > i] = 0
  j_max = np.argmax(b_tmp)
  r += b_tmp[j_max]
  b[j_max] = 0
	
print(r)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
choice = Counter()
ans = 0
"""for i in range(m):
    choice = choice + Counter(c[i])
    if choice:
        use = max(choice)
        ans += use
        choice[use] -= 1"""
print(ans)

Submission status: Wrong Answer

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

n, m = input().split()
i, ans = 1, 0
for _ in range(i, int(n)):
  a, b = input().split()
  if (int(a) + i) <= int(m):
    ans += int(b)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = []; b = []
for _ in range(n):
  _a, _b = map(int, input().split())
  a.append(_a)
  b.append(_b)

import numpy as np
a = np.array(a)
b = np.array(b)
"""
a, b = list(zip(*np.c_[a,b][np.argsort(a)[::-1]]))
a = np.array(a)
b = np.array(b)
"""

r = 0
for i in range(1, m+1):
  b_tmp = b.copy()
  b_tmp[a > i] = 0
  j_max = np.argmax(b_tmp)
  r += b_tmp[j_max]
  b[j_max] = 0
 
print(r)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [0] * N
B = [0] * N
ab = []
for i in range(N):
    A[i], B[i] = map(int, input().split())
    ab.append([A[i], B[i]])

ab.sort()
i = N
ans = 0
nums = []
while 1 <= i:
    if M <= 0:
        nums.sort()
        nums.reverse()
        if nums[-1] < ab[i-1][1]:
            nums.pop()
            nums.append(ab[i-1][1])
    if M >= 1:
        if ab[i-1][0] <= M:
            nums.append(ab[i-1][1])
            M -= 1
        else:
            while ab[i-1][0] > M:
                i -= 1
                if i - 1 < 0:
                    break
            if ab[i-1][0] <= M:
                nums.append(ab[i-1][1])
                M -= 1
    i -= 1

if len(nums) == 0:
    nums.append(0)

print(sum(nums))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
N, M = map(int, input().split())
AB_list = []
for i in range(N):
  A, B = map(int, input().split())
  if A <= M:
    AB_list.append([A, B])
  AB_list.sort(key=itemgetter(1, 0), reverse=True)
result = 0
i = 0
for m in range(M, 0, -1):
  while i < len(AB_list):
    a, b = AB_list[i]
    if a <= m:
      result += b
      AB_list.pop(i)
      break
    i += 1
print(result)

Submission status: Wrong Answer

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

n, m = input().split()
i = 0
ans = 0
for _ in range(int(n)):
  a, b = input().split()
  if (int(a) + i) <= int(m):
    ans += int(b)
    i += 1
    
print(ans)

Submission status: Wrong Answer

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

C = [[0,0] * x for x in range(N)] 
for i in range(N):
  C[i] = list(map(int, input().split()))
C.sort(key=lambda x: (x[1], x[0]), reverse=True)

cnt = 0
while len(C) > 0:
  m = C.pop(0)
  if m[0]<= M:
    M = M - 1
    cnt = cnt + m[1]

print(cnt)

Submission status: Wrong Answer

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

C = [[0,0] * x for x in range(N)] 
for i in range(N):
  C[i] = list(map(int, input().split()))
C.sort(key=lambda x: (x[1], x[0]), reverse=True)
B =[0 * x for x in range(N)]

def max_fee(d, Li):
#  print (d, Li)
  if d == 0:
    return 0
  else:
    for i in range(N):
#      print ("-> ", i,Li[i]) 
      if Li[i][0] <= d:
        m = Li[i][1]
        Li.remove(Li[i])
#        print ("-->", m)
        return m + max_fee(d-1, Li)
      else:
        return 0
    else:
      return 0

print (max_fee(M, C))

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst_f = [[] for i in range(m)]
#lst = sorted(lst, key=lambda x:x[0])
#lst = sorted(lst, key=lambda x:x[1], reverse=True)
cnt = 0
ans = 0
cntup = m
for a, b in lst:
  if a <= m:
    lst_f[a-1].append(b)
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
avb = [] 
for i in lst_f:
  for j in i:
    avb.append(-j)
  if avb != []:
    ans -= min(avb)
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC137D - Summer Vacation
import sys
input = sys.stdin.readline

from heapq import heappush, heappushpop


def main():
    N, M = tuple(map(int, input().split()))
    A = set(tuple(map(int, input().split())) for _ in range(N))
    T = [[] for _ in range(M + 1)]
    for a, b in A:
        if a <= M:
            T[M - a] += [b]
    q = []
    for i in range(M + 1):
        for v in T[i]:
            if len(q) <= i:
                heappush(q, v)
            else:
                heappushpop(q, v)
    print(sum(q))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import defaultdict
    from heapq import heappush, heappop
    _, m, *ab = map(int, open(0).read().split())
    works = defaultdict(list)
    for a, b in zip(*[iter(ab)]*2):
        works[a].append(-b)

    candidates, pay = [], 0
    for day in range(1, m+1):
        if day not in works:
            continue
        for x in works[day]:
            heappush(candidates, x)
        if candidates:
            pay += heappop(candidates)
    print(-pay)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappush, heappop

na = lambda: map(int, sys.stdin.readline().split())

n, m = na()
ab = [list(na()) for _ in range(n)]
ab.sort()

ans = 0
h = []
for day in range(1, m+1):
  for i in range(len(ab)):
    if ab[i][0] <= day:
      heappush(h, -ab[i][1])
    else:
      ab = ab[i:]
      break
  if h:
    ans += -heappop(h)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    _, m, *ab = map(int, open(0).read().split())
    ab = zip(ab[0::2], ab[1::2])
    pay = 0
    day = 0
    for t in reversed(sorted(ab, key=lambda x: (x[1], x[0]))):
        a, b = t

        # 目標日以降
        if day > m:
            break
        # 報酬が受け取れない
        if a > m or day+a > m:
            continue

        pay += b
        day += 1

    print(pay)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst = sorted(lst, key=lambda x:x[0])
lst = sorted(lst, key=lambda x:x[1], reverse=True)
#print(lst)
cnt = 0
for i in range(m):
  lst = [j for j in lst if j[0]<=m]
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
  #print(lst_f)
  if lst != []:
    #print(lst)
    cnt += lst[0][1]
    lst.remove(lst[0])
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst = sorted(lst, key=lambda x:x[0], reverse=True)
lst = sorted(lst, key=lambda x:x[1], reverse=True)
#print(lst)
cnt = 0
for i in range(m):
  lst = [j for j in lst if j[0]<=m-i]
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
  #print(lst_f)
  if lst != []:
    #print(lst)
    cnt += lst[0][1]
    del lst[0]
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst = sorted(lst, key=lambda x:x[0], reverse=True)
lst = sorted(lst, key=lambda x:x[1], reverse=True)
#print(lst)
cnt = 0
for i in range(m):
  lst = [j for j in lst if j[0]<=m-i]
  #print(filter(lambda y:y<=m-i, map(lambda x:x[0], lst)))
  #lst2 = list(filter(lambda y:y[1]<=m-i, lst))
  #print(lst_f)
  if lst != []:
    print(lst)
    cnt += lst[0][1]
    del lst[0]
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
class End:
    
    def __init__(self, i):
        self.i = i + 1


class Node:
    
    def __init__(self, i):
        self.end = End(i)


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

ans = 0
schedule = {}
BA.sort(reverse=True)
for b, a in BA:
    if a <= M:
        if a in schedule:
            w = schedule[a]
            x = w.end.i
            if x <= M:
                ans += b
                schedule[x] = w
                if x + 1 in schedule:
                    w.end.i = schedule[x + 1].end.i
                else:
                    w.end.i += 1
        else:
            ans += b
            if a + 1 in schedule:
                schedule[a] = schedule[a + 1]
                if a - 1 in schedule:
                    schedule[a - 1].end.i = schedule[a + 1].end.i
            elif a - 1 in schedule:
                schedule[a] = schedule[a - 1]
                schedule[a - 1].end.i += 1
            else:
                schedule[a] = Node(a)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from heapq import merge
from heapq import heappush


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

last_day_to_reward = {}

for i in range(N):
    a, b = map(int, input().split(' '))
    last_day = max(0, M - a + 1)
    if last_day not in last_day_to_reward:
        last_day_to_reward[last_day] = []
    heappush(last_day_to_reward[last_day], b)

ans = 0
candidate = []
for i in reversed(range(1, M+1)):
    if i in last_day_to_reward:
        candidate = list(merge(candidate, last_day_to_reward[i]))

    if candidate:
        r = candidate.pop(-1)
        ans += r

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

l=sorted(l, key=lambda x:x[1], reverse=True)

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

Submission status: Wrong Answer

Solution code:
class End:
    
    def __init__(self, i):
        self.i = i + 1


class Node:
    
    def __init__(self, i):
        self.end = End(i)


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

ans = 0
schedule = {}
BA.sort(reverse=True)
for b, a in BA:
    if a <= M:
        if a in schedule:
            w = schedule[a]
            x = w.end.i
            if x <= M:
                ans += b
                schedule[x] = w
                if x + 1 in schedule:
                    w.end = schedule[x + 1].end
                else:
                    w.end.i += 1
        else:
            ans += b
            if a + 1 in schedule:
                schedule[a] = schedule[a + 1]
            else:
                schedule[a] = Node(a)
            if a - 1 in schedule:
                schedule[a - 1].end = schedule[a].end
print(ans)

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())

#ab=sorted(ab,key=lambda x:x[1],reverse=True)
ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**10
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        #koho=np.append(koho,ab[i][1])
        heapq.heappush(koho,-ab[i][1])
        i+=1

    try:
        tmp=heapq.heappop(koho)
        res+=(-tmp)
    except:
        break

    
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())

#ab=sorted(ab,key=lambda x:x[1],reverse=True)
ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        #koho=np.append(koho,ab[i][1])
        heapq.heappush(koho,-ab[i][1])
        i+=1
    #print(koho)

    try:
        tmp=heapq.heappop(koho)
        res+=(-tmp)
    except:
        break

    #print(tmp)
    
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

#print(do)
'''
3 6
4 5
4 3
6 4

'''

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


import heapq

N,M=acinput()

ab=[]
for i in range(N):
    ab.append(acinput())

#ab=sorted(ab,key=lambda x:x[1],reverse=True)
ab=sorted(ab,key=lambda x:x[0])


res=0
do=[0]*(M+1)
nowdate=M-1

koho=[]
k=0
while True:
    #print(k)
    i=k
    while True:
        if i>=len(ab):
            k=10**8
            break
        if ab[i][0]+nowdate>M:
            k=i
            break
        #koho=np.append(koho,ab[i][1])
        heapq.heappush(koho,-ab[i][1])
        i+=1
    #print(koho)

    try:
        tmp=heapq.heappop(koho)
    except:
        break

    #print(tmp)
    res+=(-tmp)
    nowdate-=1
    if nowdate<0:
        break
    

print(int(res))

Submission status: Wrong Answer

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

d = 0
ans = 0
for i in reversed(range(1, M+1)):
  while d <= i:
    idx = B.index(max(B))
    if A[idx] <= i:
      d += A[idx]
      ans += B[idx]
      B[idx] = -1
    else:
      break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
N, M = map(int, input().split())
AB_list = []
for i in range(N):
  A, B = map(int, input().split())
  if A <= M:
    AB_list.append([A, B])
  AB_list.sort(key=itemgetter(1, 0), reverse=True)
result = 0
for m in range(M, 0, -1):
  pass
#  for i in range(len(AB_list)):
#    pass
    # ab = AB_list[i]
    # if ab[0] <= m:
    #   result += ab[1]
    #   AB_list.pop(i)
    #   break
print(result)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
N, M = map(int, input().split())
AB_list = []
for i in range(N):
  A, B = map(int, input().split())
  if A <= M:
    AB_list.append([A, B])
  AB_list.sort(key=itemgetter(1, 0), reverse=True)
result = 0
for m in range(M, 0, -1):
  for i in range(len(AB_list)):
    pass
    # ab = AB_list[i]
    # if ab[0] <= m:
    #   result += ab[1]
    #   AB_list.pop(i)
    #   break
print(result)

Submission status: Wrong Answer

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 UnionFind:

    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.height = [0 for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def getsize(self, x):
        return self.size[self.find(x)]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.height[x] < self.height[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = self.par[x]
            self.size[x] += self.size[y]
            if self.height[x] == self.height[x]:
                self.height[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

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])
ans = 0
# print(ab)
uf = UnionFind(M+2)
bit = BIT(M)
ub = M+1
for a, b in ab:
    # print([bit.sum(i) for i in range(1, M+1)])
    i = M-a+1
    # print(i, ub)
    if bit.sum(i) < i and a < ub:
        ans += b
        bit.add(i, 1)
        uf.unite(i, i+1)
        lb = 0
        while lb+1 < ub:
            mid = (lb+ub)//2
            if uf.same(mid, ub):
                ub = mid
            else:
                lb = mid
# print([bit.sum(i) for i in range(1, M+1)])
# print()
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter, attrgetter
N, M = map(int, input().split())
AB_list = []
for i in range(N):
  A, B = map(int, input().split())
  if A <= M:
    AB_list.append([A, B])
  AB_list.sort(key=itemgetter(1, 0), reverse=True)
result = 0
for m in range(M, 0, -1):
  for i in range(len(AB_list)):
    ab = AB_list[i]
    if ab[0] <= m:
      result += ab[1]
      AB_list.pop(i)
      break
print(result)