TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import heapq
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
l.append([0,0])
ans=0
k=[]
j=0
for i in range(1,m+1):
  while j<=n and l[j][0]<=i:
    heapq.heappush(k, l[j][1])
    j+=1
  if len(k)!=0:
  	ans+=k[-1]
  	k.pop(-1)
print(ans)

n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
l.append([0,0])
ans=0
k=[]
j=0
for i in range(1,m+1):
  while j<=n and l[j][0]<=i:
    k.append(l[j][1])
    j+=1
  ans+=max(k)
  k.remove(max(k))
print(ans)

import heapq
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
l.append([0,0])
ans=0
k=[]
j=0
for i in range(1,m+1):
  while j<=n and l[j][0]<=i:
    heapq.heappush(k, -1*l[j][1])
    j+=1
  if len(k)!=0:
  	ans+=-1*k[0]
  	heapq.heappop(k)
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    
    banpei_list=[[i,0] for i in range(1,m+2)]
    
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    print(jobs_list)
    ans=0
    index=0
    que=[]
    while True:
        day,pay=jobs_list[index]
        print(jobs_list[index])
        
        if day>m:
            break
        
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        
        
        else:
            heapq.heappush(que,-pay)
            print(que)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()

import heapq

def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    
    banpei_list=[[i,0] for i in range(1,m+2)]
    
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    print(jobs_list)
    ans=0
    index=0
    que=[]
    while 1:
        day,pay=jobs_list[index]
        print(jobs_list[index])
        
        if day>m:
            break
        
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        
        
        else:
            heapq.heappush(que,-pay)
            print(que)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()

#-*-coding:utf-8-*-

import heapq

def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    
    banpei_list=[[i,0] for i in range(1,m+2)]
    
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    ans=0
    index=0
    que=[]
    while 1:
        day,pay=jobs_list[index]
        
        if day>m:
            break
        
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        
        
        else:
            heapq.heappush(que,-pay)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A] += [-B]
print(dic, sorted(dic.keys()))

ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        heap += dic[i + 1]
    heapq.heapify(heap)
    # print(heap)
    if heap:
        ans += -heapq.heappop(heap)

print(ans)


import heapq

N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A not in dic:
        dic[A] = [-B]
    else:
        dic[A].append(-B)


ans = 0
heap = []

for i in range(M):
    # print(i)
    if i + 1 in dic:
        for j in dic[i + 1]:
            heapq.heappush(heap, j)
    # print(heap)
    if heap:
        ans = ans - heapq.heappop(heap)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
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
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))


job = list()
salary = list()
k = m
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 - k > 0:
        salary.remove(min(salary))
    else:
        k -= 1

print(sum(salary))


import heapq
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
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,q = map(int,input().split())
s = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    s[i] = [a,b]
s.sort()
ans = [-1 for i in range(n)]
for i in range(n-1):
    ans[s[i][1]-1] = s[i][0]-1
count = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    count[p-1] += x
ans1 = [0 for i in range(n)]
ans1[0] = count[0]
for i in range(1,n):
    ans1[i] = ans1[ans[i]] + count[i]
for i in range(n):
    print(ans1[i])

n,m = map(int,input().split())
ans = 0
import heapq
g = [[] for i in range(100000)]
for i in range(n):
    a,b = map(int,input().split())
    a -= 1
    g[a].append(-b)
for i in range(100000):
    heapq.heapify(g[i])
p = []
heapq.heapify(p)
for i in range(m):
    if len(g[i]) != 0:
        heapq.heappush(p,[heapq.heappop(g[i]),i])
    if len(p) != 0:
        x = heapq.heappop(p)
        ans += -x[0]
        if len(g[x[1]]) != 0:
            heapq.heappush(p,[heapq.heappop(g[x[1]]),x[1]])            
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def factorization(N):
    d = {}
    for n in range(2, N + 1):
        tmp = n
        for i in range(2, int(n ** 0.5) + 1):
            if tmp % i == 0:
                cnt = 0
                while tmp % i == 0:
                    cnt += 1
                    tmp //= i
                if i not in d:
                    d[i] = cnt
                else:
                    d[i] += cnt

        if tmp != 1:
            if tmp not in d:
                d[tmp] = 1
            else:
                d[tmp] += 1

    return d


def main():
    N = int(input())
    d = factorization(N)
    d = [v for k, v in d.items() if v > 1]
    cnt = {2: 0, 4: 0, 14: 0, 24: 0, 74: 0}
    cnt[2] = len(d)
    for i in range(len(d)):
        val = d[i]
        if val >= 74:
            cnt[74] += 1
        if val >= 24:
            cnt[24] += 1
        if val >= 14:
            cnt[14] += 1
        if val >= 4:
            cnt[4] += 1

    ans = cnt[74]
    ans += cnt[24] * (cnt[2] - 1)
    ans += cnt[14] * (cnt[4] - 1)
    ans += cnt[4] * (cnt[4] - 1) // 2 * (cnt[2] - 2)

    print(ans)


if __name__ == "__main__":
    main()


import sys
import heapq

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    d = {i: [] for i in range(M + 1)}
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        d[a].append(b)

    ans = 0
    q = []
    heapq.heapify(q)
    for i in range(M, 0, -1):
        a = M - i + 1
        for b in d[a]:
            heapq.heappush(q, -b)
        if q:
            b = heapq.heappop(q)
            ans += -b

    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
ab=[]
q=0
for i in range(n):
    p=[int(j) for j in input().split()]
    q=max(q,p[0])
    ab.append(p)
from operator import itemgetter
 
ab.sort(key=itemgetter(1))
ab.reverse()
ab.sort(key=itemgetter(0))
l=[]
import bisect
ans=0
for i in range(1,m+1):
    while True:
        if ab==[]:
            break
        if ab[0][0]<=i:
            insert_index = bisect.bisect_left(l,ab[0][0])  #2
            l.insert(insert_index,ab[0][0])
            del ab[0]
        else:
            break
    if l!=[]:
        ans+=l[-1]

print(ans)

n,m=map(int,input().split())
ab=[]
l=[[] for i in range(m+1)]
for i in range(n):
    tmp=[int(j) for j in input().split()]
    ab.append(tmp)
    a,b=tmp
    if a<=m:
        l[a].append(b)
import heapq
q=[]
ans=0
for i in range(1,1+m):
    for j in l[i]:
        heapq.heappush(q,-j)
    if q:
        ans-=heapq.heappop(q)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def update(i, x):
    i += 1
    while i < m + 1:
        bit[i] += x
        i += i & -i

def get_sum(i):
    i += 1
    s = 0
    while i > 0:
        s += bit[i]
        i -= i & -i
    return s

n, m = map(int, input().split())
bit = [0] * (m + 1)
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: (-x[1], -x[0]))
cnt = 0
ans = 0
for a, b in ab:
    if a <= m:
        a = m - a
        if get_sum(a) < a + 1:
            update(a, 1)
            cnt += 1
            ans += b
    print(a,b,bit,get_sum(a))
    if cnt == m: break
print(ans)


# pdf
from heapq import *

n, m = map(int, input().split())
hp = []
for _ in range(n):
    a, b = map(int, input().split())
    heappush(hp, [a, b])
ans = 0
mx = b
ch = []
a, b = heappop(hp)
flag = 1
for i in range(1, m + 1):
    while a <= i:
        if flag:
            heappush(ch, -b)
            flag = 0
        if not hp:break
        a, b = heappop(hp)
        flag = 1
    if ch:
        ans -= heappop(ch)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
N,M=(int(i) for i in input().split())



tasks=[[] for i in range(10**5+1)]
for i in range(N):
    a,b=(int(i) for i in input().split())
    tasks[a-1].append(b)

pq=[]
ans=0
for i in range(M):
    for b in tasks[i]:
        heappush(pq,b)
    if len(pq)!=0:
        ans+=heappop(pq)

print(ans)



import heapq
N,M=(int(i) for i in input().split())



tasks=[[] for i in range(10**5+1)]
for i in range(N):
    a,b=(int(i) for i in input().split())
    tasks[a-1].append(b)

pq=[]
ans=0
for i in range(M):
    for b in tasks[i]:
        heapq.heappush(pq,-b)
    if len(pq)!=0:
        temp=heapq.heappop(pq)
        ans-=temp

print(ans)



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def calc_total_reward(m, data):
    
    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
    reward_list = []
    
    print(day_to_rewards)
    for day in range(1, m+1):
        print(day)
        if day in day_to_rewards:
            print('add')
            reward_list.extend(day_to_rewards[day])
        sorted(reward_list)
        print(reward_list)
        if len(reward_list) > 0:
            total_reward += reward_list.pop()
    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)    

def calc_total_reward(m, data):
    
    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
    reward_list = []
    
    # print(day_to_rewards)
    for day in range(1, m+1):
        # print(day)
        if day in day_to_rewards:
            print('add')
            reward_list.extend(day_to_rewards[day])
        sorted(reward_list)
        # print(reward_list)
        if len(reward_list) > 0:
            total_reward += reward_list.pop()
    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)    

import sys
import heapq

N, M = list(map(int, input().split()))
jobs = []
for line in sys.stdin:
    A, B = map(int, line.split())
    if A > M:
        continue
    jobs.append((A, B))

jobs.sort(reverse=True)

q = []
ans = 0
for i in range(1, M + 1):
    while jobs and jobs[-1][0] <= i:
        A, B = jobs.pop()
        heapq.heappush(q, -B)

    if q:
        ans += -heapq.heappop(q)
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
import sys

finput = sys.stdin.readline

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

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    
    ans += heapq.heappop(hq)
print(-ans)    


import heapq
import sys

finput = sys.stdin.readline

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

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

print(-ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
q, z = [], 0
v = [q for _ in [0] * 10**5]
for a, b in t:
    v[a - 1] += b,
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    z += -heappop(q)
print(z)

from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
q, z = [], 0
v = [q for _ in [None] * 10**5]
for a, b in t:
    v[a - 1] += b,
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    if q:
        z += -heappop(q)
print(z)

from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
v = [[] for _ in [0] * 10**5]
q = []
for a, b in t:
    v[a - 1] += b,
z = 0
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    z += -heappop(q)
print(z)

from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
v = [[] for _ in [0] * 10**5]
q = [0]
for a, b in t:
    v[a - 1] += b,
z = 0
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    z += -heappop(q)
print(z)

from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
q, z = [], 0
v = [[] for _ in [None] * 10**5]
for a, b in t:
    v[a - 1] += b,
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    if q:
        z += -heappop(q)
print(z)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+2):
    ab.append([])
for i in range(n):
    a,b=map(int,input().split())
    ab[a].append(-b)
h = []
s=0
for i in range(1,m+2):
    for v in ab[i]:
        heapq.heappush(h,v)
    if len(h)!=0:
        s-=heapq.heappop(h)
print(s)

import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+1):
    ab.append([])
for i in range(n):
    a,b=map(int,input().split())
    ab[a].append(-b)
h = []
s=0
for i in range(m,-1,-1):
    for v in ab[i]:
        heapq.heappush(h,v)
    if len(h)!=0:
        s-=heapq.heappop(h)
print(s)

import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+1):
    ab.append([])
for i in range(n):
    a,b=map(int,input().split())
    ab[a].append(b)
h = []
s=0
for i in range(1,m):
    for v in ab[i]:
        heapq.heappush(h,-1*v)
    if len(h)>0:
        s+=-1*heapq.heappop(h)
print(s)


import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+1):
    ab.append([])
for i in range(m+1):
    a,b=map(int,input().split())
    ab[a].append(-1*b)
h = []
s=0
for i in range(1,m+1):
    for v in ab[i]:
        heapq.heappush(h,v)
    if len(h)!=0:
        s+=-1*heapq.heappop(h)
print(s)

import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+1):
    ab.append([])
for i in range(n):
    a,b=map(int,input().split())
    if a>m:
        continue
    ab[a].append(b)
h = []
s=0
for i in range(1,m+1):
    for v in ab[i]:
        heapq.heappush(h,-1*v)
    if len(h)>0:
        s+=-1*heapq.heappop(h)
print(s)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq
N,M = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(N)]
l = sorted(l)
heap = []
a = 0
b = 0
for i in range(1,M+1):
    while l[a][0] <= i:
        a = 0
        heapq.heappush(heap,-(l[a][1]))
        a += 1
    if heap == []:
        continue
    else:
        b += -(heapq.heappop(heap))
print(b)






import heapq
N,M = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(N)]
l = sorted(l)
heap = []
a = 0
b = 0
for i in range(1,M+1):
        while l and l[a][0] <= i:
            heapq.heappush(heap, -(l[a][1]))
        if heap :
            b -= (heapq.heappop(heap))
print(b)


import heapq
N,M = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(N)]
l = sorted(l,reverse=True)
heap = []
ans = 0
for i in range(1,M+1):
        while l and l[-1][0] == i:
            heapq.heappush(heap, -(l.pop()[1]))
        if heap :
            ans -= (heapq.heappop(heap))
print(ans)





Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
#137D
def main():
    import sys
    import heapq as h
    from collections import defaultdict
    N, M = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    #print(L)
    D = defaultdict(list)
    for i in range(N):
        D[L[i][0]-1].append(-L[i][1])
    
    #print(D)
    ans = 0
    tmp=[]
    h.heapify(tmp)
    for d in range(M):
        for b in D[d]:
            h.heappush(tmp, b)
        #print(tmp)
        ans += h.heappop(tmp)
        
    print(-ans)



if __name__=='__main__':
    main()

#137D
def main():
    import sys
    import heapq as h
    from collections import defaultdict
    N, M = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    #print(L)
    D = defaultdict(list)
    for i in range(N):
        D[L[i][0]-1].append(-L[i][1])
    
    #print(D)
    ans = 0
    tmp=[]
    h.heapify(tmp)
    for d in range(M):
        for b in D[d]:
            h.heappush(tmp, b)
        #print(tmp)
        ans += h.heappop(tmp)

#137D
def main():
    import sys
    import heapq as h
    from collections import defaultdict
    N, M = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    #print(L)
    D = defaultdict(list)
    for i in range(N):
        D[L[i][0]-1].append(-L[i][1])
    
    #print(D)
    ans = 0
    tmp=[]
    h.heapify(tmp)
    for d in range(M):
        for b in D[d]:
            h.heappush(tmp, b)
        #print(tmp)
        if tmp:
            ans += h.heappop(tmp)
        
    print(-ans)



if __name__=='__main__':
    main()

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
l = []
for i in range(n):
    a,b = map(int,input().split())
    l.append([a,b])
l.sort(reverse=True,key= lambda x:x[0])
l.sort(reverse=True,key= lambda x:x[1])
print(l)
da = 0
mon = 0
for i in range(n):
    a,b = l[i]

    if da + a <= m:
        mon += b
        da += 1
    else:
        continue
print(mon)


import heapq as hq
n,m = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,-b))
ab.sort()
ans = 0
idx = 0
q = []
for i in range(1,m+1):
    while idx<n and ab[idx][0] ==i:
        a,mb = ab[idx]
        hq.heappush(q,mb)
        idx+=1
    if q!=[]:
        ans += -1*hq.heappop(q)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
valuesDict = {}
for _ in range(N):
  A, B = map(int, input().split())
  valuesDict[A] = B if valuesDict[A] >= B else valuesDict[A]

answer = 0
for i in range(M):
  today = i + 1
  answer += valuesDict.get(today) if valuesDict.get(today) is not None else 0

print(answer)

N, M = map(int, input().split())
valuesDict = {}
for i in range(N):
  A, B = map(int, input().split())
  valuesDict[i+A] += B

print(valuesDict[M])

N, M = map(int, input().split())
valuesDict = {}
for i in range(N):
  today = i + 1
  A, B = map(int, input().split())
  valuesDict[today+A] += B
answer = 0
for i in range(M):
  today = i + 1
  answer += valuesDict[today]

print(answer)


import heapq
N, M = map(int,input().split())
reward = [[] for _ in range(M)]
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    reward[A-1].append(B)
q = []
ans = 0
for day in range(M):
  for r in reward[day]:
    heapq.heappush(q,-r)
  if len(q) >0:
    ans += -heapq.heappop(q)
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys,heapq
input=sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AB=[list(map(int,input().strip().split())) for _ in range(N)]
AB.sort()
print(AB)
n=0
sumB=0
q=[]
for m in range(1,M+1):
    maxB=0
    while n<N and AB[n][0]<=m:
        heapq.heappush(q,-AB[n][1])
        n+=1
    sumB+=heapq.heappop(q)
    if len(q)==0: break
    
print(-sumB)

import sys,heapq
input=sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AB=[list(map(int,input().strip().split())) for _ in range(N)]
AB.sort()
n=0
sumB=0
q=[]
for m in range(1,M+1):
    maxB=0
    while n<N and AB[n][0]<=m:
        heapq.heappush(q,-AB[n][1])
        n+=1
    sumB+=heapq.heappop(q)
    if len(q)==0: break
    
print(-sumB)

import sys,heapq
input=sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AB=[list(map(int,input().strip().split())) for _ in range(N)]
AB.sort()
n=0
sumB=0
q=[]
for m in range(1,M+1):
    while n<N and AB[n][0]<=m:
        heapq.heappush(q,-AB[n][1])
        n+=1
    if len(q)!=0:
        sumB+=heapq.heappop(q)

print(-sumB)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n, m = map(int, input().split())
work = [list(map(int, input().split())) for i in range(n)]
dic = {}
for w in work:
    a, b = w[0], w[1]
    if a not in dic.keys():
        dic[a]=[b]
    else:
        index=bisect.bisect_right(dic[a], b)
        dic[a].insert(index, b)
dic_=sorted(dic.items(), key=lambda x:x[0])
res = 0
while m > 0:
    print(dic_)
    flag=True
    for i in range(len(dic_)):
        if dic_[i][0] >= m:
            flag=False
            if i==0:
                break
            res+=dic_[i][1].pop(-1)
    if flag:
        dic_[-1][1].pop(-1)
    m-=1

from collections import defaultdict
from bisect import bisect_right
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
work=defaultdict(list)
for A, B in lst:
  work[A].append(B)
for k in list(work.keys()):
  work[k].sort()
ans=0
for day in range(1, M+1):
  days=list(work.keys())
  idx=bisect_right(days, day)
  if idx==0:
    continue
  maxi=0
  maxv=work[days[maxi]][-1]
  for i in range(idx):
    if maxv<work[days[i]][-1]:
      maxv=work[days[i]][-1]
      maxi=i
  ans+=work[days[maxi]].pop()
  if not work[days[maxi]]:
    work.pop(days[maxi])
print(ans)

from collections import defaultdict
from bisect import bisect_right
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(N)]
work=defaultdict(list)
for a, b in lst:
  work[b].append(a)
for k in work.keys():
  work[k].sort()
ans=0
while M>0 and len(work)>0:
  max_profit=list(work.keys())[-1]
  i=bisect_right(work[max_profit], M)
  if i==0:
    work.pop(max_profit)
    continue
  ans+=max_profit
  work[max_profit].pop(i-1)
  M-=1
  if not work[max_profit]:
    work.pop(max_profit)
print(ans)

from itertools import bisect
n, m = map(int, input().split())
work = [map(int, input().split()) for i in range(n)]
dic = {}
for w in work:
  a, b = w[0], w[1]
  if a not in dic.keys():
    dic[a]=[b]
  else:
    index=bisect.bisect_right(dic[a], b)
    dic[a].insert(index, b)
res = 0
while m > 0:
  index=bisect.bisect_left(dic.keys(), m)
  res+=dic[index].pos(len(dic[index])-1)
print(res)

import heapq
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(list)
for i in range(N):
    A, B = map(int, input().split())
    d[A].append(-B)

ans = 0
work = []
for i in range(1, M+1):
    for j in range(len(d[i])):
        heapq.heappush(work, d[i][j])
    if len(work):
        ans -= heapq.heappop(work)
print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)])



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
    
    if pool:
        max_reword = max(pool)
        print(day, max_reword)
        rewords += max_reword
        pool.remove(max_reword)

print(rewords)


import sys
from heapq import heappop, heappush

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



index = 0
pool = []
rewords = 0
for i in range(M):
    day = i + 1

    while index < N and day >= int(sorted_ab[index][0]):
        heappush(pool, -sorted_ab[index][1])
        index += 1
    
    if pool:
        rewords += -heappop(pool)

print(rewords)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        [a, b] = [int(number) for number in input().split()]
        #money_par_day = b / a
        part_times.append([b, a])
        #part_times.sort(reverse=True)
    part_times = sorted(part_times, key = lambda x: (x[0], x[1]))
    print(part_times)
    money = 0
    day = 0

    

    for part_time in part_times:
        [b,a] = part_time
        if a + day <= M:
            day += a
            money += b
        else:
            continue
    print(money)

if __name__ == '__main__':
    main()


def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        [a, b] = [int(number) for number in input().split()]
        #money_par_day = b / a
        part_times.append([b, a])
        #part_times.sort(reverse=True)
    part_times = sorted(part_times, key = lambda x: (x[0], x[1]))
    money = 0
    day = 0

    

    for part_time in part_times:
        [b,a] = part_time
        if a + day <= M:
            day += a
            money += b
        else:
            continue
    print(money)

if __name__ == '__main__':
    main()


import heapq

def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[0])] #if part_time[0] <= M]
    money = 0
    hp = []
    for day in range(M):
        while part_times != [] and part_times[0][0] <= day + 1:
            part_time = part_times[0]
            heapq.heappush(hp, - part_time[1])
            part_times.pop(0)
        if hp != []:
            money -= heapq.heappop(hp)

    print(money)

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
mport heapq
n,m=map(int,input().split())
list=[[] for i in range(m)]
h=[]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    list[a-1].append(-b)
ans=0
for i in range(m):
  for j in list[i]:
    heapq.heappush(h,j)
  if h:
    ans+=-heapq.heappop(h)
  else:
    continue
print(ans)  

import heapq
n,m=map(int,input().split())
list=[[] for i in range(m)]
h=[]
for i in range(n):
  a,b=map(int,input().split())
  if a<=m:
    list[a-1].append(-b)
ans=0
for i in range(m):
  for j in list[i]:
    heapq.heappush(h,j)
  if h:
    ans+=-heapq.heappop(h)
  else:
    continue
print(ans)  


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import heapq

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

l=sorted(l, key=lambda x:x[1], reverse=True)

a=[]
day=0
ans=0
for j in range(1,m+1):
    while 1:
        if day>=n:
            break
        if l[day][0]<=j:
            heapq.heappush(a,-l[day][1])
            day+=1
        else:
            break
    if a:
        ans-=heapq.heappop(a)
print(ans)

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

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

hq = []
ans, j = 0, 0

for i in range(1,M+1):
    while (j<N) and (X[j][0] <=i):
        heappush(hq,-X[j][1])
        j+=1
    if hq:
        ans-=heappop(hq)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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.lexsort((X[:,0], -X[:,1]), axis=0)[::-1]
X = X[X_ind]
# print(X)
least = M - 1
p = 0
while least >= 0:
    last, X = X[-1], X[:-1]
    # print(last, X)
    if (M - least) >= last[0]:
        p += last[1]
        least -= 1

print(p)


from heapq import heappush,heappop
N, M = map(int, input().split())

X = []

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


X = sorted(X, key=lambda x:(x[0], x[1]), reverse=True)

# print(X)
q = []
ans = 0
for i in range(1, M + 1):
    while X and X[-1][0] <= i:
        _, b = X.pop()
        heappush(q, -b)
    if q:
        ans -= heappop(q)
        
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#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 = []

for j in range(0, M):
    for i in range(N):
        if A[i] == j+1:
            heapq.heappush(hq, -B[i])
    if len(hq) > 0:
        point[j] = -heapq.heappop(hq)
point
sum(point)

N= int(input())
s = []

for _ in range(N):
    s.append(input())

for i in range(N):
    s[i] = [*s[i]]
    s[i] = sorted(s[i])

counter = 0
for i in range(N):
    for j in range((i+1), N):
        if s[i] == s[j]:
            counter += 1

print(counter)   

#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 = []

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)

#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 = []

for j in range(0, M):
    for i in range(N):
        if A[i] == j + 1:
            heapq.heappush(hq, -B[i])
    if len(hq) > 0:
        point[j] = -heapq.heappop(hq)

sum(point)

#input
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:
        jobs[A].append(B)
    else:
        jobs[A] = [B]

#output
import heapq


point = 0
hq = []

for A in range(1, M+1):
    if A in jobs:
        for B in jobs[A]:
            heapq.heappush(hq, -B)
    else:
        if len(hq) == 0:
            continue
    point += -heapq.heappop(hq)

print(point)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
l=[['0']*10 for _ in range(n)]
for i in range(n):
        a=str(input())
        for j in range(10):
                l[i][j]=a[j]
        l[i].sort()
l.sort()

c=0
d=[]
for j in range(n-1):
        if l[j]==l[j+1] and j==n-2:
                c+=2
                d.append(c)
        elif l[j]==l[j+1]:
                c+=1
        else:
                c+=1
                d.append(c)
                c=0
aa=0
for k in range(len(d)):
        aa+=d[k]*(d[k]-1)//2
print(aa)


import heapq

n,m=map(int,input().split())
L=[[] for _ in range(m)]
for _ in range(n):
        a,b=map(int,input().split())
        if a<=m:
                L[a-1].append(-b)
h=[]
heapq.heapify(h)

ans=0
for i in range(m):
        for j in L[i]:
                heapq.heappush(h,j)
        if len(h)==0:
                continue
        ans+=heapq.heappop(h)*(-1)
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from heapq import *
n, m = map(int, input().split())
pay = []
for _ in range(n):
    a, b = map(int, input().split())
    pay.append((a, b))
pay = sorted(pay, reverse=True)
print(pay)
q = []
ans = 0
for i in range(1, m+1):
    while pay and pay[-1][0] <= i:
        a, b = pay.pop()
        heappush(q, -b)
    print(q)
    if q:
        b = -heappop(q)
        ans += b
print(ans)

from heapq import *
n, m = map(int, input().split())
pay = []
for _ in range(n):
    a, b = map(int, input().split())
    pay.append((a, b))
pay = sorted(pay, reverse=True)
q = []
ans = 0
for i in range(1, m+1):
    while pay and pay[-1][0] <= i:
        a, b = pay.pop()
        heappush(q, -b)
    if q:
        b = -heappop(q)
        ans += b
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#template
def inputlist(): return [int(k) for k in input().split()]
#template

N,M = inputlist()
li = []
for i in range(N):
    A,B = inputlist()
    B *= -1
    li.append([A,B])
ans = 0
from heapq import *
li.sort()
k = []
heapify(k)
flag = 0
for i in range(1,M+1):
    if flag == N:
        for t in range(M+1-i):
            ans -= heappop(k)
		break
    while li[flag][0] <= i:
        heappush(k,li[flag][1])
        flag = flag + 1
        if flag == N:
            break
    if len(k)>=1:
        ans -= heappop(k)
print(ans)


#template
def inputlist(): return [int(k) for k in input().split()]
#template

N,M = inputlist()
li = []
for i in range(N):
    A,B = inputlist()
    B *= -1
    li.append([A,B])
ans = 0
from heapq import *
li.sort()
k = []
heapify(k)
flag = 0
for i in range(1,M+1):
    if flag == N:
        for t in range(M+1-i):
            ans -= heappop(k)
        break
    while li[flag][0] <= i:
        heappush(k,li[flag][1])
        flag = flag + 1
        if flag == N:
            break
    if len(k)>=1:
        ans -= heappop(k)
print(ans)

Verdicts: Runtime Error

Accepted