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:
N,M=map(int,input().split())
d={}
for i in range(M):d[i]=[0]
for i in range(N):
    a,b=map(int,input().split())
    if 0<=M-a:
        d[M-a].append(b)

t=[]
ans=0
for i in range(M)[::-1]:
    t+=d[i]
    ans+=max(t)
    t.remove(max(t))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,M = (int(a) for a in input().split())
    job = [list(map(int, input().split())) for i in range(N)]
    sum = 0
    for i in range(1,M+1):
        max = 0
        x = -1
        for j in range(N):
            if job[j][0]<=i and max<job[j][1]:
                max = job[j][1]
                x = j
        if x!=-1:
            sum += max
            job[x][1] = 0
            del(job[x:x+1])
            N -= 1
    print(sum)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(a) for a in input().split())
job = [list(map(int, input().split())) for i in range(N)]
sum = 0
for i in range(1,M+1):
    max = 0
    x = -1
    for j in range(N):
        if job[j][0]<=i and max<job[j][1]:
            max = job[j][1]
            x = j
    if x!=-1:
        sum += max
        job[x][1] = 0
        del(job[x:x+1])
        N -= 1
print(sum)

Submission status: Time Limit Exceeded

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:
		ccc = 0
		if i[0] == day:
			heappush(heap, -i[1])
			ccc += 1
		elif i[0] > day:
			del(jobs[0:ccc])
			break
    
	if len(heap) > 0:
		ans += -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)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      if list1 != []:
        p = max(list1, key = lambda x:x[1])
        income += p[1]
        list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    if list1 != []:
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      
print(income)

Submission status: Time Limit Exceeded

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

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

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

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

jobs.sort(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: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:x[1], reverse = True)
income = 0
day = 1 #残り日数
i = 0

while day <= m:
  if ab[i][0] <= day:
    income += ab[i][1]
    ab.pop(i)
    day += 1
    i = 0
  else:
    i += 1
  if i >= len(ab):
    day += 1
    i = 0
  #print(day,i,income)
  
print(income)

Submission status: Time Limit Exceeded

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

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

Solution code:
from heapq import heappush, heappop

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

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


list.sort(key = lambda x: x[0])

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

Solution code:
from heapq import heappush, heappop

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

list.sort()

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

Solution code:
import heapq
job = list()
salary = list()
n,m = map(int,input().split())
k = -1
def h_sort(list):
    h = []
    for v in list:
        heapq.heappush(h, v)
    return [heapq.heappop(h) for i in range(len(h))]

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

job = h_sort(job)
job.reverse()


for x in job:
    s,t = x
    if k == -1 or k > t:
        k = t
    salary.append(t)

    if s - m > 0:
        if salary[0] > k:
            salary = h_sort(salary)
            k = -1
        del salary[0]
    else:
        m -= 1

print(sum(salary))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
job = [list() for _ in range(m)]
total = 0
l = list()
for _ in range(n):
    a,b = map(int,input().split())
    if a <= m :
        job[a-1].append(b)
for i in range(m):
    l += job[i]
    if l != []:
        l.sort(reverse = True)
        total += l.pop(0)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

l = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    if tmp[0] <= M:
        l.append(tmp)

l.sort()
ans = 0
a = []
for i in range(1, M+1):
    for j in l:
        if j[0] == i:
            heapq.heappush(a, -j[1])
        elif j[0] > i:
            break
    if len(a) != 0:
        ans -= heapq.heappop(a)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l=[]
for i in range(N):
  a=list(map(int,input().split()))
  l.append(a)
l.sort(key=lambda x: x[0])
#print(l)
p=[]
ans=0
for j in range(1,M+1):
  if len(l)!=0:
    while l[0][0]<=j:
      a=l.pop(0)
      p.append(a[1])
      if len(l)==0: break
  if len(p)!=0:
    b=max(p)
    p.remove(b)
    ans+=b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve(n, m, work_list):
    # 1-origin
    dp = [[0] * (m + 1) for i in range(n + 1)]

    # time O(N log(N))
    work_list.sort()

    # time O(NM)
    for key, value in enumerate(work_list, 1):
        work_day, work_value = value[0], value[1]
        prev_key = key - 1
        for day in range(1, m + 1):
            prev_day = day - 1
            dp[key][day] = dp[prev_key][day]
            if day >= work_day:
                dp[key][day] = max(dp[key][day], dp[prev_key][prev_day] + work_value)

    return dp[n][m]


def main():
    n, m = map(int, input().split())

    work_list = []
    # time O(N)
    for i in range(n):
        work = list(map(int, input().split()))
        if work[0] > m:
            continue
        work_list.append(work)

    ans = solve(n, m, work_list)
    print(ans)


main()

Submission status: Time Limit Exceeded

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 = []
 
result = 0
p = 0

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

Submission status: Time Limit Exceeded

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 = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    add = 0
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
        else:
            break
        add = 1
    if len(List_S) != 0:
        if add == 1:
            List_S.sort()
        result += List_S.pop()
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    add = 0
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
        else:
            break
        add = 1
    if len(List_S) != 0:
        if add == 1:
            List_S.sort()
        result += List_S.pop()
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    add = 0
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
            add = 1
        else:
            break
    if len(List_S) != 0:
        if add == 1:
            List_S.sort()
        result += List_S.pop()
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    add = 0
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
            add = 1
        else:
            break
    if len(List_S) != 0:
        if add == 1:
            List_S.sort()
        result += List_S[len(List_S)-1]
        List_S.pop()
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    add = 0
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
            add = 1
        else:
            break
    if len(List_S) != 0:
        if add == 1:
            List_S.sort(reverse = True)
        result += List_S[0]
        del List_S[0]
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    for j in range(p,N):
        if List[j][0] <= i:
            List_S.append(List[j][1])
            p += 1
        else:
            break
    if len(List_S) != 0:
        List_S.sort(reverse = True)
        result += List_S[0]
        del List_S[0]
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    for j in range(p,N):
        A = List[j][0]
        B = List[j][1]
        if A <= i:
            List_S.append(B)
            p += 1
        else:
            break
    if len(List_S) != 0:
        max_index = List_S.index(max(List_S))
        result += List_S[max_index]
        del List_S[max_index]
 
print(result)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

ans = 0
a = []
for i in range(1, M+1):
    for j in list:
      if j[0] == i:
        heapq.heappush(a, -j[1])       
    if len(a) != 0:
        ans += heapq.heappop(a)*(-1)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
l2 = []
for i in range(1, M+1):
    tmp = [j[1] for j in list if j[0] == i]
    l2.extend(tmp)
    l2.sort(reverse=True)
    if len(l2) != 0:
        ans += l2.pop(0)

print(ans)

Submission status: Time Limit Exceeded

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

cands_list = [[] for _ in range(M)]
for _ in range(N):
    [A, B] = map(int, input().split())
    if A - 1 < M:
        cands_list[A - 1].append(B)

reward = 0
cands = []
for i in range(M):
    cands.extend(cands_list[i])
    if len(cands) > 0:
        best = max(cands)
        reward += best
        cands.remove(best)

print(reward)

Submission status: Time Limit Exceeded

Solution code:
from itertools import groupby

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

cands_list = [[] for _ in range(M)]
for [A, B] in ABs:
    if A - 1 < M:
        cands_list[A - 1].append(B)

reward = 0
cands = []
for i in range(M):
    cands.extend(cands_list[i])
    if len(cands) > 0:
        best = max(cands)
        reward += best
        cands.remove(best)

print(reward)

Submission status: Time Limit Exceeded

Solution code:
job = list()
salary = list()
n,m = map(int,input().split())
k = -1

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

job.sort(reverse = True)

for x in job:
    s,t = x
    if k == -1 or k > t:
         k = t
    salary.append(t)

    if s - m > 0:
        if salary[0] > k:
              salary.sort()
              k = -1
        del salary[0]
    else:
        m -= 1

print(sum(salary))

Submission status: Time Limit Exceeded

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

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

job.sort(reverse = True)

for x in job:
    s,t = x
    salary.append(t)

    if s - m > 0:
        salary.sort()
        salary.pop(0)
    else:
        m -= 1

print(sum(salary))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(a) for a in input().split())
job = [list(map(int, input().split())) for i in range(N)]
sum = 0
for i in range(1,M+1):
    max = 0
    x = -1
    for j in range(N):
        if job[j][0]<=i and max<job[j][1]:
            max = job[j][1]
            x = j
    if x!=-1:
        sum += max
        job[x][1] = 0
        del(job[x:x+1])
        N -= 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(a) for a in input().split())
job = [list(map(int, input().split())) for i in range(N)]
sum = 0
for i in range(1,M+1):
    max = 0
    x = -1
    for j in range(N):
        if job[j][0]<=i and max<job[j][1]:
            max = job[j][1]
            x = j
    if x!=-1:
        sum += max
        job[x][1] = 0
print(sum)

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
l = []
for _ in range(n):
	a,b = map(int, input().split())
	l.append((a,b))
l = sorted(l, key = lambda x: -x[1])
ans = 0
for i in range(1, m + 1):
	k = [x for x in l if x[0] <= i]
	if k:
		x = k[0]
		ans += x[1]
		l.remove(x)
	else:
		continue
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)]
earn = 0
AB.sort(key=lambda x:x[1], reverse=True)
for day in reversed(range(M)):
    for i, ab in enumerate(AB):
        if ab[0] + day <= M:
            earn += ab[1]
            del AB[i]
            break
print(earn)

Submission status: Time Limit Exceeded

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

earn = 0
for day in reversed(range(M)):
    maxearn = -1
    maxindex = -1
    for i, ab in enumerate(AB):
        if ab[0] + day <= M:
            if ab[1] > maxearn:
                maxearn = ab[1]
                maxindex = i
    if maxindex == -1:
        continue
    earn += maxearn
    del AB[maxindex]

print(earn)

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A > M:
            continue
        if A in jobs.keys():
            jobs[A] = jobs[A] + [-B]
        else:
            jobs[A] = [-B]

    profit = 0
    days = jobs.keys()
    potential_jobs = []
    
    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in days:
            for job in jobs[elappsed_day]:
                heappush(potential_jobs, job)
        if len(potential_jobs) > 0:
            profit += heappop(potential_jobs)
            
    print(-profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A > M:
            continue
        if A in jobs.keys():
            jobs[A] = jobs[A] + [B]
        else:
            jobs[A] = [B]

    profit = 0
    days = jobs.keys()
    potential_jobs = []

    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in days:
            potential_jobs += jobs[elappsed_day]
        if len(potential_jobs) > 0:
            profit += potential_jobs.pop(potential_jobs.index(max(potential_jobs)))
            
    print(profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(n):
    a,b= map(int,input().split())
    job[i] = a,b
    salary[i] = b
job.sort(reverse = True)
max = max(salary)
salary = [max+1 for _ in range(n)]

for j in range(n):
    s,t = job[j]
    salary[j] = t

    if s - m > 0:
        salary[salary.index(min(salary))] = max+1
    else:
        m -= 1
for k in range(n):
    if salary[k] == max+1:
        salary[k] = 0
print(sum(salary))

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A in jobs.keys():
            jobs[A] = jobs[A] + [B]
        else:
            jobs[A] = [B]

    profit = 0
    days = jobs.keys()
    potential_jobs = []

    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in days:
            potential_jobs += jobs[elappsed_day]
        if len(potential_jobs) > 0:
            profit += potential_jobs.pop(potential_jobs.index(max(potential_jobs)))
            
    print(profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A in jobs.keys():
            jobs[A] = jobs[A] + [B]
        else:
            jobs[A] = [B]

    profit = 0
    potential_jobs = []

    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in jobs.keys():
            potential_jobs += jobs.pop(elappsed_day)
        if len(potential_jobs) > 0:
            profit += potential_jobs.pop(potential_jobs.index(max(potential_jobs)))
            
    print(profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A in jobs.keys():
            jobs[A] = jobs[A] + [B]
        else:
            jobs[A] = [B]

    profit = 0
    potential_jobs = []

    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in jobs.keys():
            potential_jobs += jobs[elappsed_day]
        if len(potential_jobs) > 0:
            profit += potential_jobs.pop(potential_jobs.index(max(potential_jobs)))
            
    print(profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, M = map(int, input().split())
    jobs = {}
    for _ in range(N):
        A, B = map(int, input().split())
        if A in jobs.keys():
            jobs[A] = jobs[A] + [B]
        else:
            jobs[A] = [B]

    profit = 0
    potential_jobs = []

    # M-1日後から今日まで遡る
    for elappsed_day in range(1, M+1):
        if elappsed_day in jobs.keys():
            potential_jobs += jobs[elappsed_day]
        if len(potential_jobs) > 0:
            profit += max(potential_jobs)
            potential_jobs.remove(max(potential_jobs))
            
    print(profit)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[1], reverse=True)
List_M = "B" + "A" * M

result = 0

for i in range(N):
    A = List[i][0]
    B = List[i][1]
    p = List_M[A:].find("A")
    if p != -1:
        List_M = List_M[:A+p] + "B" + List_M[A+p+1:]
        result += B

print(result)

Submission status: Time Limit Exceeded

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

for k1 in range(N):
    a, b = map (int, input().split())
    list.append([a,b])
list.sort(key=lambda x: x[0], reverse = True)
list.sort(key=lambda x: x[1], reverse = True)
#print(list)
#print('then')

earn = 0
for day in range (1, M+1):
    for k, v in enumerate(list):
        #print(day)
        if v[0] <= day:
            earn += v[1]
            del list[k]
            #print (list)
            break

print(earn)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[1], reverse=True)
List_M = [0]*(M+1)
result = 0

for i in range(N):
    p = 0
    A = List[i][0]
    B = List[i][1]
    while (A+p) < (M+1):
        if List_M[A+p] == 0:
            List_M[A+p] = B
            result += B
            break
        else:
            p += 1
    
print(result)

Submission status: Time Limit Exceeded

Solution code:
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=lambda x: x[1], reverse=True)
List_M = [0]*(M+1)

for i in range(N):
    p = 0
    A = List[i][0]
    B = List[i][1]
    while p < M:
        if (A+p) > M:
            break
        elif List_M[A+p] == 0:
            List_M[A+p] = B
            break
        else:
            p += 1
result = 0
for i in range(M+1):
    result += List_M[i]
    
print(result)

Submission status: Time Limit Exceeded

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

X = []

i = 0
while i < N:
    X.append(list(map(int, input().split())))
    i += 1

X = np.asarray(X)

X_ind = np.argsort(X[:,0], axis=0)
X = X[X_ind]
# print(X)
least = 1
p = 0
while least <= M:
    # print(least)
    best_index = -1
    best_s = 0
    for i in range(X.shape[0]):
        target = X[i]
        if least >= target[0] and best_s <= target[1]:
            best_index = i
            best_s = target[1]
        elif least < target[0]:
            break
    # print(target)
    p += best_s
    if best_index >= 0:
        X = np.delete(X, best_index, axis=0)
    least += 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
from heapq import *
from collections import defaultdict

n, m = map(int, input().split())
jobs = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    jobs[a].append(-b)

result = 0
pool = []
for i in range(1, m+1):
    pool += jobs[i]
    heapify(pool)
    if 0 < len(pool):
        result += -heappop(pool)

print(result)

Submission status: Time Limit Exceeded

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

X = []

i = 0
while i < N:
    X.append(list(map(int, input().split())))
    i += 1

X = np.asarray(X)

X_ind = np.argsort(X[:,1], axis=0)
X = X[X_ind]
# print(X)
least = 1
p = 0
while least <= M:
    # print(least)
    best_index = -1
    best_s = 0
    for i in range(X.shape[0]):
        target = X[i]
        if least >= target[0] and best_s <= target[1]:
            best_index = i
            best_s = target[1]
    # print(target)
    p += best_s
    if best_index >= 0:
        X = np.delete(X, best_index, axis=0)
    least += 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
jobs = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    jobs[a].append(b)

result = 0
pool = []
for i in range(1, m+1):
    pool += jobs[i]
    pool = sorted(pool)
    if 0 < len(pool):
        result += pool.pop()

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools as ite
n, m = map(int, input().split())
L = [list(map(int,input().split())) for i in range(n)]
L2= ite.permutations(L, n)
max_money = 0
for ele in L2:
    d = 0
    money = 0
    for ele2 in ele:
        if ele2[0]+d <=m:
            money +=ele2[1]
        d+=1
    if max_money < money:
        max_money = money
print(max_money)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
works = []
for _ in range(n):
  a, b = map(int, input().split())
  if a <= m:
    works.append([a, b])
works.sort(key=lambda x:x[0])

def insert(base, add):
  if len(add) == 0:
    return base
  add.sort()
  result = []
  i = 0
  for x in base:
    while i < len(add) and add[i] <= x:
      result.append(add[i])
      i += 1
    result.append(x)
  if i < len(add):
    result.extend(add[i:])
  return result

ar = 0
salary = 0
cand = []
for day in range(1, m+1):
  al = ar
  while ar < len(works) and works[ar][0] <= day:
    ar += 1
  cand = insert(cand, [b for (a, b) in works[al:ar]])
#  print('day:', day, al, ar)
#  print(' ', cand)
  if len(cand) == 0:
    continue
  salary += cand[-1]
  cand.pop()
print(salary)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify, heappop, heappush

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

lst = [list(map(int, input().split())) for s in range(N)]
lst = sorted(lst, key=lambda x: (x[0], -x[1]))

heap = []
heapify(heap)
r = 0
for i in range(1, M + 1):
    # i日後
    while lst and lst[0][0] <= i:
        v = lst.pop(0)[1]
        heappush(heap, -v)

    if len(heap) != 0:
        r += heappop(heap) * (-1)

print(r)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        days, reward = map(int, input().split())
        jobs.append([reward, days])

    jobs = sorted(jobs, reverse=True)
    res = 0
    # 残りi日の時点でどの仕事をするか
    for i in range(m+1):
        for j in jobs:
            if j[1] <= i:
                res += j[0]
                j[1] = 100001
                break

    print(res)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, m = map(int, input().split())
    jobs = []
    for i in range(n):
        days, reward = map(int, input().split())
        jobs.append((days, reward))

    jobs = sorted(jobs, key=lambda item: item[1], reverse=True)
    res = 0
    # 残りi日の時点でどの仕事をするか
    for i in range(m+1):
        for j in jobs:
            if j[0] <= i:
                res += j[1]
                jobs.remove(j)
                break

    print(res)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
works = []
for _ in range(n):
  a, b = map(int, input().split())
  if a <= m:
    works.append([a, b])
works.sort(key=lambda x:x[0])

alim = 0
salary = 0
for day in range(1, m+1):
  while alim < len(works) and works[alim][0] <= day:
    alim += 1
  #print('day:', day, alim)
  if alim == 0:
    continue
  ix = works[:alim].index(max(works[:alim], key=lambda x: x[1]))
  #print('max:', ix, max(works[:alim]))
  salary += works[ix][1]
  works[ix][1] = 0
print(salary)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N, M = map(int, input().split())
jobs = []
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs.append([day, value])
jobs = sorted(jobs, lambda x: x[0])

ans = 0
hq = []
job_i = 0
for day in range(1, M+1):
    for job in list(jobs[job_i:]):
        if day < job[0]:
            break

        heapq.heappush(hq, - job[1])
        job_i += 1
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

ans = 0
hq = []
for day in range(1, M+1):
    for job in list(jobs):
        if day == job[0]:
            heapq.heappush(hq, - job[1])
            jobs.remove(job)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

ans = 0
hq = []
for day in range(1, M+1):
    for job in jobs:
        if day == job[0]:
            heapq.heappush(hq, - job[1])
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)