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())
from collections import defaultdict
AB = [[0,0]]*N
for n in range(N):
    temp = list(map(int,input().split()))
    if temp[0] <= M:
        AB[n] = temp
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
hist = defaultdict(int)
for work in sorted_AB:
    hist[work[0]] = work[0]-1
    while True:
        if hist[work[0]] >= M:
            break
        elif work_schedule[hist[work[0]]] == 0:
            work_schedule[hist[work[0]]]  = work[1]
            break
        elif  work_schedule[hist[work[0]]] != 0:
            hist[work[0]] += 1
print(sum(work_schedule))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    temp = list(map(int,input().split()))
    if temp[0] <= M:
        AB[n] = temp
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
for work in sorted_AB:
    cnt = 0
    while True:
        if work[0]-1+cnt >= M:
            break
        elif work_schedule[work[0]-1+cnt] == 0:
            work_schedule[work[0]-1+cnt]  = work[1]
            break
        elif  work_schedule[work[0]-1+cnt] != 0:
            cnt+=1
print(sum(work_schedule))

Submission status: Time Limit Exceeded

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

N, M = map(int, input().split())
Wlist = []
for i in range(N):
    A, B = map(int, input().split())
    Wlist.append([A,B])
Wlist.sort(key=lambda x:x[0])

Ans = 0
for day in range(1,M+1):
    Best = 0
    BestIdx = -1
    for i, W in enumerate(Wlist):
        if W[0] > day:
            break
        if Best < W[1]:
            Best = W[1]
            BestIdx = i
    if BestIdx >= 0:
        Ans += Best
        Wlist[BestIdx][1] = 0
            
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
AB = [[0,0]]*N
for n in range(N):
    AB[n] = list(map(int,input().split()))
work_schedule = [0]*M
sorted_AB = sorted(AB,key=lambda x:(-x[1],x[0]))
for work in sorted_AB:
    cnt = 0
    while True:
        if work[0]-1+cnt >= M:
            break
        elif work_schedule[work[0]-1+cnt] == 0:
            work_schedule[work[0]-1+cnt]  = work[1]
            break
        elif  work_schedule[work[0]-1+cnt] != 0:
            cnt+=1
print(sum(work_schedule))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import heapq
N,M = map(int, input().split())
works_array = np.array([tuple(map(int, input().split())) for k in range(N)])
rewards = []
reward_sum = 0
heapq.heapify(rewards)
for k in range(M+1):
    indices = np.where(works_array[:,0]==k)[0]
    if indices.shape[0] != 0:
        for index in indices:
            heapq.heappush(rewards, -works_array[index, 1])
    if len(rewards) != 0:
        reward_sum += - heapq.heappop(rewards)
print(reward_sum)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
reward = 0
for i in reversed(range(m)):
    mx = 0
    flag = 0
    for j in range(n):
        if ab[j][0] > m-i: break
        if ab[j][1] > ab[mx][1] or not flag:
            mx = j
            flag = 1
    if ab[mx][1] > 0 and flag:
        reward += ab[mx][1]
        ab[mx][1] = 0
print(reward)

Submission status: Time Limit Exceeded

Solution code:
import heapq
#listから複数index削除するやつ
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

[N,M]=[int(x) for x in input().split()]
work=[[int(x) for x in input().split()] for _ in range(N)]

work.sort() #日付の短い順にsortしておく　これいる？いる！！！！
tank=[] #候補を入れる
res=0 #回答
indexlist=[] #バイトは重複不可なので決定済の労働をindexで管理

for i in range(M+1): #日付を後ろから見ていく
  for n,item in enumerate(work): #（日付的に働けるかをみて）候補たりうるものを探しheapqに突っ込む
    if item[0]<=i:
      heapq.heappush(tank,-item[1])
      indexlist.append(n)
      
    work=dellist(work,indexlist)
    indexlist=[]
    
  #print("tank1:",tank)
  
  if len(tank)==0: #候補がなければ次の日へ
    #print("continue.")
    continue

  else: #候補があればもっとも良いのを回答に足す
    res -= heapq.heappop(tank)
    #print("res=",res)
    
  #print("tank2:",tank)
    
print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int, input().split())
works_array = np.array([tuple(map(int, input().split())) for k in range(N)])
reward = 0
for k in range(M+1):
    workable_indices = np.where(works_array[:,0] <= k)[0]
    if workable_indices.shape[0] == 0:
        continue
    else:
        max_index = np.argmax(works_array[workable_indices, 1])
        reward += works_array[workable_indices[max_index], 1]
        works_array = np.delete(works_array, workable_indices[max_index], axis=0)
print(reward)

Submission status: Time Limit Exceeded

Solution code:
import heapq
[N,M]=[int(x) for x in input().split()]
work=[[int(x) for x in input().split()] for _ in range(N)]
work.sort() #日付の短い順にsortしておく　これいる？

tank=[] #候補を入れる
res=0 #回答
indexlist=[] #バイトは重複不可なので決定済の労働をindexで管理

for i in range(M+1): #日付を後ろから見ていく
  
  for n,item in enumerate(work): #（日付的に働けるかをみて）候補たりうるものを探しheapqに突っ込む
    if item[0]<=i and n not in indexlist:
      heapq.heappush(tank,-item[1])
      indexlist.append(n)
  #print("tank1:",tank)
  
  if len(tank)==0: #候補がなければ次の日へ
    #print("continue.")
    continue

  else: #候補があればもっとも良いのを回答に足す
    res -= heapq.heappop(tank)
    #print("res=",res)
    
  #print("tank2:",tank)
    
print(res)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[0],-x[1]])+[[float('inf'),0]]
for i in range(n):l[i][0]-=1
w=[n]*m
for i in range(m):
    j=0
    while l[j][0]<=i:
        if l[j][1]>l[w[i]][1] and j not in w:
            w[i]=j
        j+=1
print(sum(l[w[i]][1] for i in range(m)))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
d = dict()
for _ in range(n):
    a, b = map(int, input().split())
    d.setdefault(a, [])
    d[a].append(b)

l = []
ans = 0
for i in range(1, m + 1):
    if i in d:
        l += d[i]
        l.sort()
    if len(l) > 0:
        m = l.pop()
        ans += m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, m = map(int, input().split())
ab_list = [list(map(int, input().split())) for _ in range(n)]
ab_list.sort(key=lambda i: (i[0]))

l = []
ans = 0
d = {key: list(val) for key, val in itertools.groupby(ab_list, key=lambda i: i[0])}
for i in range(1, m + 1):
    if i in d:
        l += [b for _, b in d[i]]
        l.sort()
    if len(l) > 0:
        m = l.pop()
        ans += m
print(ans)

Submission status: Time Limit Exceeded

Solution code:

class Job(object):
    def __init__(self, day, reward):
        self.day = day
        self.reward = reward
        self.is_used = False


class MyJobs(object):
    def __init__(self, num_elements_in_array):
        self.heapm = {}

    def append(self, priority, value):
        if not priority in self.heapm.keys():
            self.heapm[priority] = []
        self.heapm[priority].append(value)

    def get_best(self, priority):
        day = -1
        reward = -1

        for i in range(priority + 1):
            if not (i in self.heapm.keys()):
                continue
            for j in range(len(self.heapm[i])):
                if self.heapm[i][j].is_used:
                    continue
                cur = self.heapm[i][j].reward
                if not (0 > day):
                    best = self.heapm[day][reward].reward
                if (0 > day) or (cur > best):
                    day = i
                    reward = j
        if (0 > day):
            return 0
        self.heapm[day][reward].is_used = True
        return self.heapm[day][reward].reward


(n, m) = map(int, input().split())
jobs = MyJobs(m)
for _ in range(n):
    (a, b) = map(int, input().split())
    jobs.append(a - 1, Job(a - 1, b))

sum = 0
for i in range(m):
    sum += jobs.get_best(i)
print(sum)

Submission status: Time Limit Exceeded

Solution code:

class Job(object):
    def __init__(self, day, reward):
        self.day = day
        self.reward = reward
        self.is_used = False


class MyJobs(object):
    def __init__(self, num_elements_in_array):
        self.heap = [[] for _ in range(100000)]

    def append(self, priority, value):
        self.heap[priority].append(value)

    def get_best(self, priority):
        day = -1
        reward = -1
        for i in range(priority + 1):
            for j in range(len(self.heap[i])):
                if self.heap[i][j].is_used:
                    continue
                cur = self.heap[i][j].reward
                if not (0 > day):
                    best = self.heap[day][reward].reward
                if (0 > day) or (cur > best):
                    day = i
                    reward = j
        if (0 > day):
            return 0
        self.heap[day][reward].is_used = True
        return self.heap[day][reward].reward


(n, m) = map(int, input().split())
jobs = MyJobs(m)
for _ in range(n):
    (a, b) = map(int, input().split())
    jobs.append(a - 1, Job(a - 1, b))

sum = 0
for i in range(m):
    sum += jobs.get_best(i)
print(sum)

Submission status: Time Limit Exceeded

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

n,m=map(int,input().split())
l=[[0,0] for _ in range(n)]
for i in range(n):
        l[i][1],l[i][0]=map(int,input().split())
l.sort()
l=l[::-1]
ans=0
for k in range(1,m+1):
        for j in range(n):
                if l[j][1]<=k:
                        ans+=l[j][0]
                        l[j][0]=0
                        l.sort()
                        l=l[::-1]
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq


class Work(object):
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.is_used = False


(n, m) = map(int, input().split())
works = []
for _ in range(n):
    (a, b) = map(int, input().split())
    works.append(Work(a, b))
sorted_works = sorted(works, key=lambda x: x.a)

sum = 0
for i in range(1, m + 1):
    options = []
    for j, work in enumerate(sorted_works):
        if work.a > i:
            break
        if work.is_used:
            continue
        heapq.heappush(options, (-work.b, j))
    if 0 == len(options):
        continue
    target = heapq.heappop(options)
    sum += -1 * target[0]
    sorted_works[target[1]].is_used = True
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(v) for v in input().split(' ')]
AB = []
for _ in range(N):
    a, b = [int(v) for v in input().split(' ')]
    AB.append((a, b))
AB = sorted(AB, reverse=True)

dp = []
for i in range(M+1):
    t = []
    for j in range(N):
        t.append(0)
    dp.append(t)

for i, ab in enumerate(AB):
    if ab[0] <= M:
        dp[0][i] = ab[1]
    else:
        dp[0][i] = 0

d = {
    i: [i]
    for i in range(N)
}

for i in range(M):
    for j in range(N):
        max_ = 0
        for k, ab in enumerate(AB):
            if k not in d[j] and ab[0] + i + 1 <= M and ab[1] > max_:
                max_ = ab[1]
                d[j].append(k)
        dp[i+1][j] = dp[i][j] + max_

print(max(dp[M]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[0],-x[1]])+[[float('inf'),float('inf')]]
for i in range(n):l[i][0]-=1
w=[0]*m
for i in range(m):
    j=0
    k=-1
    while l[j][0]<=i:
        if l[j][1]>w[i]:
            w[i]=l[j][1]
            k=j
        j+=1
    if k>=0:del l[k]
print(sum(w))

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

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

hq = []
ans = 0
index = 0
for i in reversed(range(M)):
    for j in range(index, N):
        if jobs[j][0] < M - i:
            break
        if jobs[j][0] == M - i:
            heapq.heappush(hq, -jobs[j][1])
            index += 1

    if len(hq):
        ans += heapq.heappop(hq) * (-1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

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

hq = []
ans = 0
for i in reversed(range(M)):
    for x in jobs:
        if x[0] == M - i:
            heapq.heappush(hq, -x[1])
    if len(hq):
        ans += heapq.heappop(hq) * (-1)

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

ans = 0
for i in range(1, M+1):
    temp = 0
    index = -1
    for j in range(len(Data)):
        if (Data[j][0] <= i) and (temp < Data[j][1]):
            temp = Data[j][1]
            index = j
    if index != -1:
        ans += temp
        Data[index][1] = -1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)
# print(jobs)
days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    max_money = money_list.pop(money_list.index(max(money_list)))
    days.append(max_money)
    if max_money == 0:
        money_list.append(0)
print(sum(days))

Submission status: Time Limit Exceeded

Solution code:
N, M= map(int, input().split())
B=[]
for i in range(N):
    B.append([None]*2)
    l=input().split()
    B[i][0]=int(l[1])
    B[i][1]=int(l[0])
B.sort(reverse=True)
h=[False]*(M+1)
a=0
d=M+1
for i in range(N):
    if d>B[i][1]:
      for j in range(B[i][1],d):
        if h[j]==False:
            h[j]=True
            a+=B[i][0]
            break
      else:
        d=B[i][1]
print(a)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

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

abl = []


def main():
    for i in range(n):
        abl.append(tuple(map(int, input().split())))

    abl.sort()

    ans = 0
    q = []

    for i in range(1, m+1):
        for j, ab in enumerate(abl):
            if ab[0] == i:
                heappush(q, -ab[1])
        if q:
            ans += -heappop(q)

    return ans


print(main())

Submission status: Time Limit Exceeded

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

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [b]
    else:
        jobs[a].append(b)

# print(jobs)

days = []
money_list = [0]
for i in range(1, m+1):
    # print('days', days)
    if i in jobs.keys():
        money_list.extend(jobs[i])
    # print(money_list)
    days.append(max(money_list))
    if max(money_list) != 0:
        money_list.remove(max(money_list))

print(sum(days))

Submission status: Time Limit Exceeded

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

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

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

days = [0 for i in range(m)]
for i in range(n):
    # print(jobs_sorted[i])
    after = jobs_sorted[i][0]
    money = jobs_sorted[i][1]
    if after <= m:
        for j in range(m - after, -1, -1):
            if days[j] < money:
                days.insert(j + 1, money)
                del days[0]
                break
    # print(days)

print(sum(days))

Submission status: Time Limit Exceeded

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

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

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

days = [0 for i in range(m)]
for i in range(n):
    # print(jobs_sorted[i])
    if jobs_sorted[i][0] <= m:
        for j in range(m - jobs_sorted[i][0], -1, -1):
            if days[j] < jobs_sorted[i][1]:
                days.insert(j + 1, jobs_sorted[i][1])
                del days[0]
                break
    # print(days)

print(sum(days))

Submission status: Time Limit Exceeded

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

abl = []


def main():
    for i in range(n):
        abl.append(tuple(map(int, input().split())))

    abl.sort()

    ans = 0

    for i in range(1, m+1):
        bm, mi = -1, -1

        for j, ab in enumerate(abl):
            if ab[0] > i:
                break
            if ab[1] > bm:
                bm = ab[1]
                mi = j

        if bm >= 0 and mi >= 0:
            ans += bm
            del abl[mi]

    return ans


print(main())

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A = [[] for i in range(M)]
for _ in range(N):
    a,b = map(int,input().split())
    if a<=M: A[M-a].append(b)
B = []
for m in range(M):
    B = B+A[m]
    B.sort(reverse=True)
    B = B[:m+1]
print(sum(B))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque
import numpy as np

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
max_work = np.array([])
while day <= M:
    w = 0
    tmp = 0
    max_work = max_work.tolist()
    if len(work[day]) > 0:
        max_work.append(work[day][0])
    else:
        max_work.append(-1)
    max_work = np.asarray(max_work)
    a = np.argmax(max_work) + 1
    if max_work[a - 1] > 0:
        ans += max_work[a - 1]
        work[a].popleft()
        if len(work[a]) > 0:
            max_work[a - 1] = work[a][0]
        else:
            max_work[a - 1] = -1
    day += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
    
import heapq
ans=0
h=[]
for d in range(m-1, -1, -1):
    for v in ab:
        if v[0]<=m-d:
            heapq.heappush(h, v[1]*(-1)) 
    ab=[v for v in ab if v[0]>m-d]
    try:
        ans-=heapq.heappop(h)
    except IndexError:
        ans+=0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
while day <= M:
    w = 0
    tmp = 0
    for d in range(1, day + 1):
        if len(work[d]) > 0 and work[d][0] > w:
            w = work[d][0]
            tmp = d
    if tmp > 0:
        work[tmp].popleft()
    ans += w
    day += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import queue
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        q.append(-l[cnt][1])
        q.sort()
        cnt += 1
    
    if len(q) != 0:
        ans +=-q.pop(0)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]
# 必要な日数の照準にソートする
jobs.sort()
# 次に選ぶバイト候補の保存場所
money = []
ans = 0

# より制約の強い、最終リミットに近い日に行うバイトの割当てから攻めていく
for limit in range(1, m + 1):
    for a, b in jobs:
        # limit日までに報酬のもらえるアルバイトを抽出
        if a == limit:
            # 次に選ぶバイト候補に追加
            heapq.heappush(money, -b)
        elif a > limit:
            break
    # 要素数が空の場合のエラー処理
    if money != []:
        ans += heapq.heappop(money) * (-1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ans=0
for d in range(m-1, -1, -1):
    candidate=[i for i in ab if i[0]<=(m-d)]
    if candidate!=[]:
        get=max(list(i[1] for i in candidate))
        work=[t for t in candidate if t[1]==get] 
        ab.remove(work[0])
        ans+=get
print(ans)

Submission status: Time Limit Exceeded

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

reward = []
heapq.heapify(reward)

total = 0
for i in range(M)[::-1]:
    for j in range(len(reward), N):
        if tasks[j][0] == M - i:
            heapq.heappush(reward, -1 * tasks[j][1])

    if len(reward) > 0:
        total += heapq.heappop(reward) * (-1)

print(total)

Submission status: Time Limit Exceeded

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

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

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

days = [0 for i in range(m + 1)]
for i in range(n):
    # print(jobs_sorted[i])
    if jobs_sorted[i][0] <= m:
        for j in range(m - jobs_sorted[i][0], -1, -1):
            if days[j] < jobs_sorted[i][1]:
                for k in range(0, j):
                    if days[k+1] != 0:
                        days[k] = days[k+1]
                days[j] = jobs_sorted[i][1]
                break
    # print(days)

print(sum(days))

Submission status: Time Limit Exceeded

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

reward = []
heapq.heapify(reward)

total = 0
for i in range(M)[::-1]:
    for j in range(N):
        if tasks[j][0] == M - i:
            heapq.heappush(reward, -1 * tasks[j][1])
    if len(reward) > 0:
        total += heapq.heappop(reward) * (-1)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

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

l.sort()
q = []
ans = 0
for i in range(1,m+1):
    while len(l) > 0 and l[0][0] == i:
        tmp = l.pop(0)
        heapq.heappush(q,-tmp[1])
    
    if len(q) != 0:
        ans += -heapq.heappop(q)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline

n, m = map(int, input().split())
dic = defaultdict(list)
total = 0
candidates = []

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

for day in range(1, m+1):
    if day in dic:
        candidates += dic[day]

    if candidates:
        fee = max(candidates)
        total += fee
        candidates.remove(fee)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict


input = sys.stdin.readline
n, m = map(int, input().split())
dic = defaultdict(list)
total = 0
candidates = []

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

for day in range(1, m+1):
    if day in dic:
        candidates += dic[day]

    if candidates:
        fee = max(candidates)
        total += fee
        candidates.remove(fee)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import heapq

n, m = map(int, input().split())
a_list = []
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        a_list.append([a, b])
a_list.sort()
a_list_1 = [aa[0] for aa in a_list]
a_list_2 = [-aa[1] for aa in a_list]
ans = 0
heap_list = []
for i in range(1, m + 1):
    k = bisect.bisect_right(a_list_1, i) - 1
    if k >= 0:
        for aa in a_list_2[:k+1]:
            heapq.heappush(heap_list, aa)
        del a_list_1[:k+1], a_list_2[:k+1]
    if len(heap_list) > 0:
        ans -= heapq.heappop(heap_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import heapq

n, m = map(int, input().split())
a_list = []
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        a_list.append([a, b])
a_list.sort()
a_list_1 = [aa[0] for aa in a_list]
a_list_2 = [-aa[1] for aa in a_list]
ans = 0
heap_list = []
for i in range(1, m + 1):
    k = bisect.bisect_right(a_list_1, i) - 1
    if k >= 0:
        heap_list.extend(a_list_2[:k+1])
        del a_list_1[:k+1], a_list_2[:k+1]
    heapq.heapify(heap_list)
    if len(heap_list) > 0:
        ans -= heapq.heappop(heap_list)
print(ans)

Submission status: Time Limit Exceeded

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

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

    total_reward = 0
    for day in range(1, m+1) :
        max_reward_day = None
        
        for day2 in range(1, day+1):
             if day2 in day_to_rewards and len(day_to_rewards[day2]) > 0:
                    
                # 初期化
                if max_reward_day is None:
                    max_reward_day = day2

                # max 更新
                reward = day_to_rewards[day2][-1]
                if reward > day_to_rewards[max_reward_day][-1]:
                    max_reward_day = day2
        
        if max_reward_day is not None:
            total_reward += day_to_rewards[max_reward_day].pop()
        
#         while work_day > 0:
#             if work_day in day_to_rewards and len(day_to_rewards[work_day]) > 0:

#                 reward = day_to_rewards[work_day].pop()
#                 total_reward += reward
#                 print('find', work_day, reward)
#                 break
#             else:
#                 print('not find')
#                 work_day -= 1
#         print(day)
    return total_reward

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

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

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

Submission status: Time Limit Exceeded

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

n, m = map(int, input().split())
dic = {}
fee = 0

for i in range(n):
    a, b = map(int, input().split())
    if a not in dic:
        dic[a] = [b]
    else:
        dic[a].append(b)

for i in range(1, m+1):
    keys = [x for x in range(1, i+1)]
    temp_max_list = []
    for key in keys:
        if key not in dic or dic[key] == []:
            temp_max_list.append(-1)
        else:
            temp_max_list.append(max(dic[key]))
    if max(temp_max_list) == -1:
        continue
    fee += max(temp_max_list)
    select = temp_max_list.index(max(temp_max_list)) + 1
    dic[select].remove(max(temp_max_list))

print(fee)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,m = map(int,input().split())
day = []
for i in range(n):
    a,b = map(int,input().split())
    day.append([a,b])
task = []
cost = 0
heapq.heapify(task)
for i in range(1,m+1):
    for j in [k[1] for k in day if k[0] == i]:
        heapq.heappush(task,-j)
        #print(task,j)
    if task != []:
        c = heapq.heappop(task)
        cost += (-1)*c  
print(cost)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    for a, b in ab[j:]:
        if a > i:
            break
        heappush(hq, -b)
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort(key=lambda x: (x[0], -x[1]))
hq = []
result = 0
for i in range(1, m + 1):
    j = 0
    for a, b in ab:
        if a > i:
            break
        j += 1
        heappush(hq, -b)
    ab = ab[j:]
    if hq:
        result -= heappop(hq)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
hp = []
ret = 0
for i in range(1, M+1):
    # push
    while len(AB) > 0 and AB[len(AB)-1][0] <= i:
        # heappush(hp, AB.pop()[1]*-1)
        hp.append(AB.pop()[1])
    # pop
    if len(hp) > 0:
        hp.sort()
        ret += hp.pop()
        # ret += heappop(hp)*-1

print(ret)

Submission status: Time Limit Exceeded

Solution code:
#N is numbers of BAITO, M is limit of days
N,M=map(int,input().split())

i=0
inp ={}
while i<N:
  readTime,inCome=map(int,input().split())
  if readTime in inp:
    inp[readTime].append(inCome)
  else:
    inp[readTime]=[inCome]
  
  i=i+1

#print(inp)  

result=0
pool=[]
i=1
while i<=M:
  if i in inp:
	  pool=pool+inp[i]
  #print(i,pool)
  
  if len(pool)>0:
    result=result+max(pool)
    pool.remove(max(pool))
    #print(pool)
  
  i=i+1
 
print(result)

Submission status: Time Limit Exceeded

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()
ab.reverse()
#print(ab)
here = 0
ans = 0
pool = []
import heapq
for i in range(m+1):
  while True:
    if here == n:
      break
    elif ab[here][0] == -i:
      heapq.heappush(pool,-ab[here][1])
      here += 1
    else:
      break
  pool.sort()
  try:
    #print(pool)
    ans -= heapq.heappop(pool)
    #print(pool)
  except:
    pass
print(ans)