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:
#Binary Indexed Tree (1-index！！！！！！！！)
class BinaryIndexedTree():
    def __init__(self, size):
        self.__node = [0] * (size+1)
        self.size = size

    #node[index]にvalueを足して、BITを更新 O(logN)
    def add(self, index, value):
        while index <= self.size:
            self.__node[index] += value
            index += index&-index    
    
    #indexまでの和を返す O(logN)
    def sum(self, index):
        ret = 0 #零元・単位元
        while index > 0:
            ret += self.__node[index]
            index -= index&-index    
        return ret

    def update_max(self, index, value):
        while index <= self.size:
            self.__node[index] = max(self.__node[index], value)
            index += index & -index


    #indexまでの最大値を返す
    def query_max(self, index):
        ret = 0
        while index > 0:
            ret = max(ret, self.__node[index])
            index -= index & -index
        return ret
        
        

    #0-indexでの添字を受け取って、1-indexでの添字での値を返す
    def get_node(self, index):
        return self.__node[index]

    def show(self):
        #print(self.__node)
        for date in range(1,self.size+1):
            print("date,",date,self.sum(date))

#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M= MI()
    works = LLIN(N)
    works.sort(key = itemgetter(1),reverse = True)
    BIT = BinaryIndexedTree(M)
    for date in range(1,M+1):
        #print(date)
        BIT.add(date,1)
    ans = 0
    for date, money in works:
        #BIT.show()
        if BIT.sum(M-date+1)>0:
            #print(M-date+1)
            BIT.add(M-date+1, -1)
            ans += money
    print(ans)
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
to = {}
rew = []
day = [0 for _ in range(m)]
count = 0
for i in range(n):
    a, b = map(int, input().split())
    to[a-1] = to.get(a-1, 0) + 1
    rew.append(b)
index_count = 0
for i in range(m):
    index_count += to.get(i, 0)
    candidate = rew[0:index_count]
    #print(candidate)
    if len(candidate) == 0:
        continue
    max_index = candidate.index(max(candidate))
    count += candidate[max_index]
    rew[max_index] = 0
    
print(count)

Submission status: Wrong Answer

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

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

#sort by hosyu
work_list.sort(key=itemgetter(1), reverse=True)
sum = 0
workdays = list(range(M+1))

for day, reward in work_list:
    latest = M - day

    #find maximum day
    k = workdays[:latest+1]

print(sum)

Submission status: Wrong Answer

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

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

#sort by hosyu
work_list.sort(key=itemgetter(1), reverse=True)
sum = 0
workdays = list(range(M+1))

for day, reward in work_list:
    latest = M - day

    #find maximum day
    k = workdays[:latest+1]
    if len(k) > 0:
        work_day = max(k)
        if work_day > -1:
            workdays[work_day] = -1
            sum += reward

print(sum)

Submission status: Wrong Answer

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

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

#sort by hosyu
work_list.sort(key=itemgetter(1), reverse=True)
sum = 0
workdays = list(range(M+1))

for day, reward in work_list:
    latest = M - day

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

print(sum)

Submission status: Wrong Answer

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

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

#sort by hosyu
work_list.sort(key=itemgetter(1), reverse=True)
sum = 0
workdays = list(range(M+1))

for day, reward in work_list:
    latest = M - day

    #find maximum day
    k = list(filter((lambda x: x > -1), workdays[:latest+1]))
    if len(k) == 0:
        continue
    else:
        work_day = max(k)
        workdays[work_day] = -10
        sum += reward

print(sum)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

N,M = (int(i) for i in input().split())
C=[0]*N
T = []

for i in range(N):
    C[i] = [int(j) for j in input().split()]

C.sort()
k = 0
ans = 0
for j in range(0,M+1):
    for i in range(k,N):
        if C[i][0] > j:
            k = i
            break
        else:
            heappush(T,-1*C[i][1])
    if T != []:
        ans += -1 * heappop(T)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

N,M = (int(i) for i in input().split())
C=[0]*N
T = []

for i in range(N):
    C[i] = [int(j) for j in input().split()]

C.sort()
k = 0
ans = 0
for j in range(1,M+1):
    for i in range(k,N):
        if C[i][0] > j:
            k = i
            break
        else:
            heappush(T,-1*C[i][1])
    if T != []:
        ans += -1 * heappop(T)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

N,M = (int(i) for i in input().split())
C=[0]*N
T = []

for i in range(N):
    C[i] = [int(j) for j in input().split()]

C.sort()
print(C)
k = 0
ans = 0
for j in range(1,M+1):
    for i in range(k,N):
        if C[i][0] > j:
            k = i
            break
        else:
            heappush(T,-1*C[i][1])
    if T != []:
        ans += -1 * heappop(T)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

N,M = (int(i) for i in input().split())
C=[0]*N
T = []

ans = 0
for i in range(N):
    C[i] = [int(j) for j in input().split()]

C.sort()
k = 0
ans = 0
for j in range(1,M+1):
    for i in range(k,N):
        if C[i][0] > j:
            k = i
            break
        else:
            heappush(T,-1*C[i][1])
    if T != []:
        ans += -1 * heappop(T)

print(ans)

Submission status: Wrong Answer

Solution code:
#Binary Indexed Tree (1-index！！！！！！！！)
class BinaryIndexedTree():
    def __init__(self, size):
        self.__node=[0]+[1]*(size)
        self.size = size

    #node[index]にvalueを足して、BITを更新 O(logN)
    def add(self, index, value):
        while index <= self.size:
            self.__node[index] += value
            index += index&-index    
    
    #indexまでの和を返す O(logN)
    def sum(self, index):
        ret = 0 #零元・単位元
        while index > 0:
            ret += self.__node[index]
            index -= index&-index    
        return ret

    def update_max(self, index, value):
        while index <= self.size:
            self.__node[index] = max(self.__node[index], value)
            index += index & -index


    #indexまでの最大値を返す
    def query_max(self, index):
        ret = 0
        while index > 0:
            ret = max(ret, self.__node[index])
            index -= index & -index
        return ret
        
        

    #0-indexでの添字を受け取って、1-indexでの添字での値を返す
    def get_node(self, index):
        return self.__node[index]

#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M= MI()
    works = LLIN(N)
    works.sort(key = itemgetter(1),reverse = True)
    BIT = BinaryIndexedTree(M)
    ans = 0
    for date, money in works:
        if BIT.sum(M-date+1)>0:
            BIT.add(M-date+1, -1)
            ans += money
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

point = [0] * M
C = [[i, j] for i, j in zip(A, B)]
C = sorted(C, key = lambda x:(x[1], x[0]), reverse = True)

for j in range(M):
    for i in range(N):
        if C[i][0] + j <= M:
            point[j] = C[i][1]
            C.pop(i)
            N -= 1
            break

print(sum(point))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [False]*N
for i in range(N):
    AB[i] = tuple(map(int, input().split()))
AB.sort(key=lambda x: x[0], reverse=True)
AB.sort(key=lambda x: x[1], reverse=True)

ans, idx = 0, 0
for i in reversed(range(1, M+1)):
    for j in range(idx, N):
        if AB[j][0] <= i:
            ans += AB[j][1]
            break
    idx = j + 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(s[0])]
l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]
upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]

if len(upper) == 0:
    print(0)
elif len(lower) == 0:
    print(sum([i[1] for i in upper]))
else:
    lower_max = max([i[1] for i in lower])
    upper_min = min([i[1] for i in upper])
    x = sorted([i for i in upper if i[1] < lower_max],key=lambda i:i[1])
    y = [i for i in upper if i[1] >= lower_max]
    z = sorted([i for i in lower if i[1] > upper_min],key=lambda i:i[1],reverse=True)
    w = [i for i in lower if i[1] <= upper_min]
    if len(z) == 0 or len(x) == 0:
        print(sum([i[1] for i in upper]))
    elif len(x) > len(z):
        print(sum([i[1] for i in z])+sum([i[1] for i in x])-sum([i[1] for i in x[:len(z)]])+sum([i[1] for i in y]))
    else:
        print(sum([i[1] for i in z[:len(x)]])+sum([i[1] for i in y]))

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(s[0])]
l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]
upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]

if len(upper) == 0:
    print(0)
elif len(lower) == 0:
    print(sum([i[1] for i in upper]))
else:
    lower_max = max([i[1] for i in lower])
    upper_min = min([i[1] for i in upper])
    x = sorted([i for i in upper if i[1] < lower_max],key=lambda i:i[1])
    y = [i for i in upper if i[1] >= lower_max]
    z = sorted([i for i in lower if i[1] > upper_min],key=lambda i:i[1],reverse=True)
    w = [i for i in lower if i[1] <= upper_min]
    if len(x) > len(z):
        print(sum([i[1] for i in z])+sum([i[1] for i in x])-sum([i[1] for i in x[:len(z)]])+sum([i[1] for i in y]))
    else:
        print(sum([i[1] for i in z[:len(x)]])+sum([i[1] for i in y]))

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(s[0])]
l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]

upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]

if len(upper) == 0:
    print(0)
elif len(lower) == 0:
    print(sum([i[1] for i in upper]))
else:
    lower_max = max([i[1] for i in lower])
    upper_min = min([i[1] for i in upper])  
    x = sorted([i for i in upper if i[1] < lower_max],key=lambda i:i[1])
    y = [i for i in upper if i[1] >= lower_max]
    z = sorted([i for i in lower if i[1] > upper_min],key=lambda i:i[1],reverse=True)
    if len(x) > len(z):
        print(sum([i[1] for i in z])+sum([i[1] for i in x[len(x)-len(z)+1:]])+sum([i[1] for i in y]))
    elif len(x) < len(z):
        print(sum([i[1] for i in z[:len(x)]])+sum([i[1] for i in y]))
    else:
        print(sum([i[1] for i in z])+sum([i[1] for i in y]))

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(s[0])]
l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]

upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]

if len(upper) == 0:
    print(0)
elif len(lower) == 0:
    print(sum([i[1] for i in upper]))
else:
    lower_max = max([i[1] for i in lower])
    upper_min = min([i[1] for i in upper])  
    x = sorted([i for i in upper if i[1] < lower_max],key=lambda i:i[1])
    y = [i for i in upper if i[1] >= lower_max]
    z = sorted([i for i in lower if i[1] > upper_min],key=lambda i:i[1],reverse=True)
    if len(x) > len(z):
        print(sum([i[1] for i in z])+sum([i[1] for i in x[len(x)-len(z)+1:]])+sum([i[1] for i in y]))
    else:
        print(sum([i[1] for i in z[:len(x)]])+sum([i[1] for i in y]))

Submission status: Wrong Answer

Solution code:
s = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(s[0])]
l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]

upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]

if len(upper) == 0:
    print(0)
elif len(lower) == 0:
    print(sum([i[1] for i in upper]))
else:
    lower_max = max([i[1] for i in lower])
    upper_min = min([i[1] for i in upper])  
    x = sorted([i for i in upper if i[1] < lower_max],key=lambda i:i[1])
    y = [i for i in upper if i[1] >= lower_max]
    z = sorted([i for i in lower if i[1] > upper_min],key=lambda i:i[1],reverse=True)
    w = [i for i in lower if i[1] <= upper_min]
    if len(x) > len(z):
        print(sum([i[1] for i in z])+sum([i[1] for i in x[len(x)-len(z)+1:]])+sum([i[1] for i in y]))
    else:
        print(sum([i[1] for i in z[:len(x)+1]])+sum([i[1] for i in y]))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
n, m = map(int, stdin.readline().split())
L = [list(map(int,input().split())) for i in range(n)]

ten = 0
for i in range(n):
    L = sorted(filter(lambda x:x[0]<=m, L), key = lambda x:-x[1])
    for j in range(len(L)):
        L[j][0]+=i
    if len(L):
        ten +=L[0][1]
        L.pop(0)
    else:
        break
print(ten)

Submission status: Wrong Answer

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

l_1 = [i for i in l if i[0] <= s[1]]
t = sorted(l_1,key=lambda i:i[0],reverse=True)
l_2 = [j+[s[1]-i] for j,i in zip(t,[p for p in range(s[0])])]
upper = [i for i in l_2 if i[0]<=i[2]]
lower = [i for i in l_2 if i[0]>i[2]]
if len(lower) == 0:
    print(sum([i[1] for i in upper]))
elif len(upper) == 0:
    print(0)
else:
    while max([i[1] for i in lower]) > min([i[1] for i in upper]):
        index_max = [i for i, x in enumerate(lower) if x[1] == max([i[1] for i in lower])]
        lower_max_b = [lower[i] for i in index_max]
        index_min = [i for i, x in enumerate(upper) if x[1] == min([i[1] for i in upper])]
        upper_min_b = [upper[i] for i in index_min]
        for i,j in zip(index_max,index_min):
            lower[i],upper[j] = upper[j],lower[i]  
        print(sum([i[1] for i in upper]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


def main():
    n, limit = map(int, input().split())
    jobs = [list(map(int, input().split())) for _ in range(n)]

    for j in jobs:
        j.append(j[0] * j[1])
        j.append(True)

    jobs.sort(key=lambda x: x[2], reverse=True)
    jobs = deque(jobs)

    money = 0

    while limit:
        for j in jobs:
            if j[0] <= limit and j[3]:
                j[3] = False
                money += j[1]
                limit -= 1
                break

        else:
            limit -= 1

    print(money)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


def main():
    n, limit = map(int, input().split())
    jobs = [list(map(int, input().split())) for _ in range(n)]

    jobs.sort(key=lambda x: x[1], reverse=True)
    jobs = deque(jobs)

    money = 0

    while limit:
        for j in jobs:
            if j[0] <= limit:
                job = jobs.popleft()
                money += job[1]
                limit -= 1
                break

        else:
            limit -= 1

    print(money)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# D - Summer Vacation

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

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

print(reward)

Submission status: Wrong Answer

Solution code:
n,m=(int(i) for i in input().split())
r=0
s=[[] for i in range(m+1)]
for i in range(n):
  a,b=(int(i) for i in input().split())
  if a<=m:
    s[a].append([a,b])
for i in range(m):  
  s[i+1].sort(key=lambda x:x[1])
c=[]
for i in range(m):
  if len(s[i+1])!=0:
    c.append(s[i+1].pop())
    c.sort(key=lambda x:x[1])
  if len(c)!=0:
    k=c.pop()
    r+=k[1]
    if len(s[k[0]])!=0:
      c.append(s[k[0]].pop())
print(r)

Submission status: Wrong Answer

Solution code:
n,m=(int(i) for i in input().split())
r=0
s=[[] for i in range(m+1)]
for i in range(n):
  a,b=(int(i) for i in input().split())
  if a<=m:
    s[a].append([a,b])
for i in range(m):
  s[i+1].sort(key=lambda x:x[1])
c=[]
for i in range(m):
  s[i+1].sort()
  if len(s[i+1])!=0:
    c.append(s[i+1].pop())
  if len(c)!=0:
    k=c.pop()
    r+=k[1]
    if len(s[k[0]])!=0:
      c.append(s[k[0]].pop())
print(r)

Submission status: Wrong Answer

Solution code:
n,m=(int(i) for i in input().split())
r=0
s=[[] for i in range(m+1)]
for i in range(n):
  a,b=(int(i) for i in input().split())
  if a<=m:
    s[a].append([a,b])
s.sort()
c=[]
for i in range(m):
  s[i+1].sort()
  if len(s[i+1])!=0:
    c.append(s[i+1].pop())
    c.sort()
  if len(c)!=0:
    k=c.pop()
    r+=k[1]
    if len(s[k[0]])!=0:
      c.append(s[k[0]].pop())
print(r)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
jobs = [0]*n

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

jobs.sort(key = lambda x:(-x[1],-x[0]))

total_reward = 0

days_left = m
for job in jobs:
	day, reward = job 
	if day <= days_left:
		total_reward += reward
	days_left -= 1
	if days_left==0:
		break
print(total_reward)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

n, m = input().split(' ')
N = int(n)
M = int(m)

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

# 報酬がi日後までにもらえるタスクの中(pool)で報酬が最大ものを選んでいく。
# 最大 M-1 回働ける
index = 0
pool = []
rewords = 0
for i in range(M):
    day = i + 1

    while index < N and day >= int(sorted_ab[index][0]):
        pool.append(int(sorted_ab[index][1]))
        index += 1
    # pool の中にある仕事の中から最大の報酬のものを選ぶ
    if pool:
        max_reword = max(pool)
        print(day, max_reword)
        rewords += max_reword
        pool.remove(max_reword)

print(rewords)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

n, m = input().split(' ')
N = int(n)
M = int(m)

sorted_ab = sorted([input().split() for i in range(N)])

# 報酬がi日後までにもらえるタスクの中(pool)で報酬が最大ものを選んでいく。
# 最大 M-1 回働ける
index = 0
pool = []
rewords = 0
for i in range(M):
    day = i + 1

    while index < N and day >= int(sorted_ab[index][0]):
        pool.append(int(sorted_ab[index][1]))
        index += 1
    # pool の中にある仕事の中から最大の報酬のものを選ぶ
    if pool:
        max_reword = max(pool)
        rewords += max_reword
        pool.remove(max_reword)

print(rewords)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

n, m = input().split(' ')
N = int(n)
M = int(m)

sorted_ab = sorted([input().split() for i in range(N)])

# 報酬がi日後までにもらえるタスクの中(pool)で報酬が最大ものを選んでいく。
# 最大 M-1 回働ける
index = 0
pool = []
rewords = 0
for i in range(M):
    day = i + 1

    while index < N and day >= int(sorted_ab[index][0]):
        pool.append(sorted_ab[index])
        index += 1
    # pool の中にある仕事の中から最大の報酬のものを選ぶ
    if pool:
        job = sorted(pool, key=lambda l: l[1], reverse=True)[0]
        rewords += int(job[1])
        pool.remove(job)

print(rewords)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
jobs = [list(map(int, input().split())) for _ in range(N)]
jobs = sorted(jobs, key=lambda x: (x[1], x[0]), reverse=True)

salary = 0
day = 0
flag = False
while True:
    if flag:
        break
    for i, job in enumerate(jobs):
        if job[0] + day < M + 1:
            _ = jobs.pop(i)
            salary += job[1]
            day += 1
            break
        else:
            flag = True
    if len(jobs) == 0 or day > M:
        break
        
print(salary)

Submission status: Wrong Answer

Solution code:
import heapq

# M日後までに得られる報酬
n, m = map(int, input().split())

# A日後に報酬B

task_list = []

for _ in range(n):
    a, b = map(int, input().split())
    task_list.append((a, b))

task_list = sorted(task_list,key=lambda x:x[0])
print(task_list)

j = 0
hq = []
ans = 0

for i in range(1, m+1):
    # 残り1, 2, 3, 4...
    while j < n and task_list[j][0] <= i:
        heapq.heappush(hq, -task_list[j][1])
        j += 1
    if len(hq):
        ans += heapq.heappop(hq)

print(-ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

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

task_list = []

for _ in range(n):
  a, b = map(int, input().split())
  task_list.append((a, b))

task_list = sorted(task_list, key = lambda x: x[0])

hq = []
ans, j = 0, 0

print(task_list)

for i in range(1, m+1):
  while j < n and task_list[j][0] <= i:
    heappush(hq, -task_list[j][1])
    j += 1
  if len(hq):
    ans += -heappop(hq)
  
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
print(t)

Submission status: Wrong Answer

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

for i in range(n):
    a,b = map(int,input().split())
    heapq.heappush(job,(a,b))

job.reverse()

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

print(sum(salary))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

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

jobs = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

ans = 0
heap = []
for day in range(1,M+1):
	for i in jobs:		
		if i[0] <= day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) > 0:
		ans += -heappop(heap)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

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

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


list.sort(key = lambda x: x[0])
print(list)
ans = 0
heap = []
for day in range(1,M+1):
	for i in list:		
		if i[0] == day:
			heappush(heap, -i[1])
		elif i[0] > day:
			break
    
	if len(heap) != 0:
		ans += -heappop(heap)

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
N, M = map(int, input().split())
W = [tuple(map(int, input().split())) for i in range(N)]
W.sort()
print(W)
h = []

j = 0
ans = 0
for i in range(M+1):
    while j < N and W[j][0] < i+1:
        heapq.heappush(h, (-W[j][1], W[j][1]))
        j += 1
    if h:
        p = heapq.heappop(h)
        ans += p[1]

print(ans)

Submission status: Wrong Answer

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

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

    id= id + 1

  if find != None:
    c = c + find[1]
    find[2] = True
    del X[max_i]

print(c)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
W = [tuple(map(int, input().split())) for i in range(N)]
W.sort(key=lambda x: -1000000*x[1]-x[0])

day = 0
ans = 0
for i in range(N):
    if M-day-W[i][0] >= 0:
       ans += W[i][1]
       day += 1
    if day >= M:
        break

print(ans)

Submission status: Wrong Answer

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

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


  if find != None:
    #print(find[1])
    c = c + find[1]
    find[2] = True

print(c)

Submission status: Wrong Answer

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

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


  if find != None:
    print(find[1])
    c = c + find[1]
    find[2] = True

print(c)

Submission status: Wrong Answer

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


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


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

Submission status: Wrong Answer

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

li_sort = sorted(li, key=lambda a: (a[1], a[0]), reverse=True)
ans = 0
while m > 0:
  d = 0
  e = 0
  for b, l in enumerate(li_sort):
    if m >= l[0]:
      d = l[0]
      ans += l[1]
      m -= 1
      li_sort.pop(b)
      e = 1
      break
  if e == 0:
    m = 0
    
print(ans)

Submission status: Wrong Answer

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

N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

List.sort(key=itemgetter(0))
List_S = [0]
add_list = []
 
result = 0
p = 0

for i in range(1, M+1):
    add = 0
    while p < N and List[p][0] == i:
        if List_S[len(List_S)-1] < List[p][0]:            
            List_S.append(List[p][1])
        else:
            add_list.append(List[p][1])
            add += 1
        p += 1
            
    if len(List_S) != 1:
        result += List_S.pop()
        if add > 0:
            List_S.extend(add_list)
            List_S.sort()
 
print(result)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
ab = []
for i 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)
day = 1
i = 0
ans = 0
while i <= n-1 and day <= m:
    if ab[i][0] <= m-day+1:
        ans += ab[i][1]
        day += 1
        i += 1
    else:
        i += 1
print(ans)