input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import heapq N, M = list(map(int, input().split())) Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0]) ans = 0 can_work = [] i = 0 for m in range(M + 1): while (i < N) and (Work[i][0]) <= m: heapq.heappush(can_work, -Work[i][1]) i += 1 if can_work:...
import heapq N, M = list(map(int, input().split())) works = sorted([list(map(int, input().split())) for i in range(N)]) ans = 0 hq = [] i = 0 for limit in range(1, M + 1): while (i < N) and (works[i][0] <= limit): cost, value = works[i] heapq.heappush(hq, -value) i += 1 if...
p02948
from heapq import* (N,M),*t=[list(map(int,s.split()))for s in open(0)] q=[0]*7**6 v=[[]for _ in q] z=0 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=[list(map(int,s.split()))for s in open(0)] q=[0]*7**6 v=[[]for _ in q] z=0 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)
p02948
import sys import collections import heapq input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) AB = [] for _ in range(N): a, b = list(map(int, input().split())) AB.append((a, b)) AB.sort(key=lambda x: x[0]) H = [] I = 0 ans = 0 ...
import sys import collections import heapq input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) AB = [] for _ in range(N): a, b = list(map(int, input().split())) AB.append((a, b)) AB.sort(key=lambda x: x[0]) H = [] I = 0 ans = 0 ...
p02948
# ABC137D - Summer Vacation import sys from heapq import heappop, heappush readline = sys.stdin.buffer.readline heappop_max = lambda heap: -heappop(heap) heappush_max = lambda heap, x: heappush(heap, -x) def main(): N, M = list(map(int, readline().split())) all_jobs = tuple(tuple(map(int, readline...
# ABC137D - Summer Vacation import sys from heapq import heappop, heappush readline = sys.stdin.buffer.readline heappop_max = lambda heap: -heappop(heap) heappush_max = lambda heap, x: heappush(heap, -x) def main(): N, M = list(map(int, readline().split())) available_jobs = [[] for _ in range(M + ...
p02948
# ABC137D - Summer Vacation import sys from heapq import heappop, heappush readline = sys.stdin.buffer.readline heappop_max = lambda heap: -heappop(heap) heappush_max = lambda heap, x: heappush(heap, -x) def main(): N, M = list(map(int, readline().split())) available_jobs = [[] for _ in range(M + ...
# ABC137D - Summer Vacation import sys from heapq import heappop, heappush read = sys.stdin.buffer.read heappop_max = lambda heap: -heappop(heap) heappush_max = lambda heap, x: heappush(heap, -x) def main(): N, M, *all_jobs = list(map(int, read().split())) available_jobs = [[] for _ in range(M + 1...
p02948
import sys input = sys.stdin.readline import heapq N,M = (int(x) for x in input().split()) jobs = [] taken = [0] * (M+1) jappend = jobs.append for i in range(N): A,B = (int(x) for x in input().split()) if A <= M: jappend((B*(-1),A)) heapq.heapify(jobs) for i in range(len(jobs)): temp ...
import sys input = sys.stdin.readline import heapq N,M = (int(x) for x in input().split()) jobs = [[] for i in range(M)] count = 0 h = [] for i in range(N): A,B = (int(x) for x in input().split()) if A <= M: jobs[A-1].append(B*(-1)) heapq.heapify(h) for i in range(M): if jobs[i]: ...
p02948
import heapq N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(N)] AB.sort() works=[] heapq.heapify(works) ans=0 for i in range(1,M+1): day=M-i latest=i while AB and AB[0][0]<=latest: a,b=AB.pop(0) heapq.heappush(works,-b) if not works: continue ...
import heapq N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(N)] AB.sort(reverse=True) works=[] heapq.heapify(works) ans=0 for i in range(1,M+1): day=M-i latest=i while AB and AB[-1][0]<=latest: a,b=AB.pop() heapq.heappush(works,-b) if not works: ...
p02948
import heapq N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(N)] AB.sort(reverse=True) works=[] heapq.heapify(works) ans=0 for i in range(1,M+1): day=M-i latest=i while AB and AB[-1][0]<=latest: a,b=AB.pop(-1) heapq.heappush(works,-b) if not works: ...
import heapq N,M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(N)] AB.sort(reverse=True) works=[] heapq.heapify(works) ans=0 AB=AB+[[0,0]] for i in range(1,M+1): day=M-i latest=i while len(AB)>=2 and AB[-2][0]<=latest: a,b=AB.pop(-2) heapq.heappush(works,-...
p02948
from heapq import heappush, heappop n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() ans = 0 hq = [] for i in range(1, m+1): for a, b in ab: if a == i: heappush(hq, (-b, a)) if len(hq) != 0: ans -= heappo...
from heapq import heappush, heappop n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort() ans = 0 hq = [] idx = 0 for i in range(1, m+1): for j in range(idx, n): if ab[j][0] == i: heappush(hq, (-ab[j][1], ab[j][0])) i...
p02948
n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(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.h...
n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(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.h...
p02948
import heapq def main(): N, M = list(map(int, input().split())) AB = [] for i in range(N): a, b = list(map(int, input().split())) AB.append([a, b]) AB.sort(reverse = True) q = [] ans = 0 j = N-1 for i in range(M-1, -1, -1): while j >=0 and AB[j...
import heapq def main(): N, M = list(map(int, input().split())) task = [] for _ in range(N): A, B = list(map(int, input().split())) task.append([A, B]) task.sort() hq = [] ans = 0 for i in range(1, M+1): while task and task[0][0]<= i: _, v ...
p02948
# 3.4.3 import re from collections import deque from functools import reduce from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from queue import PriorityQueue from sys import stdin def rline()...
# 3.4.3 import re from collections import deque from functools import reduce from heapq import heappop from heapq import heappush from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from sys import ...
p02948
# 3.4.3 import re from collections import deque from functools import reduce from heapq import heappop from heapq import heappush from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep from sys import ...
# 3.4.3 import re from collections import deque from functools import reduce from heapq import * from itertools import permutations from math import pi from operator import itemgetter from operator import mul from operator import xor from os import linesep def isprime(n: int) -> bool: if n <= 1: ...
p02948
import sys from collections import deque sys.setrecursionlimit(20000000) input = sys.stdin.readline def main(): n, limit = list(map(int, input().split())) jobs = [list(map(int, input().split())) for _ in range(n)] for j in jobs: j.append(True) money = 0 for d in range(1, ...
import sys from collections import deque, defaultdict from heapq import heappop, heappush sys.setrecursionlimit(20000000) input = sys.stdin.readline def main(): n, limit = list(map(int, input().split())) jobs = defaultdict(deque) for _ in range(n): d, v = list(map(int, input().s...
p02948
n,m = list(map(int,input().split())) ab = {i:[] for i in range(m+1)} for i in range(n): a,b = list(map(int,input().split())) if a in ab: ab[a].append(b) else: ab[a] = [b] #print(ab) ans = 0 for i in range(m)[::-1]: rem = m - i if ab[rem]: job = ab[rem] a...
n,m = list(map(int,input().split())) ab = {i:[] for i in range(m+1)} for i in range(n): a,b = list(map(int,input().split())) if a in ab: ab[a].append(b) else: ab[a] = [b] #print(ab) ans = 0 for i in range(m)[::-1]: rem = m - i if ab[rem]: job = ab[rem] a...
p02948
def main(): from collections import deque n, m, *ab = list(map(int, open(0).read().split())) job = [[] for _ in range(1 + max(ab))] for i, j in zip(*[iter(ab)] * 2): job[i].append(j) ans = 0 t = [] for i in range(1, m + 1): t += job[i] if len(t) == 0: ...
def main(): import heapq n, m, *ab = list(map(int, open(0).read().split())) l = [[] for _ in range(m + 1)] for i, j in zip(*[iter(ab)] * 2): if i <= m: l[i].append(-j) ans = 0 h = [] for i in range(1, m + 1): g = l[i] for j in g: ...
p02948
def main(): import heapq n, m, *ab = list(map(int, open(0).read().split())) l = [[] for _ in range(m + 1)] for i, j in zip(*[iter(ab)] * 2): if i <= m: heapq.heappush(l[i], -j) ans = 0 h = [] for i in range(1, m + 1): for j in l[i]: he...
def main(): from heapq import heappush as sushi from heapq import heappop as tempra n, m, *ab = list(map(int, open(0).read().split())) l = [[] for _ in range(m + 1)] for i, j in zip(*[iter(ab)] * 2): if i <= m: l[i].append(-j) w = [] h = [] for i in range(...
p02948
import heapq N, M = list(map(int, input().split())) S = [[0] for _ in range(M)] for _ in range(N): a, b = list(map(int, input().split())) if M < a: continue heapq.heappush(S[M-a], -b) ans = heapq.heappop(S[M-1]) for i in range(M-2, -1, -1): for num in S[i+1]: heapq.heappush(...
import heapq N, M = list(map(int, input().split())) S = list() A = [list() for _ in range(M+1)] for _ in range(N): a, b = list(map(int, input().split())) if M < a: continue heapq.heappush(A[a], -b) ans = 0 for i in range(1, M+1): for num in A[i]: heapq.heappush(S, num) ...
p02948
#!/usr/bin/env python3 from collections import deque class PriorityQueue: def __init__(self, size): self.tree = [None] * size self.bottom = 0 def add(self, data): n = self.bottom self.bottom += 1 self.tree[n] = data while n != 0: par...
#!/usr/bin/env python3 from collections import deque import heapq def solve(N, M, A, B): ans = 0 # 日付順にソートする all_works = deque(sorted(zip(A, B), key=lambda x: x[0])) pq = [] for d in range(1, M+1): # print('d=', d) # 今日が期限の仕事があれば追加 while all_works and all_w...
p02948
from heapq import heapify, heappush, heappop N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] AB.sort() queue = [] heapify(queue) ans = 0 for i in range(1, M+1): while len(AB) > 0: if AB[0][0] <= i: heappush(queue, -AB.pop(0)[1]) ...
from heapq import heappush, heappop N, M = list(map(int, input().split())) salary = [[] for i in range(M+1)] for i in range(N): A, B = list(map(int, input().split())) if A <= M: salary[A].append(B) queue = [] ans = 0 for i in range(1, M+1): for s in salary[i]: heappush(queue, ...
p02948
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B a = [] b = [] for i in range(n): ai, bi = list(map(int, input().split())) a.append(ai) b.append(bi) sum = 0 used = [False] * n for i in range(0, m): # A <= iで未使用のものをheapqに入れる...
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [-b] else: workList[a].append(-b) # print(workList) hq ...
p02948
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [-b] else: workList[a].append(-b) # print(workList) hq ...
# -*- coding: utf-8 -*- from heapq import heappush, heappop n, m = list(map(int, input().split())) # A日後、報酬B # 日付ごとに報酬をリスト化 workList = {} for i in range(n): a, b = list(map(int, input().split())) if a not in workList: workList[a] = [b] else: workList[a].append(b) hq = [] ...
p02948
from operator import itemgetter import sys input = sys.stdin.readline N, M = list(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 ...
from operator import itemgetter import sys input = sys.stdin.readline N, M = list(map(int,input().split())) # 複数の数字を変数に格納 List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]] List.sort(key=itemgetter(0)) List_S = [0] result = 0 p = 0 for i in range(1, M+1): add = 0 ...
p02948
import collections import heapq n, m = list(map(int, input().split())) que = [] for _ in range(n): a, b = list(map(int, input().split())) que.append((-b, a)) que.sort(key=lambda x: x[1]) que = collections.deque(que) h = [] heapq.heapify(h) ans = 0 for i in range(1, m + 1): while len(que) != 0...
import heapq n, m = list(map(int, input().split())) que = [] for _ in range(n): a, b = list(map(int, input().split())) que.append((-b, a)) que.sort(key=lambda x: x[1], reverse=True) def solve(que, m): ans = 0 h = [] heapq.heapify(h) for i in range(1, m + 1): while len(que...
p02948
import heapq n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(n)] arr=sorted(arr,reverse=True,key=lambda x:x[1]) arr=sorted(arr,reverse=True,key=lambda x:x[0]) q=[] tmp=0 cnt=0 for a,b in arr: if tmp!=a: tmp=a cnt=0 if m-tmp<cnt: continue heapq.heap...
import heapq n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(n)] arr2=[[i,0] for i in range(1,m+5)] arr.extend(arr2) arr=sorted(arr,reverse=True,key=lambda x:x[1]) arr=sorted(arr,key=lambda x:x[0]) tmp=arr[0][0] q=[] ans=0 pos=0 while 1: a,b=arr[pos] if a>m: ...
p02948
import heapq n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(n)] arr2=[[i,0] for i in range(1,m+2)] arr.extend(arr2) arr=sorted(arr,reverse=True,key=lambda x:x[1]) arr=sorted(arr,key=lambda x:x[0]) q=[] ans=0 pos=0 while 1: a,b=arr[pos] if a>m: break if a=...
import heapq n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(n)] arr2=[[i,0] for i in range(1,m+2)] arr.extend(arr2) arr=sorted(arr,key=lambda x:x[0]) q=[] ans=0 pos=0 while 1: a,b=arr[pos] if a>m: break if a==arr[pos+1][0]: heapq.heappush(q,-b) els...
p02948
import heapq n,m=list(map(int,input().split())) c=[list(map(int,input().split())) for i in range(n)] l=list() v=0 heapq.heapify(l) for i in range(1,m+1): for j in range(n): if c[j][0]==i: heapq.heappush(l,(-1)*c[j][1]) if l: v+=heapq.heappop(l)*(-1) print(v)
import heapq n,m=list(map(int,input().split())) lis=[[] for i in range(m)] for i in range(n): a,b=list(map(int,input().split())) if a-1<m: lis[a-1].append(-b) l=list() v=0 for i in range(m): for j in lis[i]: heapq.heappush(l,j) if l: v+=heapq.heappop(l)*(-1) print(v)
p02948
import heapq N, M = list(map(int, input().split())) jobs = [[] for _ in range(M)] for i in range(N): d, r = list(map(int, input().split())) if d-1 < M: jobs[d-1].append(-r) m = 0 heap = [] for i in range(M): for a in jobs[i]: heapq.heappush(heap, a) if len(heap) > 0: ...
import heapq def main(): N, M = list(map(int, input().split())) jobs = [[] for _ in range(M)] for i in range(N): d, r = list(map(int, input().split())) if d-1 < M: jobs[d-1].append(-r) m = 0 heap = [] for i in range(M): for a in jobs[i]: heapq.heappush(heap, a) if ...
p02948
import heapq N, M = list(map(int, input().split())) job_list = {} ans = 0 kouho = [] for _ in range(N): A, B = list(map(int, input().split())) B = B * (-1) if A in list(job_list.keys()): job_list[A].append(B) else: job_list[A] = [B] for day in range(1, M + 1): try: kouho += job_...
import heapq N, M = list(map(int, input().split())) AB_list = [] [heapq.heappush(AB_list, list(map(int, input().split()))) for _ in range(N)] ans = 0 kouho = [] for day in range(1, M + 1): if len(AB_list) != 0: while AB_list[0][0] <= day: heapq.heappush(kouho, heapq.heapp...
p02948
import heapq n, m = list(map(int, input().split())) lis = [] for i in range(m + 1): lis.append([]) for i in range(n): a, b = list(map(int, input().split())) if a <= m: lis[a].append(-b) cnd = [] heapq.heapify(cnd) res = 0 for j in range(1, m + 1): for e in lis[j]: h...
import heapq n, m = list(map(int, input().split())) lis = [[] for _ in range(m + 1)] for i in range(n): a, b = list(map(int, input().split())) if a <= m: lis[a].append(-b) cnd = [] res = 0 for j in range(1, m + 1): for e in lis[j]: heapq.heappush(cnd, e) if cnd: ...
p02948
import heapq N, M = list(map(int,input().split())) jobs = [[] for i in range(10 ** 5 + 1)] lst = [] for i in range(N): a, b = list(map(int,input().split())) jobs[a].append((-1) * b) ans = 0 for i in range(1,M+1): lst += jobs[i] if lst: heapq.heapify(lst) k = heapq.hea...
import heapq N, M = list(map(int,input().split())) L = [[] for _ in range(M)] for _ in range(N): A, B = list(map(int,input().split())) try: L[A-1].append(-B) except: pass Q = [] ans = 0 for i in range(M): for j in L[i]: heapq.heappush(Q, j) try: ans -= ...
p02948
from sys import exit, stderr, stdin input = stdin.readline import heapq from collections import defaultdict # setrecursionlimit(10**7) def debug(var, name="hoge"): print(name +":" + str(type(var)) + " = " + repr(var), file=stderr) return def main(): N,M = [int(n) for n in input().split()] ...
from sys import exit, stderr, stdin input = stdin.readline import heapq # from collections import defaultdict # setrecursionlimit(10**7) def debug(var, name="hoge"): print(name +":" + str(type(var)) + " = " + repr(var), file=stderr) return def main(): N,M = [int(n) for n in input().split()] ...
p02948
import bisect N,M = list(map(int,input().split())) AB = list(list(map(int,input().split()))for i in range(N)) AB.sort() can = [] p = 0 ans = 0 for i in range(M+1): while p<N and (AB[p][0] <= i) : index = bisect.bisect_left(can,AB[p][1]) can.insert(index,AB[p][1]) p += 1 ...
import heapq N,M = list(map(int,input().split())) AB = list(list(map(int,input().split()))for i in range(N)) AB.sort() can = [] p = 0 ans = 0 for i in range(M+1): while p<N and (AB[p][0] <= i) : heapq.heappush(can,-AB[p][1]) p += 1 if can != []: ans += heapq.heappop...
p02948
from heapq import heappush, heappop import sys input = sys.stdin.readline n, m = list(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 h...
from heapq import heappush, heappop import sys input = sys.stdin.readline n, m = list(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): while j < n and ab[j][0] <= i: heappush(hq, -ab[j][1]) ...
p02948
from collections import defaultdict N, M = list(map(int, input().split())) d = defaultdict(list) for _ in range(N): A, B = list(map(int, input().split())) d[A].append(B) works = [] for k in range(M, 0, -1): d[k] = sorted(d[k], reverse=True) if M-k+1 >= 1: works.extend(d[k][:M-k+1...
# from collections import defaultdict import heapq N, M = list(map(int, input().split())) W = [] for _ in range(N): W.append(tuple(map(int, input().split()))) W = sorted(W, key=lambda x: (x[0], -x[1])) a = [] heapq.heapify(a) # リストaのheap化 ans = 0 c = 0 for day in range(1, M+1): day_c = 0 ...
p02948
import heapq N, M = list(map(int, input().split())) W = [] # 取り組める仕事のリスト for _ in range(N): W.append(tuple(map(int, input().split()))) W = sorted(W, key=lambda x: (x[0], -x[1])) a = [] heapq.heapify(a) # リストaのheap化 ans = 0 c = 0 for day in range(1, M+1): day_c = 0 while c != N and W[c]...
import heapq N, M = list(map(int, input().split())) AB = [] for _ in range(N): A, B = list(map(int, input().split())) AB.append((A, B)) AB = sorted(AB, key=lambda x: x[0]) hq = [] heapq.heapify(hq) # リストhqのheap化 ans = 0 i = 0 for d in range(1, M+1): while i <= N-1 and AB[i][0] <= d: ...
p02948
import heapq as hq n,m=list(map(int,input().split())) a=[list(map(int,input().split())) for i in range(n)] for i in range(n): a[i][1]*=-1 hq.heapify(a) k=1 ans=0 q=0 while a and k<=m: p=hq.heappop(a) if p[0]>k: hq.heappush(a,p) k+=1 elif p[0]==k: ans-=p[1] ...
import heapq as hq n,m=list(map(int,input().split())) a=[list(map(int,input().split())) for i in range(n)] a.sort() for i in range(n): a[i][1]*=-1 b=[] hq.heapify(b) k,ans,i=1,0,0 while k<=m: while i<n and a[i][0]<=k: hq.heappush(b,a[i][1]) i+=1 if b: ans-=hq.heappop(b)...
p02948
import heapq as hq n,m=list(map(int,input().split())) a=[list(map(int,input().split())) for i in range(n)] a.sort() for i in range(n): a[i][1]*=-1 b=[] hq.heapify(b) k,ans,i=1,0,0 while k<=m: while i<n and a[i][0]<=k: hq.heappush(b,a[i][1]) i+=1 if b: ans-=hq.heappop(b)...
import heapq as hq n,m=list(map(int,input().split())) a=[list(map(int,input().split())) for i in range(n)] a.sort() for i in range(n): a[i][1]*=-1 b=[] hq.heapify(b) ans,i=0,0 for k in range(m-1,-1,-1): while i<n and a[i][0]+k<=m: hq.heappush(b,a[i][1]) i+=1 if b: ans-=...
p02948
from bisect import insort_left as sort import sys def input(): return sys.stdin.readline() n,m = list(map(int,input().split())) list = [[int(i) for i in input().split()] for i in range(n)] temp = [0] ans = 0 a = 0 list = sorted(list) for i in range(1,1+m): for j in range(a,len(list)): if list[...
import heapq as hp import sys def input(): return sys.stdin.readline() n,m = list(map(int,input().split())) list = [[int(i) for i in input().split()] for i in range(n)] temp = [0] ans = 0 a = 0 j = 0 list = sorted(list) for i in range(1,1+m): for j in range(a,len(list)): if list[j][0] == i: ...
p02948
L=lambda:list(map(int,input().split()));n,m=L();t=sorted([L()for _ in range(n)]+[[float("inf")]]);import heapq as q;h=[];a=j=0 for i in range(t[0][0],m+1): while t[j][0]==i:q.heappush(h,-t[j][1]);j+=1 if h:a-=q.heappop(h) print(a)
n,m=list(map(int,input().split())) ab=[list(map(int,input().split()))for _ in range(n)]+[[100000000,0]] for i in range(m):ab.append([i+1,0]) ab.sort() from heapq import heappop,heappush h=[] j=0 ans=0 for i in range(1,m+1): while ab[j][0]<=i: heappush(h,-ab[j][1]) j+=1 ans-=heappop(h) print(ans...
p02948
from heapq import heappop,heappush n,m = list(map(int,input().split())) AB = [[int(i) for i in input().split()] for j in range(n)] #ab.sort() AB = sorted(AB, key=lambda x: x[0]) #print(ab) tmp = 0 hq = [] ans = 0 for i in range(1,m+1): while tmp <= n-1 and AB[tmp][0] <= i: heappush(...
import sys input = sys.stdin.readline import heapq import bisect n,m = list(map(int,input().split())) ab = [[int(i) for i in input().split()] for j in range(n)] ab.sort() a_li = [-1] * n b_li = [-1] * n for i in range(n): a_li[i] = ab[i][0] b_li[i] = ab[i][1] kouho = [] bfr_idx = 0 a...
p02948
import heapq class Reverse: def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __repr__(self): return repr(self.val) class Heapq: def __init__(self, arr, desc=False): if desc: for i in range(...
import heapq class Reverse: def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __repr__(self): return repr(self.val) class Heapq: def __init__(self, arr, desc=False): if desc: for i in range(...
p02948
from operator import itemgetter a,b=list(map(int,input().split())) c=[list(map(int,input().split())) for i in range(a)] c.sort() d=[] sum=0 e=0 for i in range(1,b+1): for j in range(e,a): if c[j][0]<=i: d.append(c[j][1]) else: e=j break d.sort() if len(d)>0: sum+=d[-1...
import heapq a,b=list(map(int,input().split())) c=[list(map(int,input().split())) for i in range(a)] c.sort() d=[[0]for i in range(b)] sum=0 for i,j in c: if i<=b: d[i-1].append(j) e=[] for i in d: for j in i: heapq.heappush(e,-j) sum-=heapq.heappop(e) print(sum)
p02948
import heapq def main(): n, m = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(n)] a_t = list(zip(*a)) a_s = set(a_t[0]) cnt = 0 h = [(l[1]*-1) for l in a if l[0] == 1] heapq.heapify(h) if 1 in a_s: cnt += heapq.heappop(h) for...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import heapq def main(): n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(n)] a_t = list(zip(*ab)) AB = [[] for _ in range(m+1)] ...
p02948
import heapq n,m = list(map(int, input().split())) job_list = [] for i in range(n): a,b = list(map(int, input().split())) job_list.append((a,b)) job_list.sort(key=lambda x:x[0]) # print(job_list) hq = [] max_income = 0 j = 0 for i in range(1,m+1): while j < n and job_list[j][0] <= i: ...
import sys import heapq input = sys.stdin.readline n,m = list(map(int, input().split())) job_list = [] for i in range(n): a,b = list(map(int, input().split())) job_list.append((a,b)) job_list.sort(key=lambda x:x[0]) # print(job_list) hq = [] max_income = 0 j = 0 for i in range(1,m+1): while ...
p02948
# 2019-11-16 14:51:41(JST) import sys import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float # ...
# 2019-11-16 14:51:41(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float ...
p02948
N,M = list(map(int,input().split())) from collections import defaultdict hist = defaultdict(int) AB = [[0,0]]*N for n in range(N): temp = list(map(int,input().split())) if temp[0] <= M: AB[n] = temp hist[temp[0]] = temp[0]-1 work_schedule = [0]*M sorted_AB = sorted(AB,key=lambda x:(-x[...
from collections import defaultdict import heapq n, m = list(map(int, input().split())) dct = defaultdict(list) for i in range(n): a, b = list(map(int, input().split())) dct[a].append(-b) h = [] res = 0 for i in range(1, m + 1): if dct[i]: for item in dct[i]: heapq.he...
p02948
from heapq import heapify, heappop nm = list(map(int, input().split())) n, m = nm[0], nm[1] d = {} ab_list = list() for i in range(n): ab = list(map(int, input().split())) rem_day, reward = ab[0], ab[1] if rem_day in d: d[rem_day].append(-reward) else: d[rem_day] = [-reward]...
from heapq import heapify, heappop, heappush nm = list(map(int, input().split())) n, m = nm[0], nm[1] d = {} ab_list = list() for i in range(n): ab = list(map(int, input().split())) rem_day, reward = ab[0], ab[1] if rem_day in d: d[rem_day].append(-reward) else: d[rem_day] =...
p02948
import heapq as hq N, M = list(map(int, input().split())) A = [] for i in range(N): a, b = list(map(int, input().split())) A.append([b * (-1), a * (-1)]) # print(A) ans = 0 Q = [] hq.heapify(Q) for i in range(1, M + 1): for j in (A): if j[1] * (-1) <= i: hq.heappus...
import heapq as hq N, M = list(map(int, input().split())) A = [] for i in range(N): a, b = list(map(int, input().split())) A.append([a, b * (-1)]) A.sort() # print(A) ans = 0 j = 0 Q = [] hq.heapify(Q) for i in range(1, M + 1): while j < len(A): if A[j][0] <= i: ...
p02948
N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] from operator import itemgetter AB.sort(key = itemgetter(0)) AB.sort(key = itemgetter(1),reverse = True) days = [0]*(M+1) points = list(range(M+1)) from bisect import bisect_right for a,b in AB: point = M ...
import heapq from operator import itemgetter def main(): N, M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] AB.sort(key = itemgetter(0)) heap = [] ans = 0 cnt = 0 for i in range(1,M + 1): while cnt < N and AB[cnt][0] <= i: ...
p02948
from heapq import* N,M,*t=list(map(int,open(0).read().split())) v=[[]for _ in range(M)] for i in range(N): if t[2*i]<=M: v[t[2*i]-1].append(t[2*i+1]) z=0 q=[] for i in range(M): for j in v[i]: heappush(q,-j) b=0 if len(q): b=heappop(q) z-=b print(z)
from heapq import* N,M,*t=list(map(int,open(0).read().split())) v=[[]for _ in range(M)] for i in range(N): if t[2*i]<=M:v[t[2*i]-1].append(t[2*i+1]) z=0 q=[] for i in range(M): for j in v[i]:heappush(q,-j) z-=len(q)and heappop(q) print(z)
p02948
from heapq import* N,M,*t=list(map(int,open(0).read().split())) v=[[]for _ in range(M)] for i in range(N): if t[2*i]<=M:v[t[2*i]-1].append(t[2*i+1]) z=0 q=[] for i in range(M): for j in v[i]:heappush(q,-j) z-=len(q)and heappop(q) print(z)
from heapq import* N,M,*t=list(map(int,open(0).read().split())) v=[[]for _ in'_'*M] for i in range(N): if t[2*i]<=M:v[t[2*i]-1].append(t[2*i+1]) z=0 q=[] for i in v: for j in i:heappush(q,-j) z-=len(q)and heappop(q) print(z)
p02948
from heapq import heappop, heappush N, M = list(map(int, input().split())) W = [] for i in range(N): a = list(map(int, input().split())) heappush(W, a) ans = 0 C = [] for i in range(1,M+1): j = -i while W != [] and W[0][0] <= i: a,b = heappop(W) heappush(C,-b) if C != []: ans...
from heapq import heappop, heappush import sys input = sys.stdin.readline N, M = list(map(int, input().split())) W = [] for i in range(N): a = list(map(int, input().split())) heappush(W, a) ans = 0 C = [] for i in range(1,M+1): j = -i while W != [] and W[0][0] <= i: a,b = heappop(W) ...
p02948
from heapq import heappop, heappush import sys input = sys.stdin.readline N, M = list(map(int, input().split())) W = [] for i in range(N): a = list(map(int, input().split())) heappush(W, a) ans = 0 C = [] for i in range(1,M+1): j = -i while W != [] and W[0][0] <= i: a,b = heappop(W) ...
from heapq import heappop, heappush import sys input = sys.stdin.readline N, M = list(map(int, input().split())) W = [list(map(int, input().split())) for i in range(N)] W.sort() ans = 0 C = [] for i in range(1,M+1): j = -i while W != [] and W[0][0] <= i: a,b = heappop(W) heappush(C,-b) ...
p02948
from heapq import heapify, heappush, heappop maxA = 10**5 N, M = list(map(int, input().split())) works = [[] for _ in range(maxA)] for _ in range(N): A, B = list(map(int, input().split())) works[A-1].append(-B) PQ = [] ans = 0 for dayRest in range(1, M+1): for B in works[dayRest-1]: ...
from heapq import heapify, heappush, heappop import sys input = sys.stdin.readline N, M = list(map(int, input().split())) ABs = [tuple(map(int, input().split())) for _ in range(N)] ABs.sort() PQ = [] iAB = 0 ans = 0 for rest in range(1, M+1): while iAB < N and ABs[iAB][0] <= rest: heappush(...
p02948
from heapq import heappop, heappush n,m = list(map(int,input().split())) byte = {} for i in range(n): a,b = list(map(int,input().split())) if a not in byte: byte[a] = [] heappush(byte[a], [-b,a]) ans = 0 res = [] for i in range(1, m+1): if i in byte: heappush(res, heappop...
from heapq import heappop, heappush n,m = list(map(int,input().split())) byte = {} for i in range(n): a,b = list(map(int,input().split())) if a > m: continue if a not in byte: byte[a] = [] heappush(byte[a], -b) ans = 0 res = [] for i in range(1, m+1): if i in byte: ...
p02948
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue class Scanner(): @staticmethod def...
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue class Scanner(): @staticmethod def...
p02948
#-*-coding:utf-8-*- import sys import heapq def pickup_job(tmp_jobs): tmp_jobs = sorted(tmp_jobs,key=lambda x:x[1],reverse=True) worked_job=heapq.heappop(tmp_jobs) return worked_job def main(): N,M = list(map(int, input().split())) job_datas = [list(map(int,input().split())) for _ in ...
#-*-coding:utf-8-*- import heapq def main2(): n,m=list(map(int,input().split())) jobs_list=[list(map(int,input().split())) for _ in range(n)] #breakするタイミングを作るため、Mより大きい値の仕事を作成 banpei_list=[[i,0] for i in range(1,m+2)] #リストの統合 jobs_list.extend(banpei_list) jobs_list=sorted(jobs_li...
p02948
import heapq n,m = list(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:...
import heapq n,m = list(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: heapq.heappush(q,-l[cnt][1]) cnt += 1 if len(q) ...
p02948
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().spli...
p02948
import heapq job = list() salary = list() n,m = list(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 = list(map(int,input().split())) job.append((a,b)) job =...
import heapq job = list() salary = list() n,m = list(map(int,input().split())) for i in range(n): a,b = list(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: ...
p02948
n, m = list(map(int, input().split())) data = [[int(e) for e in input().split()] for _ in range(n)] d1 = {} for i in range(n): a, b = data[i] if a not in d1: d1[a] = [] d1[a].append(b) result = 0 d2 = {} maxb = -1 for i in range(1, m + 1): if i in d1: for j in d1[i]: if j not in d2: ...
n, m = list(map(int, input().split())) d1 = {} for _ in range(n): a, b = list(map(int, input().split())) if a in d1: d1[a].append(b) else: d1[a] = [b] result = 0 d2 = {} maxb = -1 for i in range(1, m + 1): if i in d1: for j in d1[i]: if j not in d2: d2[j] = 0 d2[j...
p02948
def main(): _map = map _range = range _len = len _max = max _input = input _int = int n, m = _map(_int, _input().split()) d1 = {} for _ in _range(n): a, b = _map(_int, _input().split()) if a in d1: d1[a].append(b) else: d1[a] = [b] result = 0 d2 = {} maxb...
def main(): _map = map _range = range _len = len _max = max _input = input _int = int n, m = _map(_int, _input().split()) d1 = {} for _ in _range(n): a, b = _map(_int, _input().split()) if a in d1: d1[a].append(b) else: d1[a] = [b] result = 0 d2 = {} maxb...
p02948
n,m=list(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: ...
n,m=list(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: ...
p02948
n,m= list(map(int, input().split())) ab_list=[] for _ in range(n): a, b = list(map(int, input().split())) ab_list.append([a,b]) ab_list.sort() import heapq l = [] heapq.heapify(l) ind=0 ans=0 for i in range(1,m+1): while n>ind and ab_list[ind][0] <= i: heapq.heappush(l,-ab_list[ind]...
import sys input=sys.stdin.readline n,m= list(map(int, input().split())) ab_list=[] for _ in range(n): a, b = list(map(int, input().split())) ab_list.append([a,b]) ab_list.sort() import heapq l = [] heapq.heapify(l) ind=0 ans=0 for i in range(1,m+1): while n>ind and ab_list[ind][0] <= i:...
p02948
import heapq N, M = [int(_) for _ in input().split()] ABs = [[] for _ in range(M + 1)] r = 0 for i in range(N): A, B = [int(x) for x in input().split()] if A <= M: ABs[A].append(-B) for m in range(1, M + 1): B_max = -1 A_max = -1 heapq.heapify(ABs[m]) # print("{0}"....
import heapq N, M = [int(_) for _ in input().split()] ABs = [[] for _ in range(M + 1)] r = 0 for i in range(N): A, B = [int(x) for x in input().split()] if A <= M: ABs[A].append(-B) q = [] for m in range(1, M + 1): if ABs[m] != 0: for b in ABs[m]: heapq.heappu...
p02948
import sys from collections import defaultdict input = sys.stdin.readline n, m = list(map(int, input().split())) dic = defaultdict(list) total = 0 candidates = [] for i in range(n): a, b = list(map(int, input().split())) dic[a].append(b) for day in range(1, m+1): if day in dic: can...
import sys import heapq from collections import defaultdict input = sys.stdin.readline n, m = list(map(int, input().split())) dic = defaultdict(list) total = 0 candidates = [] heapq.heapify(candidates) for i in range(n): a, b = list(map(int, input().split())) dic[a].append(b) for day in range(...
p02948
N, M = list(map(int, input().split())) ABs = [0] * N for i in range(N): ABs[i] = list(map(int, input().split())) ABs = sorted(ABs, reverse=True, key=lambda x: x[1]) rewards = [0] * (M + 1) count = 0 for AB in ABs: day, reward = AB if day <= M: if rewards[day] == 0: rew...
N, M = list(map(int, input().split())) ABs = [0] * N day_dic = {} for i in range(N): ABs[i] = list(map(int, input().split())) ABs = sorted(ABs, reverse=True, key=lambda x: x[1]) rewards = [0] * (M + 1) count = 0 for AB in ABs: day, reward = AB if day <= M: if rewards[day] == 0: ...
p02948
import heapq N,M = list(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]*(-1))) if heap : ans -= (heapq.heapp...
import heapq N,M = list(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(h...
p02948
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 class PrimalDual: """ 最小費用流 ダイクストラ版 """ def __init__(self, graph=None, residual=None): """ ...
import heapq import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 N, M = list(map(int, sys.stdin.readline().split())) AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] ...
p02948
import heapq N,M = list(map(int,(input().split()))) A = [0]*N B = [0]*N mission = [[] for _ in range(M+1)] work = 0 for i in range(N): if i <= M: heapq.heapify(mission[i]) A[i],B[i] = list(map(int,(input().split()))) if A[i] <= M: mission[A[i]].append(-B[i]) for day in rang...
import heapq N,M = list(map(int,(input().split()))) A = [0]*N B = [0]*N mission = [[] for _ in range(M+1)] work = 0 for i in range(N): if i <= M: heapq.heapify(mission[i]) A[i],B[i] = list(map(int,(input().split()))) if A[i] <= M: mission[A[i]].append(-B[i]) for day in rang...
p02948
import sys from collections import defaultdict n, m = list(map(int, sys.stdin.readline().split())) a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] dic = defaultdict(list) for ele in a_b: dic[ele[0]].append(ele[1]) L =[] money = 0 for d in range(1, m+1): if dic[d]: L+=...
import sys import heapq from collections import defaultdict n, m = list(map(int, sys.stdin.readline().split())) a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] dic = defaultdict(list) for ele in a_b: dic[ele[0]].append(ele[1]) #print(dic) L =[] money = 0 for d in range(1, m+1): ...
p02948
import heapq as hq n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(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...
import heapq as hq n,m = list(map(int,input().split())) ab = [] for i in range(n): a,b = list(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 ...
p02948
import heapq n, m = list(map(int, input().split(' '))) df = [] for _ in range(n): x, y = list(map(int, input().split(' '))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m+1): while counter < len(df) and df[counter][0] <= i: heapq.heappush(h, (-1)*df[counter...
def main(): import heapq n, m = list(map(int, input().split(' '))) df = [] for _ in range(n): x, y = list(map(int, input().split(' '))) df.append([x, y]) df.sort() h = [] result = 0 counter = 0 for i in range(1, m+1): while counter < len(df) and df...
p02948
import heapq from collections import deque N, M=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(N)] AB.sort(key=lambda x:x[0]) d=deque(AB) h=[] ans=0 for i in range(M+1): while d and d[0][0]<=i: heapq.heappush(h, -d.popleft()[1]) if h: ans-=heapq.he...
import heapq from collections import defaultdict N, M = list(map(int, input().split())) d = defaultdict(list) for i in range(N): A, B = list(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]) ...
p02948
import heapq N, M = list(map(int, input().split())) W = [[] for _ in range(100005)] for i in range(N): A, B = list(map(int, input().split())) W[A].append(B) hq = [] ans, ct, idx = 0, 0, 0 for A in range(1, M+1): for B in W[A]: heapq.heappush(hq, -B) if hq: B = heapq.hea...
import heapq N, M = list(map(int, input().split())) W = [[] for _ in range(100005)] for i in range(N): A, B = list(map(int, input().split())) W[A].append(B) hq = [] ans = 0 for A in range(1, M+1): for B in W[A]: heapq.heappush(hq, -B) if hq: B = heapq.heappop(hq) ...
p02948
import heapq as pq N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(N)] day_to_reward = {} for a, b in AB: if day_to_reward.get(a) is None: day_to_reward[a] = [b] else: day_to_reward[a].append(b) ans = 0 candidate = [] for i in range(1...
import heapq as pq N, M = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(N)] day_to_reward = {} for a, b in AB: if day_to_reward.get(a) is None: day_to_reward[a] = [b] else: day_to_reward[a].append(b) ans = 0 candidate = [] for i in range(1...
p02948
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True) x = [0] * M cnt = 0 cntIN = M preB = 0 for a, b in AB: if preB != b: k = M i = min(M-a, k) while i>=...
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True) x = [0] * M p = [x for x in range(M)] cnt = 0 cntIN = M for a, b in AB: i = M-a s = [] while i >= 0 and p...
p02948
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True) x = [0] * M p = [x for x in range(M)] cnt = 0 cntIN = M for a, b in AB: i = M-a s = [] while i >= 0 and p...
N, M = list(map(int, input().split())) AB = [(a, b) for _ in range(N) for a, b in [list(map(int, input().split()))] if M - a >= 0] AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True) x = [0] * M p = [x for x in range(M)] cnt = 0 cntIN = M for a, b in AB: i = M-a ...
p02948
from heapq import * from collections import defaultdict n, m = list(map(int, input().split())) jobs = defaultdict(list) for _ in range(n): a, b = list(map(int, input().split())) jobs[a].append(-b) result = 0 pool = [] for i in range(1, m+1): for j in jobs[i]: heappush(pool, j) if...
import sys from collections import defaultdict from heapq import * sys.setrecursionlimit(10**8) input = sys.stdin.readline def main(): """ main """ N,M = list(map(int, input().split())) job_list = defaultdict(list) for _ in range(N): a, b = list(map(int, input().split())) ...
p02948
from heapq import heappop, heappush import sys input = sys.stdin.readline N, M = list(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): # M - i 日後にするバイトを考える while (j < N) and (X[j][0] <= i):...
from heapq import heappop, heappush N, M = list(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): # M - i 日後にするバイトを考える while (j < N) and (X[j][0] <= i): heappush(hq, -X[j][1]) # 候補の追加 ...
p02948
import heapq def main(): n, m = [int(e) for e in input().split()] AB = [[int(e) for e in input().split()] for i in range(n)] AB.sort(key=lambda x: x[0]) H = [] ans = 0 mi = 1 for a, b in AB: while a > mi: if len(H) > 0: heapq.heapify(H) ...
import heapq def main(): n, m = [int(e) for e in input().split()] AB = [[int(e) for e in input().split()] for i in range(n)] AB.sort(key=lambda x: x[0]) H = [] ans = 0 mi = 1 for a, b in AB: while a > mi: if len(H) > 0: ans += -heapq.heapp...
p02948
def main(): N,M=list(map(int,input().split())) job=[[0,0] for i in range(0,N)] for i in range(0,N): job[i][0],job[i][1]=list(map(int,input().split())) s=0 job=sorted(job,reverse=True) for i in range(0,M): for j in range(0,N): if job[j][0]>M-i: ...
import sys import heapq input=sys.stdin.readline N,M=list(map(int,input().split())) job={i:[] for i in range(1,M+1)} for i in range(0,N): a,b=list(map(int,input().split())) if M>=a: job[a].append(b) ans=0 ablejob=[] heapq.heapify(ablejob) for i in range(1,M+1): for j in job[i]: ...
p02948
#template def inputlist(): return [int(k) for k in input().split()] #template N,M = inputlist() li = [[] for _ in range(M+1)] for i in range(N): A,B = inputlist() B *= -1 if A > M: continue li[A].append(B) ans = 0 import heapq for i in range(1,M+1): if i >= 2: li[i] ...
#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 i in ...
p02948
#最終日から見る,残り日数条件を満たす中で最大収入のものを選ぶ import heapq N,M=list(map(int,input().split())) AB=[[0,0] for _ in range(N)] for i in range(N): AB[i][0],AB[i][1] = list(map(int,input().split())) AB.sort() ans=0 q=[] heapq.heapify(q) ne=0 #dは残り日数 for d in range(1,M+1): for i in range(ne,N): if AB[i...
#最終日から見る,残り日数条件を満たす中で最大収入のものを選ぶ import heapq N,M=list(map(int,input().split())) AB=[[0,0] for _ in range(N)] for i in range(N): AB[i][0],AB[i][1] = list(map(int,input().split())) AB.sort() ans=0 q=[] heapq.heapify(q) ne=0 #dは残り日数 for d in range(1,M+1): for i in range(ne,N): if AB...
p02948
from collections import defaultdict import heapq n, m = list(map(int, input().split())) m_dict = defaultdict(list) for i in range(n): a, b = list(map(int, input().split())) m_dict[a] = m_dict[a] + [b] job_que = [] total = 0 for j in range(1, m+1): for k in m_dict[j]: ...
import heapq n, m = list(map(int, input().split())) t_r_list = [] for i in range(n): t_r_list.append(list(map(int, input().split()))) t_r_list.sort() que = [] total = 0 l = 0 for j in range(1, m + 1): while True: if l == n: break if t_r_list[l][0] != j: ...
p02948
N,M = list(map(int, input().split())) L = [[int(a) for a in input().split()] for _ in range(N)] import heapq L.sort() h = [] ans = [0]*(M) i = 0 j = 0 d = 0 while i < M and d < M: i += 1 while j < N and L[j][0] <= i: heapq.heappush(h, [-L[j][1], L[j][0]]) j += 1 if h: ...
N,M = list(map(int, input().split())) L = [[int(l) for l in input().split()] for _ in range(N)] import heapq h = [] ans = 0 L.sort() m = 1 i = 0 while i < N and L[i][0] <= M: if L[i][0] == m: heapq.heappush(h, -L[i][1]) i += 1 else: m += 1 if h: ans -...
p02948
import heapq n,m=list(map(int,input().split())) arr=[list(map(int,input().split())) for _ in range(n)] arr2=[[i,0] for i in range(1,m+2)] #すべてのAi=1 to Mについて報酬0の仕事を追加する arr.extend(arr2) arr=sorted(arr,key=lambda x:x[0]) #Aiの小さい順にソート q=[] ans=0 pos=0 while 1: a,b=arr[pos] if a>m: #AiがMより大きければその仕事を請ける意味はない ...
'''tanon 優先度付きキュー t(=0 to M-1)日目に仕事を請けることを考えると、Ai>M-tなるiについては、 その仕事を請けるかどうかを考えなくて良い(∵この仕事を請けても、 Ai>M-t⇔Ai+t>Mより報酬はM日目より後にしかもらえません)。 したがって、tを大きい順に見ていくと、 M-1日目にはAi<=1なるiについて、報酬が最大となる仕事iを請けるべき、 M-2日目にはAi<=2なるiについて、まだ請けていない仕事の中で 報酬が最大となる仕事iを請けるべき、 …0日目にはAi<=Mなるiについて、まだ請けていない仕事の中で報酬が 最大となる仕事iを請けるべきであるといえます。 したがって...
p02948
#### import #### import sys import math from collections import defaultdict #### 設定 #### sys.setrecursionlimit(10**7) #### 定数 #### mod = 10**9 + 7 #### 読み込み #### def I(): return int(eval(input())) def II(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) def Li...
#### import #### import sys import math from collections import defaultdict #### 設定 #### sys.setrecursionlimit(10**7) #### 定数 #### mod = 10**9 + 7 #### 読み込み #### def I(): return int(eval(input())) def II(): return list(map(int, input().split())) def III(): return list(map(int, input().split())) def Li...
p02948
from bisect import bisect_left import sys input = sys.stdin.readline N, M = list(map(int, input().split())) AB = [[int(i) for i in input().split()] for _ in range(N)] AB.sort(key=lambda x: x[1], reverse=True) s = [i for i in range(1, M + 1)] ret = 0 for a, b in AB : if a > s[-1] : continue ...
from heapq import heappush, heappop N, M = list(map(int, input().split())) AB = [[] for _ in range(M+1)] for _ in range(N) : a, b = list(map(int, input().split())) if a <= M : AB[M-a].append(b) q = [] for a in range(M+1) : for b in AB[a] : heappush(q, b) if len(q...
p02948
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(in...
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return eval(input()) def i(): return int(eval(input())) def S(): return input().split() def I(): return list(map(int,input().split())) def L(): return list(in...
p02948
N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort() B = [[] for _ in range(100005)] tmp = 0 for ab in AB: if ab[0] != tmp: B[ab[0]] = B[tmp].copy() B[ab[0]].append(ab[1]) tmp = ab[0] for i in range(1, M + 1): if len(B[i]) == 0: B[i] =...
N, M = list(map(int, input().split())) AB = [] for i in range(N): ab = list(map(int, input().split())) if ab[0] <= M: AB.append(ab) AB.sort(reverse = True, key = lambda x:x[1]) ans = 0 for i in range(1, M + 1): for j in range(len(AB)): if AB[j][0] <= i: ans += AB.pop(j)[1] brea...
p02948
from heapq import heappush, heappop N, M = list(map(int, input().split())) AB = [] for i in range(N): ab = list(map(int, input().split())) #Ai > M の仕事はいらない if ab[0] <= M: AB.append(ab) #最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ... #終わりから考えればよさそう AB.sort() hq = [] ans = 0 for i in range(1, M + 1): w...
from heapq import heappush, heappop N, M = list(map(int, input().split())) jobs = [[] for _ in range(M)] for i in range(N): ab = list(map(int, input().split())) #Ai > M の仕事はいらない if ab[0] <= M: jobs[ab[0] - 1].append(ab[1]) #最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ... #終わりから考えればよさそう hq = [] ans = 0 for...
p02948
import heapq import bisect N, M = list(map(int, input().split())) ABs = [list(map(int, input().split())) for _ in range(N)] lists = [[] for _ in range(10**5 + 1)] availables = [] for A, B in ABs: bisect.insort(lists[A], B) ans = 0 for i in range(1, M + 1): availables = list(heapq.merge(availables,...
import heapq N, M = list(map(int, input().split())) ABs = [list(map(int, input().split())) for _ in range(N)] heapq.heapify(ABs) availables = [] ans = 0 for i in range(1, M + 1): while ABs: a = heapq.heappop(ABs) if a[0] == i: heapq.heappush(availables, -a[1]) else: ...
p02948
from heapq import heappush, heappop N, M = list(map(int, input().split())) Data = [list(map(int, input().split())) for _ in range(N)] heap = [0] * M ans = 0 for i in range(1, M+1): N = len(Data) for j in range(N-1, -1, -1): if (Data[j][0] <= i): heappush(heap, -(Data.pop(j)[1])) ...
from heapq import heappush, heappop N, M = list(map(int, input().split())) Data = [list(map(int, input().split())) for _ in range(N)] Data.sort(reverse = True) heap = [0] * M ans = 0 for i in range(1, M+1): N = len(Data) for j in range(N-1, -1, -1): if Data[j][0] > i: break ...
p02948
import heapq n, m = list(map(int, input().split())) dic = {} for i in range(n): a, b = list(map(int, input().split())) if a >= m+1: continue if a in list(dic.keys()): dic[a].append(b) else: dic[a] = [b] ans = 0 l = [] heapq.heapify(l) for j in range(1, m+1): ...
import heapq n, m = list(map(int, input().split())) memo = [[] for _ in range(m+1)] for _ in range(n): a, b = list(map(int ,input().split())) if a <= m: memo[a].append(-b) ans = 0 HQ = [] heapq.heapify(HQ) for i in range(1, m+1): for j in memo[i]: heapq.heappush(HQ, j) ...
p02948
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 #回答 indexlis...
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 #回答 j=0 f...
p02948
from collections import deque N, M = list(map(int, input().split())) ab_list = [ list(map(int, input().split())) for i in range(N)] score_list = [[] for i in range(M+1)] for ab in ab_list: if ab[0] <= M: score_list[ab[0]].append(ab[1]) scores = [deque() for i in range(M+1)] for i in rang...
import heapq N, M = list(map(int, input().split())) ab_list = [ list(map(int, input().split())) for i in range(N)] score_list = [[] for i in range(M+1)] for ab in ab_list: if ab[0] <= M: score_list[ab[0]].append(ab[1]) ans = 0 candidates = [] for i in range(0, M+1): for s in ...
p02948
from collections import defaultdict as dd from collections import deque n,m=list(map(int,input().split())) dic=dd(list) for i in range(1,m+1): dic[i]=[0]*m for i in range(n): a,b=list(map(int,input().split())) dic[a].append(b) for k,v in list(dic.items()): dic[k]=deque(sorted(dic[k],re...
from collections import defaultdict as dd from collections import deque n,m=list(map(int,input().split())) dic=dd(list) for i in range(1,m+1): dic[i]=[0] for i in range(n): a,b=list(map(int,input().split())) dic[a].append(b) for k,v in list(dic.items()): dic[k]=deque(sorted(dic[k],re...
p02948
import heapq from collections import defaultdict N,M = list(map(int,input().split())) AB = defaultdict(list) for i in range(N): a,b = list(map(int,input().split())) if a not in AB: AB[a] = [-b] else: AB[a] += [-b] work = 0 AB2 = [] for i in range(1,M+1): AB2 += AB[i] he...
import heapq from collections import defaultdict N,M = list(map(int,input().split())) AB = defaultdict(list) for i in range(N): a,b = list(map(int,input().split())) if a not in AB: AB[a] = [-b] else: AB[a] += [-b] work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): ...
p02948