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:
# ABC-137-D
import heapq
N, M = map(int, input().split())
BA = []
for _ in range(N):
    A, B = map(int, input().split())
    BA.append((-1*B, A))
heapq.heapify(BA)

ans = 0
check_M = 1
while check_M <= M:
    try:
        max_B = heapq.heappop(BA)
    except:
        break
    if max_B[1] <= check_M:
        ans += (-1) * max_B[0]
        check_M += 1

print(ans)

Submission status: Wrong Answer

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

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M = LI()
    ab = []
    for _ in range(N):
        a, b = LI()
        ab.append((a, b))
    ab = sorted(ab, key=lambda x: (x[1], x[0]))[::-1]
    i = 0
    cnt = 0
    while 0 < M and i < N:
        day, money = ab[i]
        if day > M:
            pass
        else:
            cnt += money
            M -= 1
        i += 1
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
import heapq

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

ans = 0
candidates = []
now = 0
for i in range(M+1):
  for j in range(now, N):
    if AB[j][0] <= i:
      heapq.heappush(candidates, -AB[j][1])
      
    else:
      now = j
      break
  
  if candidates:
    ans -= heapq.heappop(candidates)

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
earn = 0
AB.sort(key=lambda x:x[0])
pos=0
cando=[]
for remain in range(M+1):
    for i in range(pos,len(AB)):
        if AB[i][0] <= remain:
            heapq.heappush(cando, -AB[i][1])
        else:
            pos=i
            break
    if cando:
        earn-=heapq.heappop(cando)
print(earn)

Submission status: Wrong Answer

Solution code:
import heapq
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
queue = []
flag = 0
heapq.heapify(queue)
ans = 0
for i in range(1,m+1):
  for j in range(flag,n):
    if ab[j][0] > i:
      flag = j
      break
    heapq.heappush(queue,-ab[j][1])
  if queue != []:
    k = heapq.heappop(queue)
    ans += k
print(-ans)

Submission status: Wrong Answer

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

day = 0
ans = 0
A_B = sorted(A_B, key=lambda x:(-x[1], -x[0]))
#print(A_B)
for i in range(N):
  #print(day)
  for j in range(i, N):
    if day + A_B[j][0] <= M:
      ans += A_B[j][1]
      break
  day += 1
print(ans)

Submission status: Wrong Answer

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

day = 0
ans = 0
A_B = sorted(A_B, key=lambda x:(-x[1], -x[0]))
#print(A_B)
for i in range(N):
  #print(day)
  if day + A_B[i][0] <= M:
    ans += A_B[i][1]
  day += 1
print(ans)

Submission status: Wrong Answer

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

day = 0
ans = 0
A_B = sorted(A_B, key=lambda x:(-x[1], -x[0]))
print(A_B)
for i in range(N):
  print(day)
  if day + A_B[i][0] <= M:
    print("a")
    ans += A_B[i][1]
  day += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

Submission status: Wrong Answer

Solution code:
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
        elif self.award==other.award and self.date<other.date:
            return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
        elif self.award==other.award and self.date>other.date:
            return True
        else:
            return False
            
    def __eq__(self,other):
        return (self.award==other.award and self.date==other.date)
jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            break
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        if self.award<other.award:
            return True
        elif self.award==other.award and self.date<other.date:
            return True
        else:
            return False
    def __lt__(self,other):
        if self.award>other.award:
            return True
        elif self.award==other.award and self.date>other.date:
            return True
        else:
            return False
            
    def __eq__(self,other):
        return (self.award==other.award and self.date==other.date)
jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            i+=1
            break
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        return self.award<other.award
    def __lt__(self,other):
        return self.award>other.award
    def __ge__(self,other):
        return self.award<=other.award
    def __le__(self,other):
        return self.award>=other.award
    def __eq__(self,other):
        return self.award==other.award
jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            i+=1
            break
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

class job:
    def __init__(self,name,date,award):
        self.name=name
        self.award=award
        self.date=date
    def __gt__(self,other):
        return self.award<other.award
    def __lt__(self,other):
        return self.award>other.award
    def __ge__(self,other):
        return self.award<=other.award
    def __le__(self,other):
        return self.award>=other.award
jobs=[]
n,m=[int(i) for i in input().split()]
for i in range(n):
    info=[int(j) for j in input().split()]
    jobs.append(job(i,info[0],info[1]))
heapq.heapify(jobs)
ans=0
for i in range(m):
    while jobs:
        work=heapq.heappop(jobs)
#         print(work.award)
        if work.date+i<=m:
            ans+=work.award
            i+=1
            break
        
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(n)],key= lambda x:(-x[1],-x[0]))
cnt=0
for i in range(n):
    if i+AB[i][0]<=m:
        cnt+=AB[i][1]

print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq

n, m = (int(i) for i in input().split())

AB = {i:[] for i in range(1, 10 ** 5 + 1)}

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

q = []
heapq.heapify(q)

ans = 0
for i in range(1,m+1):
    heapq.heapify(AB[i])
    q += AB[i]
    if q != []:
        ans += heapq.heappop(q)

print(-ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab_list = []
for i in range(n):
    # a,b = map(int,input().split())
    # ab_list.setdefault(b,[]).append(a)
    ab_list.append(list(map(int,input().split())))
ab_list = sorted(ab_list, key= lambda x:(x[1],x[0]),reverse=True)
amount = 0
for ab in ab_list:
    if ab[0]<=m:
        amount = amount + ab[1]
        m = m-1
    if m == 0:
        break

print(amount)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
now=0#今日
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([b,a])
l=sorted(l)
index=-1
ans=0
while now<m:#m日後まで
  if index<-n:
      now=m 
  elif now+l[index][1]>m:
    index-=1
  else:
    ans+=l[index][0]
    index-=1
    now+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
now=0#今日
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l=sorted(l)
index=-1
ans=0
while now<m:#m日後まで
  if now+l[index][0]>m:
    index-=1
    if index<-n:
      now=m 
  else:
    ans+=l[index][1]
    now+=1
print(ans)

Submission status: Wrong Answer

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

N,M = map(int,input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort(key=itemgetter(1,0), reverse=True)

answer = 0
for j in range(M):
    for i,[a,b] in enumerate(AB):
        if a + j <= M:
            answer += b
            AB.pop(i)
            break
        # j日目に仕事できない場合
        if i == len(AB) - 1:
            print(answer)
            exit()

print(answer)

Submission status: Wrong Answer

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

N,M = map(int,input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
# 日数の降順に並べてから、報酬の降順に並べる
AB.sort(key=itemgetter(1,0), reverse = True)

day = 0
answer = 0
for a,b in AB:
    # バイトを受ける場合
    if a + day <= M:
        day += 1
        answer += b

print(answer)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [[0,0] for _ in range(n)]
 
for i in range(n):
  a, b = map(int, input().split())
  l[i][0] = a
  l[i][1] = b
  
l.sort()

import heapq
a = []
heapq.heapify(a)

temp = 0
ans = 0
for i in range(m):
  for j in range(temp, n):
    if l[j][0] <= i+1:
      heapq.heappush(a, (-1)*l[j][1])
    else:
      temp = j
      break
  if len(a) != 0:
    ans += heapq.heappop(a)*(-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


B_MAX = (10**5)
def main():
    n, m = map(int, input().split())

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

    ans = 0
    for i in range(m + 1):
        m_i_ab = (m - i, B_MAX)
        idx = bisect.bisect_left(ab_list, m_i_ab)
        if idx:
            temp_max_ab = max(ab_list[:idx], key=lambda x: x[1]*(10**5)+x[0])
            max_idx = ab_list.index(temp_max_ab)
            temp_ab = ab_list.pop(max_idx)
            ans += temp_ab[1]
        else:
            continue

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

        if len(arr) == 0:
            break

    return sum

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

Submission status: Wrong Answer

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

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

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

        if len(arr) == 0:
            break

    return sum

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

Submission status: Wrong Answer

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

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

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

        if len(arr) == 0:
            break

    return sum

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

Submission status: Wrong Answer

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

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

        if len(arr) == 0:
            break

    return sum

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


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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n,m=map(int,input().split())
l=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=itemgetter(1))

ll=[]
t_ll=[]
x=l[0][1]
for i in l:
    if i[1]==x:
        t_ll.append(i)
    else:
        t_ll=sorted(t_ll,reverse=True,key=itemgetter(0))
        ll+=t_ll
        t_ll=[]
        t_ll.append(i)
        x=i[1]

day=0
money=0
for a,b in ll:
    if a<=m-day:
        money+=b
        day+=1
print(money)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

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

A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append((a,-b))
A = sorted(A,key=lambda x:(-x[0], -x[1]))
#この時点で、Aは(日付、-報酬)のタプルで、日付降順→(-報酬)降順になっている

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

for i in range(1,M+1):
    while A and A[-1][0]<=i:
        data = A.pop()
        heapq.heappush(H,data)
    if H:
        ans += -(heapq.heappop(H)[1])

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
arbeits = [tuple(map(int, input().split())) for _ in range(N)]
arbeits = sorted(arbeits, key=lambda x: (x[1], x[0]))
ans = 0
while arbeits and M > 0:
    day, pay = arbeits.pop()
    if day <= M:
        ans += pay
        M -= 1
print(ans)

Submission status: Wrong Answer

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      if idx + 1 < M:
        sh[idx] = sh[idx+1]
        sh[x["d"]] = sh[idx+1]
      else:
        sh[idx] = idx+1
        sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Submission status: Wrong Answer

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

#md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      sh[idx] = idx+1
      sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Submission status: Wrong Answer

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

md = []
for i in range(0,N):
  d, m = map(int, input().split())
  md.append({"m":m, "d":d-1})

md = sorted(md, key=lambda x:x["m"], reverse=True)

sh = [0]*M
ans = 0
for x in md:
  idx = x["d"]
  while idx < M :
    if sh[idx] == 0:
      sh[x["d"]] = idx+1
      ans += x["m"]
      break
    else:
      idx = sh[idx]
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
md = [0]*N

for i in range(0,N):
  d, m = map(int, input().split())
  md[i] = {"m":m, "d":d}

md = sorted(md, key=lambda x:x["m"], reverse=True)
print(md)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())

A = []
for i in range(N):
  X = list(map(int, input().split()))
  A.append(X)
  
A = sorted(A, key=itemgetter(1,0), reverse=True)
#print(A)

ans = 0
x = M

for a in A:
  if a[0] <= x:
    ans += a[1]
    x -= 1
    if x < 0:
      break
      
print(ans)

Submission status: Wrong Answer

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

lengths = []
vals = []

data = []

for i in range(n):
    x, y = [int(i) for i in input().split()]
    data.append([y, x])

data.sort(reverse=True)

for i, j in data:
    vals.append(i)
    lengths.append(j)

taken = 0
ans = 0
for i in range(n):
    if lengths[i] <= m - taken:
        taken += 1
        ans += vals[i]

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    # 10**5連勤とか超人すぎる
    n, m = [int(x) for x in sys.stdin.readline().split()]

    job_list = dict((i, collections.deque()) for i in range(1, m+1))
    for _ in range(n):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        if a <= m:
            job_list[a].append(b)

    # 同じ日にできる仕事が二つ以上あったとして、
    # 第一に報酬が最も高い仕事をその日のシフトに入れる
    # それよりも前の日に空きがあれば残りの仕事を報酬の高い順に入れる
    # 空きがなかった場合、前日以前にやる仕事の中で最も報酬の低いものよりも、残りの仕事のなかで
    # 最も報酬の高いものの方が良ければ、その日の予定をを更新する。

    day_rewards = [0 for _ in range(m+1)] # 期限当日は報酬ゼロとして

    for i in range(m, 0, -1):
        while job_list[i]:
            if i < m:
                mi = min(day_rewards[i:])
                if mi < max(job_list[i]):
                    day_rewards[day_rewards.index(mi, i)] = max(job_list[i])
                    job_list[i].remove(max(job_list[i]))
                else:
                    break
            else:
                break
                
    print(sum(day_rewards))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

income = [[0, 0]] * n
ans = 0
dp = [0] * (m+1)

for i in range(n):
  in_a, in_b = map(int, input().split(' '))
  income[i] = [in_a, in_b]

# print(n, m)
# print(income)

tmp = sorted(income, key=lambda x: x[0], reverse=True)
sorted_income = sorted(tmp, key=lambda x: x[1], reverse=True)

# print(sorted_income)

for i in range(m):
  j = 0
  while True:
    if j >= len(sorted_income):
      break
    
    income = sorted_income[j]
    if i + income[0] > m:
      # もらえるタイミングが期間外なので、その仕事はしない
      j += 1
      continue
    dp[i + income[0]] += income[1]
    del sorted_income[j]
    j += 1
    break
# print(dp)
print(sum(dp))

Submission status: Wrong Answer

Solution code:
#D summer vacation
n,m=map(int,input().split())
lists=[tuple(map(int,input().split())) for _ in range(n)]

lists=sorted(lists,key=lambda x:[x[1],x[0]])
lists=lists[::-1]

ans=0
i=0
for some in lists:
    if some[0]+i<=m:
        ans+=some[1]
        i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#D summer vacation
n,m=map(int,input().split())
lists=[tuple(map(int,input().split())) for _ in range(n)]

lists=sorted(lists,key=lambda x:[x[1],x[0]])
lists=lists[::-1]

ans=0
for i in range(n):
    if lists[i][0]+i<=m:
        ans+=lists[i][1]
print(ans)

Submission status: Wrong Answer

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

l=sorted(l)[::-1]
a=[]

for i in range(n):
    a.append([l[i][0]+l[i][1],l[i][0],l[i][1]]) #[報酬＋日数,日数,報酬]

a=sorted(a)[::-1]

s=0
j=0
for i in range(n):
    while (m-i)<a[j][1]:
        j+=1
        if j==n:
            break
    if j==n:
        break
    if (m-i)>a[j][1] or (m-i)==a[j][1]:
        s+=a[j][2]
        j+=1
    if j==n:
        break

print(s)

Submission status: Wrong Answer

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


def main():
    N, M = map(int, input().split())
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    AB.sort(key=lambda x: x[0], reverse=True)
    AB.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    for a, b in AB:
        if a <= M:
            ans += b
            M -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
c=max([x[0] for x in ab])
d=[0]*(c+1)
for i in range(n):
    d[ab[i][0]]=max(d[ab[i][0]],ab[i][1])
print(sum(d[0:m+1]))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[0]*(M+1)
for i in range(M+1):
    A[i]=[]
for i in range(N):
    b,a=map(int,input().split())
    if b <= M:
        A[b].append(a)
for i in range(M):
     A[i]=sorted(A[i])

salary=0
for i in range(1,M+1):
    maxi = 0
    index = i
    for k in range(1,i+1):
        if A[k]!=[]:
            if maxi < A[k][0]:
                maxi = A[k][0]
                index = k
                A[k].pop(0)
    salary += maxi
print(salary)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from operator import itemgetter

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB = list(zip(A,B))
    AB.sort(key=itemgetter(1,0),reverse=True)
    
    answer = 0
    day = M
    i = 0
    ## M件受注するかもう求人がない時終わり
    while day >0 and i<N:
        if AB[i][0] <= day:
            answer += AB[i][1]
            day-=1
        i+=1
    print(answer)
                
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, M = LI()
AB = [[] for i in range(N)]
ABm = [[] for _ in range(M+1)]
for i in range(N):
    AB[i] = LI()
    if AB[i][0]<=M:
        ABm[AB[i][0]].append(AB[i][1])
#AB.sort(key=lambda x: x[1],reverse = True)
#print(ABm)
ans = []
cou = []
heapq.heapify(cou)
loop = M
for i in range(loop):
    for j in ABm[i+1]:
        heapq.heappush(cou, -j)
#    print(cou)
    if cou:
        ans.append(heapq.heappop(cou)*(-1))

#print(ans)
if ans:
    print(sum(ans))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB,key=lambda x:x[0],reverse=True)
AB = sorted(AB,key=lambda x:x[1],reverse=True)
dp = [0 for _ in range(M)]
rest = M
for a,b in AB:
    aa = a-1
    if aa >= rest:
        continue
    if dp[aa] == 0:
        dp[aa] = b
    else:
        flag = False
        for i in range(aa,rest):
            if dp[i] == 0:
                dp[i] = b
                flag = True
        if flag is False:
            rest = aa
print(sum(dp))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x:(x[0],x[1]),reverse=True)
idx = 0
value = 0
cnt = 0
day = M
for j in range(N):
  if arr[j][0] <= day:
    value += arr[j][1]
    day -= 1
    cnt += 1
  if cnt==N:
    break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x:(x[1],x[0]),reverse=True)
idx = 0
value = 0
cnt = 0
day = M
for j in range(N):
  if arr[j][0] <= day:
    value += arr[j][1]
    day -= 1
    cnt += 1
  if cnt==N:
    break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x:(x[0],x[1]),reverse=True)
idx = 0
value = 0
cnt = 0
for i in range(M,0,-1):
  for j in range(idx,N):
    if arr[j][0] <= i:
      idx = j+1
      value += arr[j][1]
      cnt += 1
      break
  if (idx == N-1) or (cnt==N):
    break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x:(x[0],x[1]),reverse=True)
idx = 0
value = 0
cnt = 0
for i in range(M,0,-1):
  for j in range(idx,N):
    if arr[j][0] <= i:
      idx = j
      value += arr[j][1]
      cnt += 1
      break
  if (idx == N-1) or (cnt==N):
    break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x:(x[0],x[1]))
arr=arr[::-1]
idx = 0
value = 0
for i in range(M,0,-1):
  for j in range(idx,N):
    if arr[j][0] <= i:
      idx = j
      value += arr[j][1]
      break
  if idx == N-1:
    break
print(value)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
memo = [0] * M
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    memo[a - 1] = max(b, memo[a - 1])
ans = sum(memo)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * min(N, M)
ans = 0
for a, b in AB:
    Ma = max(M - a + 1, 0)
    i = bisect.bisect_right(memo[:Ma], 0) - 1
    if i >= 0:
        memo[i] = 1
        ans += b
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * min(N, M)
ans = 0
for a, b in AB:
    Ma = max(M - a + 1, 0)
    if 0 in memo[:Ma]:
        i = bisect.bisect_right(memo[:Ma], 0) - 1
        memo[i] = 1
        ans += b
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1], reverse=True)
memo = [0] * N
ans = 0
for a, b in AB:
    Ma = M - a + 1
    if 0 in memo[:Ma]:
        i = bisect.bisect_right(memo[:Ma], 0) - 1
        memo[i] = 1
        ans += b
print(ans)

Submission status: Wrong Answer

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

import heapq

h = []

for i in range(N):
    heapq.heappush(h, [-L[i][1], L[i][0]])
    
ans = 0
flag = [0]*(M+1)
for i in range(M):
    if h:
        temp = heapq.heappop(h)
        j = temp[1]
        while j <= M:
            if flag[j] == 0:
                flag[j] = 1
                j = M
                ans -= temp[0]
            j += 1
    else:
        break

    
print(ans)

Submission status: Wrong Answer

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

balist=[]
for i in range(N):
  A,B=map(int,input().split())
  balist.append((B,A))
  
balist.sort(reverse=True)
#print(balist)

answer=0
day=0
for (b,a) in balist:
  if day+a<=M:
    #print(b,day+a)
    answer+=b
    day+=1
    
  if day>=M:
    break
    
print(answer)