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: Time Limit Exceeded

Solution code:
from heapq import *
n, m = map(int, input().split())

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n) ]
# print(ab)
ab.sort(reverse=True)
# print(ab)
import heapq
heap = []
ans = 0
for day in reversed(range(m)):
    for i in range(len(ab)):
        if ab[i][0]==(m-day):
            heapq.heappush(heap,-ab[i][1])
    if len(heap)>0:
        ans += abs(heapq.heappop(heap))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n)]
# print(ab)
ab.sort(reverse=True)
# print(ab)
# print(len(ab))
from heapq import heappush
from heapq import heappop
# from heapq import heapify

heap = [0]*m

ans = 0
for i in reversed(range(m)):
    # print(ab)
    # print("i={}".format(i))
    if i < 0:
        break
    else:
        # print("n={}".format(n))
        for j in range(n):
            if (ab[j][0]+i) > m:
                pass
            else:
                heappush(heap, -(ab[j][1]))
                ab[j][1] = 0
        # print(heap)
    ans += heappop(heap)
    # print(ans)

# print(ans)
print(abs(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
joblist = []
for _ in range(n):
    a, b = map(int, input().split())
    joblist.append([a, b])
joblist.sort()
ans = 0
p = 0
jobable = []
for i in range(1, m+1):
    for j in range(n):
        if joblist:
            if p == n:
                break
            if joblist[p][0] == i:
                jobable.append(joblist[p][1])
                p += 1
            else:
                break
        else:
            break
    if jobable:
        k = max(jobable)
        ans += k
        jobable.remove(k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
joblist = []
for _ in range(n):
    a, b = map(int, input().split())
    joblist.append([a, b])
joblist.sort(reverse=True)
ans = 0
jobable = []
for i in range(1, m+1):
    for j in range(n):
        if joblist:
            if joblist[-1][0] == i:
                jobable.append(joblist[-1][1])
                joblist.pop()
            else:
                break
        else:
            break
    if jobable:
        k = max(jobable)
        ans += k
        jobable.remove(k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = [ list(map(int,input().split())) for i in range(n)]
# print(ab)
ab.sort(reverse=True)
# print(ab)
# print(len(ab))
from heapq import heappush
from heapq import heappop
from heapq import heapify

heap = [0]*m

ans = 0
for i in reversed(range(m)):
    # print(ab)
    # print("i={}".format(i))
    if i < 0:
        break
    else:
        # print("n={}".format(n))
        for j in range(n):
            if (ab[j][0]+i) > m:
                pass
            else:
                heappush(heap, -(ab[j][1]))
                ab[j][1] = 0
        # print(heap)
    ans += heappop(heap)
    # print(ans)

# print(ans)
print(abs(ans))

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort()
pq = []
ans = 0
for i in range(1, M + 1):
    while (len(X) > 0) and (X[0][0] <= i):
        heappush(pq, (-X[0][1]))
        X = X[1:]
    
    if pq:
        ans -= heappop(pq)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
N, M = map(int, input().split())
Data = [list(map(int, input().split())) for _ in range(N)]

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
reward = [0]*N
for i in range(N):
  A,B = map(int,input().split())
  reward[i] = [A,B]
ans = 0
remain_day = 1
for i in range(M):
  max = 0
  reward_max = [j for j in reward if j[0] <= remain_day]
  reward_max = sorted(reward_max,key=lambda x:(x[1]),reverse = True)
  if len(reward_max) > 0:
    ans +=reward_max[0][1]
    reward.remove(reward_max[0])
  reward_max = []
  remain_day += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]
for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(r)

m = 0
li = []
for i in range(M):
    li.extend(jobs[i])
    if len(li) > 0:
        m += max(li)
        li.remove(max(li))
print(m)

Submission status: Time Limit Exceeded

Solution code:
# M日後に最大の値
from heapq import heappush, heappop
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

heap = []
ans = 0
for i in range(1, M+1):
    N = len(Data)

    for j in range(N-1, -1, -1):  #range(N)
        if (Data[j][0] <= i):
            iranai = Data.pop(j)
            heappush(heap, -(iranai[1]))

    if len(heap) != 0:
        ans += -(heappop(heap))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# M日後に最大の値
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

temp = []
ans = 0
for i in range(1, M+1):
    N = len(Data)

    for j in range(N-1, -1, -1):  #range(N)
        if (Data[j][0] <= i):
            iranai = Data.pop(j)
            temp.append(iranai[1])

    if len(temp) != 0:
        ans += max(temp)
        temp.remove(max(temp))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
jobs.reverse()
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
jobs.sort(key = lambda x:(x[1],x[0]))
score = 0
for i in range(b):
  for j in range(len(jobs)):
    job = jobs[len(jobs) - j - 1]
    if job[0] <= i + 1:
      score += job[1]
      jobs.remove(job)
      break;
print(score)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
jobs = []
while True:
    try:
        jobs.append(list(map(int,input().split())))
    except:
        break;
score = 0
for i in range(b):
  max_now = 0
  deli = []
  for j in range(len(jobs)):
    job = jobs[j]
    if job[0] <= i + 1:
      if max_now < job[1]:
        max_now = job[1]
        deli = job
  score += max_now 
  if deli != []:
    jobs.remove(deli)
print(score)

Submission status: Time Limit Exceeded

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

#output
import heapq

#点数配列の用意
point = 0
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] == j + 1:
            heapq.heappush(hq, -B[i])
    if len(hq):
        point += -heapq.heappop(hq)
print(point)

Submission status: Time Limit Exceeded

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

#output
import heapq

#点数配列の用意
point = 0
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] == j + 1:
            heapq.heappush(hq, -B[i])
    if len(hq):
        point += -heapq.heappop(hq)

print(point)

Submission status: Time Limit Exceeded

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

#output
import heapq

#点数配列の用意
point = [0] * M
hq = []
#M-i日目(1 <= i <= M)に働ける仕事の中で、Bが最大のものを選ぶ
for j in range(0, M):
    for i in range(N):
        if A[i] == j + 1:
            heapq.heappush(hq, -B[i])
    if len(hq):
        point[j] = -heapq.heappop(hq)

print(sum(point))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A)

cnt = 0

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

Submission status: Time Limit Exceeded

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

cnt = 0

for day in range(1,M+1):
    B = [x[1] for x in A if x[0]<=day]
    if B:
        ind = B.index(max(B))
        cnt += B[ind]
        A[ind][1] = 0

print(cnt)

Submission status: Time Limit Exceeded

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 day in range(1,self.size+1):
            print("day,",day,self.sum(day))

#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
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)
    used = set()
    #print(works)

    for day in range(1,M+1):
        #print(day)
        BIT.add(day,1)
    ans = 0
    for day, money in works:
        #BIT.show()
        date = M-day+1
        while date in used:
            date-=1
        if date > 0 and BIT.sum(date)>0:
            BIT.add(date, -1)
            used.add(date)
            ans += money

    print(ans)
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

n, m=map(int, input().split())
ab = [["",""] for _ in range(n)]
for i in range(n):
    ab[i]=list(map(int, input().split()))

sec_sort = lambda val: val[1]
ab.sort(key = sec_sort, reverse=True)
#print(ab)

abs = [[] for _ in range(4)]

for i in range(n):
    abs[0].append(i) 
    abs[1].append(ab[i][0]) 
    abs[2].append(ab[i][1]) 
    abs[3].append(0) 

np_abs = np.array(abs)
#print(np_abs)

sum = 0
for dayLeft in range(1,m+1):

    CanWork = (np_abs[1] <= dayLeft) #日数がA以内
    isWorkLeft = (np_abs[3] == 0)
    isCandidate = np.logical_and(CanWork, isWorkLeft)
#    print(isCandidate)

    #候補が1以降ならば
    if np.any(isCandidate == True):
        index = np.min(np_abs[0][isCandidate]) #日数がA以内かつソート昇順最初のindex
#        print(index)
        sum += np_abs[2][index] #indexのBを取得して足しこむ
        np_abs[3][index] = 1 #0→1に

    #候補がなければ次のdayLeftへ
    else:
        continue

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    try:
        an+=max(y)
        y.remove(max(y))
    except:
        pass
print(an)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N,M=map(int,input().split())
x=defaultdict(list)
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(b)
y=[]
an=0
for i in range(M+1):
    y+=x[i]
    y.sort()
    try:
        an+=y.pop()
    except:
        pass
print(an)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n, m=map(int, input().split())
ab = [["" for _ in range(2)] for _ in range(n)]
for i in range(n):
    temp=list(map(int, input().split()))
    ab[i] = [temp[0],temp[1],False]

sortsecond = lambda val: val[1]

ab.sort(key = sortsecond, reverse = True)
#print(ab)

sum = 0
for dayLeft in range(1, m+1):
#    print(str(dayLeft)+"スタート")
    for i in range(n):
        if((ab[i][0] <= dayLeft) and (ab[i][2] == False)):
            sum += ab[i][1]
#            print(str(ab[i][1])+"を追加")
            ab[i][2] = True
#            print(ab)
            break

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# Summer Vacation

n, m = map(int, input().split())
albeits = []
for i in range(n):
    albeits.append(list(map(int, input().split())))

albeits = sorted(albeits)
total = 0

for d in range(1, m+1):
    cand = []
    for i in range(len(albeits)):
        if albeits[i][0] <= d:
            cand.append(albeits[i])
            # print("alb: {}".format(albeits))

    # print("day: {} candidates: {}".format(d, cand))

    if cand:
        cand.sort(key=lambda x: x[1])
        best = cand[-1]
        total += best[1]
        albeits.remove(best)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
import heapq
import numpy as np
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

for _ in range(n):
    a, b = map(int, input().split())
    dic[a].append(b)
#print(dic)

L = []
ans = 0
for i in range(limit+1):
    L += list(np.array(dic[i])*(-1))
    heapq.heapify(L)
    if len(L) >0:
        #print(L)
        ans -= heapq.heappop(L)
        #print(ans)
print(ans)

Submission status: Time Limit Exceeded

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<latest+1, workdays))
    if len(k) == 0:
        continue
    else:
        work_day = max(k)
        workdays.remove(work_day)
        sum += reward

print(sum)

Submission status: Time Limit Exceeded

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 = [0] * (M+1)

for day, reward in work_list:
    latest = M - day
    while -1 < latest:
        if workdays[latest] == 0:
            sum += reward
            workdays[latest] = 1
            break
        else:
            latest -= 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys
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 = [0] * (M+1)

for day, reward in work_list:
    latest = M - day
    while 0 <= latest:
        if workdays[latest] == 0:
            sum += reward
            workdays[latest] = 1
            break
        else:
            latest -= 1

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
n, m = [int(i) for i in raw_input().split()]

jobs = []
for _ in range(n):
    a,b = [int(i) for i in raw_input().split()]
    jobs.append((a,b))


heap = []
output = 0
added = set([])
for i in range(m-1, -1, -1):
    for j in range(len(jobs)):
        job = jobs[j]
        if j not in added and i <= m - job[0]:
            heappush(heap, (-job[1], job[0]))
            added.add(j)

    if len(heap) > 0:
        top = heappop(heap)
        # print top
        output += -top[0]

print output

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, M = map(int, input().split())
AB = [False]*N
for i in range(N):
    A, B = map(int, input().split())
    AB[i] = (A, -B)

AB.sort()
hq = []

ans, ct, idx = 0, 0, 0
for i in range(1, M+1):
    for j in AB[idx:]:
        A, B = j
        if A == i:
            heapq.heappush(hq, B)
            ct += 1
        else:
            idx = ct
            break
    if hq:
        B = heapq.heappop(hq)
        ans -= B
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, M = map(int, input().split())
AB = [False]*N
for i in range(N):
    A, B = map(int, input().split())
    AB[i] = (-B, A)

AB.sort(key=lambda x: x[1])
hq = []

ans, ct, idx = 0, 0, 0
for i in range(1, M+1):
    for j in AB[idx:]:
        if j[1] == i:
            heapq.heappush(hq, j)
            ct += 1
        else:
            idx = ct
            break
    if hq:
        B, A = heapq.heappop(hq)
        ans -= B
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, M = map(int, input().split())
AB = [False]*N
for i in range(N):
    A, B = map(int, input().split())
    AB[i] = (-B, A)

AB.sort(key=lambda x: x[1])
hq = []

ans, ct, idx = 0, 0, 0
for i in range(1, M+1):
    for j in AB[idx:]:
        if j[1] == i:
            heapq.heappush(hq, j)
            ct += 1
        else:
            idx = ct
            break
    while hq:
        B, A = heapq.heappop(hq)
        if A <= i:
            ans -= B
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    m, list_of_a_and_b = read()
    result = think(m, list_of_a_and_b)
    write(result)


def read():
    n, m = read_int(2)
    list_of_a_and_b = []
    for _ in range(n):
        list_of_a_and_b.append(read_int(2))
    return m, list_of_a_and_b


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(m, list_of_a_and_b):
    local_list_of_a_and_b = list(list_of_a_and_b)
    queue = []
    result = 0

    for days_before_deadline in range(1, m + 1):
        candidates = pop_tasks_n_days_before_deadline(local_list_of_a_and_b, days_before_deadline)
        queue.extend(candidates)
        queue.sort(key=lambda x: -x[1])
        if queue:
            task = queue.pop(0)
            result += task[1]

    return result


def pop_tasks_n_days_before_deadline(list_of_a_and_b, days_before_deadline):
    result = []
    index_list = []
    for i, (a, b) in enumerate(list_of_a_and_b):
        if a == days_before_deadline:
            index_list.append(i)
            result.append([a, b])
    index_list.sort(key=lambda x: -x)
    for i in index_list:
        list_of_a_and_b.pop(i)
    return result


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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])]
        index_min = [i for i, x in enumerate(upper) if x[1] == min([i[1] for i in upper])]
        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: Time Limit Exceeded

Solution code:
# import numpy as np

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

# A = np.array(A)

cnt = 0

for day in range(1,M+1):
    B = [x[1] for x in A if x[0]<=day]
    if B:
        ind = B.index(max(B))
        cnt += B[ind]
        del A[ind]
print(cnt)

Submission status: Time Limit Exceeded

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(True)

    money = 0

    for d in range(1, limit+1):
        available_jobs = []

        for j in jobs:
            if j[0] <= d:
                available_jobs.append(j)
        
        if available_jobs:
            available_jobs.sort(key=lambda x: x[1], reverse=True)
            for aj in available_jobs:
                if aj[2]:
                    money += aj[1]
                    aj[2] = False
                    break

    print(money)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A)

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

Submission status: Time Limit Exceeded

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(True)
        j.append(True)

    money = 0

    available_jobs = []

    for d in range(1, limit+1):

        for j in jobs:
            if j[0] <= d and j[3]:
                available_jobs.append(j)
                j[3] = False

        if available_jobs:
            available_jobs.sort(key=lambda x: x[1], reverse=True)
            for aj in available_jobs:
                if aj[2]:
                    money += aj[1]
                    aj[2] = False
                    break

    print(money)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2019/08/11

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import deque
N, M = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
A = deque(A)
B = deque(B)
Q = np.array([])
ans = 0
for m in range(1, M+1):
    while len(A)>0:
        a = A.popleft()
        b = B.popleft()
        if a <= m:
            Q = np.append(Q, b)
        else:
            A.appendleft(a)
            B.appendleft(b)
            break
    if Q.size:
        ans += np.max(Q)
        Q = np.delete(Q, np.argmax(Q))
print(int(ans))

Submission status: Time Limit Exceeded

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

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

print(reward)

Submission status: Time Limit Exceeded

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())

import numpy as np
A = np.array(A)
B = np.array(B)

C = np.array([A, B])
C.sort(1)
C = C[:, ::-1]

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

print(sum(point))

Submission status: Time Limit Exceeded

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())
  if len(c)!=0:
    c.sort(key=lambda x:x[1])
    k=c.pop()
    r+=k[1]
    if len(s[k[0]])!=0:
      c.append(s[k[0]].pop())
print(r)

Submission status: Time Limit Exceeded

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())
      c.sort(key=lambda x:x[1])
print(r)

Submission status: Time Limit Exceeded

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)
        rewords += max_reword
        pool.remove(max_reword)

print(rewords)

Submission status: Time Limit Exceeded

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

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

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

print(earned)

Submission status: Time Limit Exceeded

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

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

print(earned)