input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
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): ...
import heapq N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): for j in AB[i]: heapq.heappush(AB2,j) if not AB2: ...
p02948
import heapq N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): for j in AB[i]: heapq.heappush(AB2,j) if len(AB2) >...
import sys import heapq input = sys.stdin.readline N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) work = 0 AB2 = [] heapq.heapify(AB2) for i in range(1,M+1): for j in AB[i]: ...
p02948
from heapq import heapify, heappush, heappop N,M = list(map(int,input().split())) AB = [] for i in range(N): a,b = list(map(int,input().split())) AB.append((-b,a)) heapify(AB) ans = 0 for i in range(1,M+1): rem = [] while True: if AB: ab = heappop(AB) if ab[1...
from heapq import heapify, heappush, heappop N,M = list(map(int,input().split())) AB = [[] for i in range(M+1)] for i in range(N): a,b = list(map(int,input().split())) if a <= M: AB[a].append(-b) AB2 = [] work = 0 heapify(AB2) for i in range(1,M+1): for j in AB[i]: heappush(AB2,j...
p02948
def main(): import heapq n,m = list(map(int,input().split())) alb = {} for i in range(n): a,b = list(map(int,input().split())) if a not in list(alb.keys()): alb[a] = [b] else: alb[a] += [b] h = [] s = 0 for i in range(1,m+1): ...
def main(): import heapq n,m = list(map(int,input().split())) jobs = {} for i in range(n): a,b = list(map(int,input().split())) if a not in list(jobs.keys()): jobs[a] = [b] else: jobs[a] += [b] ob = [] ans = 0 for i in range(1,m+1):...
p02948
import heapq n, m = list(map(int,input().split())) joblist = [] for i in range(n): a,b = list(map(int,input().split())) joblist.append([a,b]) joblist.sort(key=lambda x :x[0]) kouho = [] ans =0 for i in range(1,m+1): count=0 if joblist: for j,job in enumerate(joblist): ...
import heapq n, m = list(map(int,input().split())) joblist = {} for i in range(n): a,b = list(map(int,input().split())) if a in joblist: joblist[a].append(-1*b) else: joblist[a] = [-1*b] kouho = [] ans =0 for i in range(1,m+1): if i in joblist: for j in job...
p02948
import sys sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def LIST(): return [int(x) for x in input().split()] MOD = 10**9 + 7 N, M = LIST() A = [[] for _ in range(10**4+1)] for _ in range(N): a, b = LIST() if a <= M: A...
import sys import bisect sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def LIST(): return [int(x) for x in input().split()] MOD = 10**9 + 7 N, M = LIST() A = [[] for _ in range(10**4+1)] for _ in range(N): a, b = LIST() if a <...
p02948
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): re...
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): re...
p02948
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10 ** 5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect def main(): num, max_num = list(map(int, input().split())) data = [list(map(int, input().split())) for i in range(num)] data...
from collections import Counter, defaultdict import sys sys.setrecursionlimit(10 ** 5 + 10) input = sys.stdin.readline from math import factorial import heapq, bisect visit = [] def aaa(ind_lim, dame_num): global visit if ind_lim >= dame_num: return -1 elif visit[ind_lim] == -1: ...
p02948
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): r...
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): r...
p02948
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(eval(input())) def MAP(): r...
# -*- coding: utf-8 -*- import sys from heapq import heappush, heappop def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): re...
p02948
#!/usr/bin/env python import sys n,m= [ int(x) for x in sys.stdin.readline().split() ] baito=[ [] for _ in range(m) ] for _ in range(n): ai,bi = [ int(x) for x in sys.stdin.readline().split() ] ai-=1 if ai<m: baito[ai].append(bi) # tot=0 cur=[] for i in range(m): ref= baito[i] if re...
#!/usr/bin/env python import sys n,m= [ int(x) for x in sys.stdin.readline().split() ] baito=[ [] for _ in range(m) ] for _ in range(n): ai,bi = [ int(x) for x in sys.stdin.readline().split() ] ai-=1 if ai<m: baito[ai].append(bi) # for i in range(m): if baito[i]: baito[i].sort() # tot=0 ...
p02948
#!/usr/bin/env python import sys import heapq n,m= [ int(x) for x in sys.stdin.readline().split() ] baito=[ [] for _ in range(m) ] for _ in range(n): ai,bi = [ int(x) for x in sys.stdin.readline().split() ] ai-=1 if ai<m: baito[ai].append(-bi) # tot=0 cur=[] for i in range(m): ref= bait...
#!/usr/bin/env python import sys import heapq n,m= [ int(x) for x in sys.stdin.readline().split() ] baito=[ [] for _ in range(m) ] for _ in range(n): ai,bi = [ int(x) for x in sys.stdin.readline().split() ] ai-=1 if ai<m: baito[ai].append(-bi) # tot=0 cur=[] for i in range(m): ref= bait...
p02948
import heapq n, m = list(map(int, input().split())) byte = [[] for _ in range(100001)] for _ in range(n): a, b = list(map(int, input().split())) byte[a].append(b) search = [] day = 1 ans = 0 while day-1 != m: for b in byte[day]: heapq.heappush(search, -b) if not search: da...
import heapq n, m = list(map(int, input().split())) byte = [[] for _ in range(m+2)] for _ in range(n): a, b = list(map(int, input().split())) if a > m+1: continue byte[a].append(b) search = [] day = 1 ans = 0 while day-1 != m: for b in byte[day]: heapq.heappush(search, -b)...
p02948
# D - Summer Vacation 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]: he...
import sys from heapq import heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() works = [[] for _ in range(M+1)] # M-1日後から選んでいく, for _ in range(N): a, b = lr() if a > M: continue works[a].append(-b...
p02948
import sys from collections import deque sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() AB = [lr() for _ in range(N)] #Bが報酬 AB = [(a, b) for a, b in AB if a<=M] AB.sort(reverse=True, key=lambda x: x[1]) AB = deque(AB) answer = 0 us...
import sys from heapq import heappush, heappop sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() works = [[] for _ in range(M+1)] #Bが報酬 for _ in range(N): a, b = lr() if a <= M: works[a].append(b) cand = [] answer =...
p02948
import sys from heapq import heappush, heappop, merge, heapify sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() works = [[] for _ in range(M+1)] #Bが報酬 for _ in range(N): a, b = lr() if a <= M: works[a].append(-b) ca...
import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() jobs = [[] for _ in range(M+1)] for _ in range(N): a, b = lr() if a > M: continue jobs[a].append(b) answer...
p02948
from collections import defaultdict, deque import sys import math sys.setrecursionlimit(100000) MIN = -10 ** 9 MAX = 10 ** 9 + 7 def main(): # N = int(input()) N, M = [int(a) for a in input().split()] AB = [ [int(a) for a in input().split()] for _ in range(N) ] ...
from collections import defaultdict, deque import sys import heapq import math sys.setrecursionlimit(100000) MIN = -10 ** 9 MAX = 10 ** 9 + 7 def main(): # N = int(input()) N, M = [int(a) for a in input().split()] AB = [ [int(a) for a in input().split()] for _ in range(N)...
p02948
import sys, math, itertools, bisect, copy, re from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle # from functools import reduce # from math import ceil, floor, log10, log2, factorial # from pprint import pprint INF =...
import sys, math, itertools, bisect, copy, re from collections import Counter, deque, defaultdict from itertools import accumulate, permutations, combinations, takewhile, compress, cycle # from functools import reduce # from math import ceil, floor, log10, log2, factorial # from pprint import pprint import he...
p02948
import math, heapq from operator import itemgetter from collections import defaultdict INF = float("inf") MOD = int(1e9 + 7) N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] ab = sorted(AB) v, que = 0, [] for n in range(1, M + 1): while ab: a, ...
import math, heapq from operator import itemgetter from collections import defaultdict INF = float("inf") MOD = int(1e9 + 7) def main(): N, M = list(map(int, input().split())) AB = defaultdict(list) for _ in range(N): a, b = list(map(int, input().split())) AB[a].append(b) ...
p02948
import math, heapq from operator import itemgetter as ig from collections import defaultdict as dd # 定数 INF = float("inf") MOD = int(1e9 + 7) # ヒープ class heapque: def __init__(self, *args): self.que = [] for arg in args: self.push(arg) def push(self, v): heapq.he...
import math, heapq from operator import itemgetter as ig from collections import defaultdict as dd # 定数 INF = float("inf") MOD = int(1e9 + 7) # ヒープ class heapque: def __init__(self, *args): self.que = [] for arg in args: self.push(arg) def push(self, v): heapq.he...
p02948
import sys from collections import deque def main(): input = sys.stdin.readline N, M = list(map(int, input().split())) q = deque() for _ in range(N): a, b = list(map(int, input().split())) if a > M: continue q.append((a, b)) ans = 0 cnt = 1 ...
import sys from collections import defaultdict from heapq import heappop, heappush def main(): input = sys.stdin.readline 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) ans = 0 ...
p02948
import sys input = sys.stdin.readline def main(): n,m = list(map(int,input().split())) money = [[] for _ in range(10**5)] dp = [0] * m for _ in range(n): a,b = list(map(int,input().split())) money[a-1].append(b) max1 = [] for i in range(m): max1 += money[...
import sys import heapq imput = sys.stdin.readline def main(): n,m = list(map(int,input().split())) money = [[] for _ in range(10**5)] dp = [0] * m hq = [] heapq.heapify(hq) for _ in range(n): a,b = list(map(int,input().split())) money[a-1] += [b] for i in r...
p02948
import logging logging.basicConfig(level=logging.INFO, format="%(message)s") #logging.disable(logging.CRITICAL) def main(): N, M = list(map(int, input().split())) A_B = [list(map(int, input().split()))[::-1] for _ in range(N)] logging.info("Hello!") sorted_A_B = sorted(A_B, reverse=True) ...
import logging import heapq logging.basicConfig(level=logging.INFO, format="%(message)s") #logging.disable(logging.CRITICAL) def main(): N, M = list(map(int, input().split())) A_B = [list(map(int, input().split())) for _ in range(N)] logging.info("Hello!") A_B.sort() logging.info(A_...
p02948
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) n,m = inpl() aa = [[] for ...
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) n,m = inpl() aa = [[] for ...
p02948
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) n,m = inpl() aa = [[] for ...
from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue,datetime mod = 10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) ans = 0 hq = [] n,m = inp...
p02948
from collections import deque import sys input = sys.stdin.readline def main(): N,M = list(map(int,input().split())) paylist = [[] for _ in range(M)] for _ in range(N): a,b = list(map(int,input().split())) if M >= a: paylist[a-1].append(b) work = [] payment...
import heapq import sys input = sys.stdin.readline def main(): N,M = list(map(int,input().split())) paylist = [[] for _ in range(M)] for _ in range(N): a,b = list(map(int,input().split())) if M >= a: heapq.heappush(paylist[a-1],-b) work = [] payment = 0 ...
p02948
n,m = list(map(int,input().split())) lis = [[] for _ in range(10**5)] for _ in range(n): a,b = list(map(int,input().split())) lis[a-1].append(b) ans = 0 li = [] for i in range(m): li += lis[i] li.sort(reverse=True) try: ans += li[0] del(li[0]) except: continue print(ans)
from heapq import heappush,heappop,heapify n,m = list(map(int,input().split())) lis = [[] for i in range(m+1)] for _ in range(n): a,b = list(map(int,input().split())) if a <= m: lis[a].append(-b) ans = 0 num = [] heapify(num) for j in range(1,m+1): for nu in lis[j]: heapp...
p02948
import heapq n,m = list(map(int,input().split())) lb = [[] for _ in range(10**5+5)] for _ in range(n): a,b = list(map(int,input().split())) lb[a].append(b) res = 0 q = [] heapq.heapify(q) for i in range(1,m+1): for b in lb[i]: heapq.heappush(q,b * (-1)) if q: res += heapq....
import heapq def main(): n,m = list(map(int,input().split())) lb = [[] for _ in range(10**5+5)] for _ in range(n): a,b = list(map(int,input().split())) lb[a].append(b) res = 0 q = [] heapq.heapify(q) for i in range(1,m+1): for b in lb[i]: heapq...
p02948
#coding utf-8 import heapq N,M=list(map(int,input().split())) AB= [[int(i) for i in input().split()] for i in range(N)] work=[] heapq.heapify(work) ans=0 for i in range(1,M+1): for j in range(N): if AB[j][0]==i: heapq.heappush(work,-AB[j][1]) if work: tmp=heapq.heappop(work) ans-=tmp ...
#coding utf-8 import heapq N,M=list(map(int,input().split())) AB= [[int(i) for i in input().split()] for i in range(N)] AB.sort(reverse=True) work=[] heapq.heapify(work) ans=0 for i in range(1,M+1): while AB and AB[-1][0] <=i: tmp=AB.pop() heapq.heappush(work,-tmp[1]) if work: tmp=heapq...
p02948
# -*- coding: utf-8 -*- """ Created on Sun Apr 12 02:06:07 2020 @author: Kanaru Sato """ import heapq n,m = list(map(int, input().split())) albeit = [] for i in range(m+1): albeit.append([]) for i in range(n): a,b = list(map(int, input().split())) if a <= m: albeit[a].append(-1*...
# -*- coding: utf-8 -*- """ Created on Sun Apr 12 02:06:07 2020 @author: Kanaru Sato """ import heapq n,m = list(map(int, input().split())) albeit = [] for i in range(m+1): albeit.append([]) for i in range(n): a,b = list(map(int, input().split())) if a <= m: albeit[a].append(-1*...
p02948
import heapq n, m = list(map(int, input().split())) ba=[] for i in range(n): a, b = list(map(int, input().split())) ba.append([-b, a]) heapq.heapify(ba) ans=0 for i in range(m - 1, -1, -1): not_use = [] while ba: l = heapq.heappop(ba) if l[1] + i <= m: ans ...
import heapq n, m = list(map(int, input().split())) l = [[] for _ in range(m)] for i in range(n): a, b = list(map(int, input().split())) if a <= m: l[a-1].append(b) a = [] ans = 0 for i in range(m): for j in l[i]: heapq.heappush(a, (-1) * j) if a: ans += hea...
p02948
import heapq n ,m = list(map(int,input().split())) li = [] for i in range(n): x, y= list(map(int,input().split())) li.append([x,y]) li.sort() heap = [] ans = 0 for i in range(m): bar = True while bar: if len(li) == 0: break if i >= li[0][0] - 1: ...
import heapq n ,m = list(map(int,input().split())) li = [] for i in range(n): x, y= list(map(int,input().split())) li.append([x,y]) li.sort() heap = [] ans = 0 j = 0 for i in range(1, m + 1): while j < n and li[j][0] <= i: heapq.heappush(heap,-li[j][1]) j += 1 if heap: ...
p02948
n,m = list(map(int,input().split())) work = [list(map(int, input().split())) for i in range(n)] from operator import itemgetter work = sorted(work,key=itemgetter(1),reverse=True) count = 0 for i in range(1,m+1): for j in range(len(work)): if work[j][0] <= i: count += work[j][1] del work[j] ...
import heapq n,m = list(map(int,input().split())) a = [0] * n b = [0] * n info = [[] for _ in range(m+1)] for i in range(n): a[i], b[i] = list(map(int,input().split())) if a[i] <= m: info[a[i]].append(b[i]) l = [] count = 0 for j in range(1,m+1): for x in info[j]: heap...
p02948
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] pay_list = [] heapq.heapify(pay_list) ans = 0 for i in range(1, M+1): # 実行可能なバイトリストを抽出 for j in range(len(AB)-1, -1, -1): a = AB[j][0] b = AB[j][1] if a <= i: ...
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] pay_list = [] heapq.heapify(pay_list) ans = 0 # AB = sorted(AB, key=lambda x: x[0]) AB = sorted(AB, reverse=True) for i in range(1, M+1): # 実行可能なバイトリストを抽出 for j in range(len(AB)-1, -1, -1):...
p02948
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] pay_list = [] heapq.heapify(pay_list) ans = 0 # AB = sorted(AB, key=lambda x: x[0]) AB = sorted(AB, reverse=True) for i in range(1, M+1): # 実行可能なバイトリストを抽出 for j in range(len(AB)-1, -1, -1):...
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] pay_list = [] heapq.heapify(pay_list) ans = 0 AB = sorted(AB, reverse=True) for i in range(1, M+1): # 実行可能なバイトリストを抽出 for j in range(len(AB)-1, -1, -1): a = AB[j][0] b = AB[...
p02948
N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] import heapq AB.sort() heap = [] heapq.heapify(heap) ans = 0 i = 0 day = 1 while day <= M: while i < N and AB[i][0] <= day: heapq.heappush(heap,-AB[i][1]) i += 1 day += 1 if not(heap)...
import heapq N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range (N)] AB.sort() ans = 0 q = [] heapq.heapify(q) idx = 0 for i in range(1,M+1): while idx<N and AB[idx][0]<=i: heapq.heappush(q, -AB[idx][1]) idx += 1 if q: p = -heapq....
p02948
import collections N,M = list(map(int,input().split())) allhiyatoi = [[] for j in range(M+1)] for i in range(N): temp = list(map(int,input().split())) if temp[0] > M: continue allhiyatoi[temp[0]].append(temp[1]) temp = [] for i in allhiyatoi: temp.append(collections.deque(so...
from heapq import heappush, heappop N,M = list(map(int,input().split())) allhiyatoi = [[] for j in range(M+1)] for i in range(N): temp = list(map(int,input().split())) if temp[0] > M: continue allhiyatoi[temp[0]].append(temp[1]) reward = 0 Q = [] for i in allhiyatoi: for j in ...
p02948
#解説の方法 N,M = list(map(int,input().split())) AB = [[] for _ in range(10**5+1)]#報酬振り込み日数ごとに報酬を格納 for _ in range(N): a,b = list(map(int,input().split())) AB[a].append(b) q = [] ans =0 for i in range(1,M+1): q += AB[i]#後ろから見るイメージ 残りi日で請けれる仕事をリストに追加する if len(q)>0: q.sort() ans += ...
import heapq #解説の方法 N,M = list(map(int,input().split())) AB = [[] for _ in range(10**5+1)]#報酬振り込み日数ごとに報酬を格納 for _ in range(N): a,b = list(map(int,input().split())) AB[a].append(-b) q = [] heapq.heapify(q) ans =0 for i in range(1,M+1): for b in AB[i]: heapq.heappush(q,b) if len(q)>0:...
p02948
class Job(object): def __init__(self, day, reward): self.day = day self.reward = reward self.is_used = False class MyJobs(object): def __init__(self, num_elements_in_array): self.heapm = {} def append(self, priority, value): if not priority in list(se...
import heapq (n, m) = list(map(int, input().split())) jobs = {} for _ in range(n): (a, b) = list(map(int, input().split())) if not a in jobs: jobs[a] = [] jobs[a].append(-b) heap = [] sum = 0 for i in range(1, m + 1): if i in jobs: for j in jobs[i]: heapq.hea...
p02948
from queue import PriorityQueue N, M = list(map(int, input().split())) # N件の仕事, M日後までに得られる報酬 jobs = [[] for _ in range(M)] # 締め切りごとに仕事を格納する二重配列 for i in range(N): # N件の仕事を見て行く a, b = list(map(int, input().split())) if a > M: # a日後にもらえる、そのaが期日のMよりも大きかったらスルー continue jobs[M-a].append(b)...
from queue import PriorityQueue N, M = list(map(int, input().split())) # N件のアルバイト, M日後までに欲しい jobs_list = [[] for _ in range(M+1)] for i in range(N): a, b = list(map(int, input().split())) if a > M: # M日後にもらえる仕事ならok continue jobs_list[a].append(b) pq = PriorityQueue() ans = 0 fo...
p02948
N, M = list(map(int, input().split())) AB = {} for _ in range(N): a, b = list(map(int, input().split())) if a in AB: AB[a].append(b) else: AB[a] = [b] count = 0 current = [] for day in range(1, M + 1): if day in AB: current.extend(AB[day]) current.sort(...
import heapq N, M = list(map(int, input().split())) AB = {} for _ in range(N): a, b = list(map(int, input().split())) if a in AB: AB[a].append(b) else: AB[a] = [b] count = 0 current = [] for day in range(1, M + 1): if day in AB: for work in AB[day]: h...
p02948
import bisect n,m = list(map(int,input().split())) data = [tuple(map(int,input().split())) for i in range(n)] data.sort(key = lambda tup:tup[0]) salary =[] ans=0 prev=0 memo=0 for day in range(m): for i in range(memo,n): if data[memo][0]<=(day+1): bisect.insort(salary,data[memo][1]) # salary.append...
import heapq n,m = list(map(int,input().split())) AB =[tuple(map(int,input().split())) for i in range(n)] ans,memo=0,0 hq=[] AB.sort(key=lambda tup:tup[0]) for day in range(m): for i in range(memo,n): if AB[i][0]<=(day+1): heapq.heappush(hq,-AB[i][1]) memo+=1 else: break if len(hq): ans ...
p02948
import heapq N, M = list(map(int, input().split())) AB = {} q = [] ans = 0 for i in range(N): A, B = list(map(int, input().split())) if A in AB: AB[A].append(-B) else: AB[A] = [-B] for i in range(1, M+1): if i in AB: for B in AB[i]: heapq.hea...
import sys from heapq import heappush, heappop input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) A, B = [[] for i in range(M)], [] for i in range(N): a, b = list(map(int, input().split())) if a > M: continue A[a-1].append(-b) ...
p02948
from heapq import* (N,M),*t=[list(map(int,s.split()))for s in open(0)] z,*q=[0]*99*M v=[[]for _ in q] 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)] z,*q=[0]*50*M v=[[]for _ in q] 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
from heapq import* (N,M),*t=[list(map(int,s.split()))for s in open(0)] z,*q=[0]*50*M v=[[]for _ in q] for a,b in t:v[a-1]+=b, for i in v[:M]:[heappush(q,-j)for j in i];z-=heappop(q) print(z)
from heapq import* (N,M),*t=[list(map(int,s.split()))for s in open(0)] q=[0]*50*M v=[[]for _ in q] for a,b in t:v[a-1]+=b, print((sum(([heappush(q,-j)for j in i],-heappop(q))[1]for i in v[:M])))
p02948
from collections import deque N, M = list(map(int,input().split())) class WorkList: def __init__(self): self.payList = [[] for _ in range(10001)] self.payList_sorted = [] def add(self, a, b): if a <= M: self.payList[10001 - b].append(a) def sort_task(self...
import bisect from collections import deque N, M = list(map(int,input().split())) work = [list(map(int,input().split())) for _ in range(N)] wq = deque(sorted(work)) paytree = [] ans = 0 for day in range(M + 1): while len(wq) > 0 and wq[0][0] <= day: bisect.insort_right(paytree,wq.poplef...
p02948
import bisect from collections import deque N, M = list(map(int,input().split())) work = [list(map(int,input().split())) for _ in range(N)] wq = deque(sorted(work)) paytree = [] ans = 0 for day in range(M + 1): while len(wq) > 0 and wq[0][0] <= day: bisect.insort_left(paytree,wq.p...
import heapq from collections import deque N, M = list(map(int,input().split())) work = [list(map(int,input().split())) for _ in range(N)] wq = deque(sorted(work)) paytree = [] ans = 0 for day in range(M + 1): while len(wq) > 0 and wq[0][0] <= day: heapq.heappush(paytree, wq.popleft()[1...
p02948
N, M = [int(x) for x in input().split()] AB = [0] * N for i in range(N): A, B = [int(x) for x in input().split()] AB[i] = (A, B) # 期間が短い報酬が高い def key(ab): a, b = ab return -b, a AB = sorted(((a, b) for a, b in AB if a <=M), key=key) #print(BA) def calc(jobs, M): m = 0 for d, (...
import heapq N, M = [int(x) for x in input().split()] AB = [0] * N for i in range(N): AB[i] = [int(x) for x in input().split()] AB = sorted(AB) jobs = set() answer = 0 nextpush = 0 candidates = [] for day in range(M)[::-1]: while nextpush < N: a, b = AB[nextpush] if day + ...
p02948
import heapq N, M = [int(x) for x in input().split()] AB = [0] * N for i in range(N): AB[i] = [int(x) for x in input().split()] AB = sorted(AB) jobs = set() answer = 0 nextpush = 0 candidates = [] for day in range(M)[::-1]: while nextpush < N: a, b = AB[nextpush] if day + ...
# 優先度キューを使う import heapq N, M = [int(x) for x in input().split()] AB = [0] * N for i in range(N): AB[i] = [int(x) for x in input().split()] # 毎日、候補となる集合を再計算すると間に合わない # M-1日後から当日に向けて計算してけば、 # day 日時点で day + a = M となる仕事だけを候補に追加することで # day + 1日までに追加した候補を再利用できる。 # さらに、候補からpopした要素は次回から考慮しないため、設問の条件とも一致する...
p02948
import heapq n, m = list(map(int, input().split())) baitos = [] for _ in range(n): baitos.append(list(map(int, input().split()))) baitos = sorted(baitos) # print(sorted(baitos)) # print(baitos) money = 0 avail = [] heapq.heapify(avail) for day in range(m): while baitos: if baitos[0][0...
import heapq n, m = list(map(int, input().split())) baitos = [list(map(int, input().split())) for _ in range(n)] baitos = sorted(baitos) # print(sorted(baitos)) # print(baitos) money = 0 avail = [] # heapq.heapify(avail) index = 0 for day in range(m): while index < n and baitos[index][0] <= day + 1...
p02948
def slove(): import sys, heapq input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) ab = [] for i in range(n): a, b = list(map(int, input().rstrip('\n').split())) ab.append([a, b]) heapq.heapify(ab) s_q = [] heapq.heapify(s_q) d = ...
def slove(): import sys, heapq input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] heapq.heapify(ab) s_q = [] heapq.heapify(s_q) r = 0 for d in range(1, m + 1): while Tr...
p02948
def slove(): import sys, heapq input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] heapq.heapify(ab) s_q = [] heapq.heapify(s_q) r = 0 for d in range(1, m + 1): while Tr...
def slove(): import sys import heapq input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) l = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] r = [] heapq.heapify(l) heapq.heapify(r) t = 0 for i in range(m + 1): while ...
p02948
def slove(): import sys import heapq input = sys.stdin.readline n, m = list(map(int, input().rstrip('\n').split())) ls =[] v = [] heapq.heapify(v) for i in range(n): a, b = list(map(int, input().rstrip('\n').split())) ls.append([a, b]) ls.sort(reverse=True)...
import sys import heapq def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n, m = list(map(int, input().rstrip('\n').split())) ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)] ab.sort(reverse=True) ls = [] heapq.heapify(ls) t = 0 for i in ra...
p02948
import heapq from collections import defaultdict def main(): N, M = list(map(int, input().split())) ans = 0 d = defaultdict(list) for _ in range(N): A, B = list(map(int, input().split())) d[A].append(-B) cand = [] heapq.heapify(cand) for day in range(M-1,-1,-1): ...
import heapq from collections import defaultdict def main(): N, M = list(map(int, input().split())) ans = 0 d = defaultdict(list) for _ in range(N): A, B = list(map(int, input().split())) d[A].append(-B) cand = [] heapq.heapify(cand) for day in range(M-1,-1,-1): ...
p02948
from collections import defaultdict n, m = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for i in range(n)]) c = [[]] * m a, b = ab[0] last = a ad = [b] for i in range(1, n): a, b = ab[i] if a == last: ad.append(b) else: if last <= m: ...
import heapq n, m = list(map(int, input().split())) ab = sorted([list(map(int, input().split())) for i in range(n)]) c = [[]] * m a, b = ab[0] last = a ad = [b] for i in range(1, n): a, b = ab[i] if a == last: ad.append(b) else: if last <= m: c[last - 1] = ad ...
p02948
import bisect n,m=list(map(int,input().split())) l=[[] for _ in range(m)] for _ in range(n): a,b=list(map(int,input().split())) if a<=m: l[a-1].append(b) ans=0 w=[] for i in range(m): for j in l[i]: bisect.insort_right(w,j) if w!=[]: ans+=w.pop(-1) print(ans)
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())) if a<=m: l[a-1].append(b) ans=0 w=[] for i in range(m): for j in l[i]: heapq.heappush(w,-j) if w!=[]: ans-=heapq.heappop(w) print(ans)
p02948
# -*- coding: utf-8 -*- """ D - Summer Vacation https://atcoder.jp/contests/abc137/tasks/abc137_d """ import sys from heapq import heapify, heappop from bisect import bisect_left def solve(N, M, jobs): days = [d for d in range(1, M+1)] heapify(jobs) ans = 0 while jobs: B, A ...
# -*- coding: utf-8 -*- """ D - Summer Vacation https://atcoder.jp/contests/abc137/tasks/abc137_d """ import sys from heapq import heapify, heappop, heappush def solve(N, M, jobs): heapify(jobs) availables = [] ans = 0 for day in range(1, M+1): while jobs and jobs[0][0] <= da...
p02948
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heapify, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, read...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heapify, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, read...
p02948
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heapify, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, read...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, readline().sp...
p02948
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, readline().sp...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush def main(): N, M = list(map(int, readline().split())) tasks = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, readline().sp...
p02948
from operator import itemgetter N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort(reverse=True, key=itemgetter(1)) res = [0 for _ in range(M)] for i, (a, b) in enumerate(AB): p = M - a while p >= 0 and res[p] != 0: p -= 1 if p >=...
import heapq N, M = list(map(int, input().split())) AB = [[] for _ in range(M)] for _ in range(N): a, b = list(map(int, input().split())) if a - 1 < M: AB[a - 1].append(-b) res = 0 cand = [] for i in range(M): AB[i].sort(reverse=True) for b in AB[i]: heapq.heappush(...
p02948
n,m = list(map(int,input().split())) from collections import defaultdict dic = defaultdict(list) l = [] for i in range(n): a,b=list(map(int,input().split())) dic[a].append(b) s = 0 t = [0] for i in range(m): t += dic[i+1] if len(t) ==0 : M = 0 else: M = max(t) s +=M ...
n,m = list(map(int,input().split())) import heapq from collections import defaultdict dic = defaultdict(list) l = [] heapq.heapify(l) for i in range(n): a,b=list(map(int,input().split())) b = -b dic[a].append(b) s = 0 t = [0] for i in range(m): for i in dic[i+1]: heapq.heappush(l,i...
p02948
from operator import itemgetter n, m = list(map(int, input().split())) abab = [list(map(int, input().split())) for _ in range(n)] abab = sorted(sorted(abab, key=itemgetter(0), reverse=True), key=itemgetter(1), reverse=True) gyara = [0 for _ in range(m+1)] for a, b in abab : for i in range(a, m+1) : ...
from heapq import * n, m = list(map(int, input().split())) abab = [list(map(int, input().split())) for _ in range(n)] bites = [[] for _ in range(m)] for a, b in abab : if a <= m : bites[a-1].append(-b) ans = 0 board = [] for bite in bites: for b in bite : heappush(board, b) if board : ans ...
p02948
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...
from heapq import heappush, heappop n, m = list(map(int, input().split())) jobs = {} for _ in range(n): a, b = list(map(int, input().split())) if a > m: continue if a in jobs: jobs[a].append(b) else: jobs[a] = [b] result = 0 candidates = [] for a in range(1, m + 1): if a in jobs: ...
p02948
from heapq import heappush, heappop n, m = list(map(int, input().split())) jobs = {} for _ in range(n): a, b = list(map(int, input().split())) if a > m: continue if a in jobs: jobs[a].append(b) else: jobs[a] = [b] result = 0 candidates = [] for a in range(1, m + 1): if a in jobs: ...
from heapq import heappop, heappush import sys input = sys.stdin.readline def calculate(N,M,arr): ret = 0 j = 0 res = [] # 1,2,3,4,5 # ↑ # 4,3,2,1 # M = 4 # range(1,5) => 1,2,3,4 for i in range(1,M+1): # i = 1,2,3 # 比如M=4的话,第三天(最多1天),...
p02948
#Binary Indexed Tree (1-index!!!!!!!!) class BinaryIndexedTree(): def __init__(self, size): self.__node = [0] * (size+1) self.size = size #node[index]にvalueを足して、BITを更新 O(logN) def add(self, index, value): while index <= self.size: self.__node[index] += value ...
import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict from itertools import accumulate,permutations,combinations,product,combinations_with_replacement ...
p02948
n, m = list(map(int, input().split(" "))) xys = [tuple(map(int, input().split(" "))) for i in range(n)] xys = sorted(xys, key=lambda x: (-x[0], x[1])) dp = [[0 for x in range(m)] for y in range(n)] for i in range(n): a, b = xys[i] # print(i, a, b) if i == 0: for j in range(0, m - a + 1):...
n, m = list(map(int, input().split(" "))) xys = [tuple(map(int, input().split(" "))) for i in range(n)] xys = sorted(xys, key=lambda x: (x[0], -x[1])) ans = 0 for i in range(1, m + 1): cm = -1 cmi = -1 for j in range(len(xys)): if xys[j][0] <= i and xys[j][1] > cm: cm = xys[...
p02948
n,m=list(map(int,input().split())) l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[x[0],-x[1]])+[[float('inf'),0]] for i in range(n):l[i][0]-=1 w=[n]*m for i in range(m): j=0 while l[j][0]<=i: if l[j][1]>l[w[i]][1] and j not in w: w[i]=j j+=1 print((s...
from heapq import heappop, heappush n,m=list(map(int,input().split())) a=[] for i in range(n): heappush(a,list(map(int,input().split()))) heap=[] s=0 for i in range(m): while 1: if len(a)==0:break else: if a[0][0]==i+1:heappush(heap,-heappop(a)[1]) else:brea...
p02948
import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) mod = 10**9+7 Max = sys.maxsize def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in ra...
import sys,collections as cl,bisect as bs,heapq as hq sys.setrecursionlimit(100000) mod = 10**9+7 Max = sys.maxsize def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] ...
p02948
import heapq N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] d_AB = {a:[] for a,b in AB} for a,b in AB: d_AB[a].append(-b) H = [] money = 0 for i in range(1,M+1): if i in list(d_AB.keys()): H += d_AB[i] else: H += [0] #pri...
import heapq N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] d_AB = {a:[] for a,b in AB} for a,b in AB: d_AB[a].append(-b) #print(d_AB) H = [] heapq.heapify(H) money = 0 for i in range(1,M+1): if i in list(d_AB.keys()): for ab in d_AB[i]: ...
p02948
N, M = list(map(int, input().split())) AB = {} for i in range(N): a, b = list(map(int, input().split())) if a in list(AB.keys()): AB[a].append(b) else: AB[a] = [b] dp = [0] * (M+1) for i in range(1, M+1): tmp = 0 km = -1 tm = -1 for k in range(i+1): if k...
from heapq import heappush, heappop N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N)] AB.sort(reverse=True) hp = [] ret = 0 for i in range(1, M+1): # push while len(AB) > 0 and AB[len(AB)-1][0] <= i: heappush(hp, AB.pop()[1]*-1) # pop if l...
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())) c=[list(map(int,input().split())) for i in range(n)] ans, available = 0, [] heapq.heapify(available) heapq.heapify(c) for i in range(1, m+1): while len(c)!=0 and c[0][0]<=i: now = heapq.heappop(c) heapq.heappush(available,-now[1]) if len(...
p02948
from operator import itemgetter n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] d = [0] * (m+1) ab.sort(key=itemgetter(1), reverse=True) for a, b in ab: x = m - a while x >= 0: if d[x] == 0: d[x] = b break ...
from heapq import heappop, heappush n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(n)] h = [] ans = 0 ab.sort() i = 0 for d in range(1, m+1): while i < n: if ab[i][0] <= d: heappush(h, - ab[i][1]) i += 1 else: ...
p02948
import heapq N, M = list(map(int, input().split())) rewards = [None] * N for i in range(N): a, b = list(map(int, input().split())) rewards[i] = (b, a) heap = [] total = 0 for day in range(1, M + 1): target_rewards = list([x for x in rewards if (day - 1) < x[1] <= day]) for reward in targ...
import heapq N, M = list(map(int, input().split())) rewards = [[] for _ in range(M + 1)] for i in range(N): a, b = list(map(int, input().split())) if a <= M: rewards[a].append(b) heap = [] total = 0 for day in range(1, M + 1): for reward in rewards[day]: heapq.heappush(heap, -...
p02948
import bisect 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() day = 1 i = 0 maxi = [] ans = 0 while day <= M: if i < N and AB[i][0] == day: ind = bisect.bisect_left(maxi,AB[i][1]) ...
import heapq 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() day = 1 i = 0 lis = [] ans = 0 while day <= M: if i < N and AB[i][0] == day: heapq.heappush(lis,-1 * AB[i][1]) i +=...
p02948
def work(l): l.sort(key=lambda x:x[1],reverse=True) salary = l.pop(0) return salary[1] n,m = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(n)] queue = [] ans = 0 i = 0 while i < m: i += 1 for j in range(len(a)): if a[j][0] == i: ...
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) #解法 rewards = 0 heap = [] for i in range(M): for reward in jobs[i]: heapq.heappush(heap, reward) ...
p02948
import sys import heapq N, M = list(map(int, input().split())) jobs = [] for line in sys.stdin: A, B = list(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: ...
import sys import heapq N, M = list(map(int, input().split())) possiblyValidJobs = {} for line in sys.stdin: A, B = list(map(int, line.split())) if A > M: continue if A in possiblyValidJobs: possiblyValidJobs[A].append(B) else: possiblyValidJobs[A] = [B] validJo...
p02948
import heapq N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(N)] ab = sorted(ab, key=lambda x:x[0]) day = 0 pay = 0 q = [] for i in range(1, M+1): for j in range(len(ab)): if ab[0][0] <= i: a, b = ab.pop(0) heapq.heappush(q, (-b, a)) else: ...
import heapq N, M = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(N)] day = {i+1: [] for i in range(M)} for a, b in ab: if a <= M: day[a] += [-b] q = [] heapq.heapify(q) pay = 0 for i in range(M): for b in day[i+1]: heapq.heappush(q, b) if len(q) > 0: ...
p02948
import heapq import copy N,M = list(map(int,input().split())) baito = [] for i in range(N): baito.append(list(map(int, input().split()))) baito.sort(key=lambda x: x[0]) que = [] ans = 0 for i in range(1, M+1): tmp = copy.copy(baito) for val in baito: if val[0] <= i: ...
import heapq N,M = list(map(int,input().split())) baito = [[] for i in range(M+1)] for i in range(N): A,B = list(map(int,input().split())) if A <= M: baito[A].append(B) que = [] ans = 0 for i in range(1, M+1): if len(baito[i]) != 0: for val in baito[i]: heapq.he...
p02948
from heapq import heapify, heappop, heappush N,M = list(map(int, input().split())) AB = [] for i in range(N): a,b = list(map(int, input().split())) if a<=M: AB.append((a,-b)) else: N-=1 AB.sort() Q = [] heapify(Q) ans = 0 i = 0 for day in range(M): while i<N and AB[i][...
from heapq import heapify, heappop, heappush 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() Q = [] ans = 0 i = 0 for day in range(M): while i<N and AB[i][0] == day+1: heappush(Q, AB[i][1]) i+...
p02948
import collections import heapq inputs = [int(x) for x in input().split()] n, m = inputs[0], inputs[1] conditions = {} for i in range(n): inputs = [int(x) for x in input().split()] if inputs[0] in list(conditions.keys()): conditions[inputs[0]].append(inputs[1]) else: conditions[inputs[0]] = ...
import collections import heapq inputs = [int(x) for x in input().split()] n, m = inputs[0], inputs[1] conditions = collections.deque([]) for i in range(n): conditions.append([int(x) for x in input().split()]) conditions = sorted(conditions) cnt, ans = 0, 0 candidates = [] for reversed_day in range(...
p02948
import queue N, M = list(map(int, input().split())) AB = [[] for _ in range(M + 1)] for n in range(N): a, b = list(map(int, input().split())) if a > M: continue AB[a].append(0-b) earn = 0 q = queue.PriorityQueue() for m in range(1, M + 1): for job in AB[m]: q.put(jo...
import heapq N, M = list(map(int, input().split())) AB = [[] for _ in range(M + 1)] for n in range(N): a, b = list(map(int, input().split())) if a > M: continue AB[a].append(0-b) earn = 0 q = [] for m in range(1, M + 1): for job in AB[m]: heapq.heappush(q, job) ...
p02948
N, M = list(map(int, input().split())) from collections import deque AB = deque(sorted([list(map(int, input().split())) for i in range(N)])) from heapq import * q = [] heapify(q) ans = 0 remain_days = 1 while remain_days <= M: for a, b in list(AB): if a <= remain_days: heappush(q, -...
N, M = list(map(int, input().split())) jobs = sorted([list(map(int, input().split())) for i in range(N)], reverse=True) from heapq import * q = [] heapify(q) ans = 0 for i in range(1, M+1): while jobs and jobs[-1][0] <= i: heappush(q, -1*jobs.pop()[1]) if q: ans += -1 * heappop(q) p...
p02948
import heapq N, M = list(map(int, input().split())) w = [[] for i in range(M)] for i in range(N): a, b = list(map(int, input().split())) try: w[a-1].append(-b) except: pass ans = 0 a = [] for i in range(M): a += w[i] heapq.heapify(a) try: ans += -heapq.heap...
import heapq N, M = list(map(int, input().split())) w = [[] for i in range(M)] for i in range(N): a, b = list(map(int, input().split())) try: w[a-1].append(-b) except: pass ans = 0 a = [] heapq.heapify(a) for i in range(M): for x in w[i]: heapq.heappush(a, x) t...
p02948
import bisect N, M = list(map(int, input().split())) income = [[] for _ in range(M+1)] # income[i]はi日後に報酬が得られる全ての仕事についての報酬のリスト for _ in range(N): a, b = list(map(int, input().split())) if a <= M: bisect.insort_left(income[a], b) # 後ろから考える。残りi日のときに終了までに報酬が得られる仕事のうち報酬最大のものを選ぶ ans = 0 for rest...
import heapq N, M = list(map(int, input().split())) income = [[] for _ in range(M+1)] # income[i]はi日後に報酬が得られる全ての仕事についての報酬のリスト for _ in range(N): a, b = list(map(int, input().split())) if a <= M: income[a].append(-b) # 後ろから考える。残りi日のときに終了までに報酬が得られる仕事のうち報酬最大のものを選ぶ ans = 0 tmp = [] for rest_d...
p02948
from collections import defaultdict import heapq n, m = list(map(int, input().split())) d = defaultdict(list) for i in range(n): a, b = list(map(int, input().split())) d[a-1].append(-b) cnt = 0 a = [] for i in range(m): a += d[i] heapq.heapify(a) if a: cnt += -heapq.heappop(a) ...
from collections import defaultdict import heapq n, m = list(map(int, input().split())) d = defaultdict(list) for i in range(n): a, b = list(map(int, input().split())) d[a-1].append(-b) cnt = 0 a = [] heapq.heapify(a) for i in range(m): for j in d[i]: heapq.heappush(a, j) if a: ...
p02948
import bisect n, m = list(map(int, input().split())) ls = [list(map(int, input().split())) for _ in range(n)] ls.sort(key=lambda x: x[0]) la = [x[0] for x in ls] lb = [x[1] for x in ls] selected = [] res = 0 for i in range(1, m + 1): k = bisect.bisect(la, i) bs = lb[:k] index = -1 temp =...
import heapq n, m = list(map(int, input().split())) ls = [list(map(int, input().split())) for _ in range(n)] ls.sort(key=lambda x: x[0]) q = [] res = 0 index = 0 for i in range(1, m + 1): while index < n and ls[index][0] <= i: heapq.heappush(q, -ls[index][1]) index += 1 if len(q) ...
p02948
import bisect import sys input = sys.stdin.readline inpl = lambda: list(map(int,input().split())) class SegmentTree: def __init__(self, value, N=0, comp=lambda x,y: x<=y, reverse=False): M = max(len(value),N) N = 2**(len(bin(M))-3) if N < M: N *= 2 self.N = N self...
import sys input = sys.stdin.readline inpl = lambda: list(map(int,input().split())) class SegmentTree: def __init__(self, value, N=0, comp=lambda x,y: x<=y, reverse=False): M = max(len(value),N) N = 2**(len(bin(M))-3) if N < M: N *= 2 self.N = N self.node = [0] * (...
p02948
import sys import heapq input = sys.stdin.readline n,m = list(map(int,input().split())) alwork = [() for i in range(10**5+1)] w = [] hpop = heapq.heappop hpush = heapq.heappush ans = 0 for i in range(n): a,b = list(map(int,input().split())) alwork[a] += (-b,) for i in range(1,m+1): for j in alwo...
import sys import heapq input = sys.stdin.readline n,m = list(map(int,input().split())) l=[tuple(map(int,input().split())) for i in range(n)] l.sort(reverse=True) w = [] hpop = heapq.heappop hpush = heapq.heappush ans = 0 for i in range(1,m+1): while l and l[-1][0]==i: hpush(w,-l.pop()[1]) if ...
p02948
import heapq N,M = (int(x) for x in input().split()) AB = [] sum = 0 for i in range(N): a,b = (int(x) for x in input().split()) AB.append([a,b]) AB = sorted(AB , key = lambda x : x[0]) heap = [] j = 0 for i in range(M+1): while j<N and AB[j][0] < i+1: heapq.heappush(heap,-AB[j][1...
import heapq N,M = (int(x) for x in input().split()) AB = [] sum = 0 for i in range(N): a,b = (int(x) for x in input().split()) AB.append([a,b]) AB = sorted(AB , key = lambda x : x[0]) heap = [] heapq.heapify(heap) j = 0 for i in range(M+1): while j<N and AB[j][0] < i+1: heapq.h...
p02948
if __name__ == '__main__': n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(n)] ab = sorted(ab, key=lambda x: x[1], reverse=True) free_day = set(list(range(m + 1))) answer = 0 for i in range(n): a = ab[i][0] b = ab[i][1] ...
from heapq import heappush, heappop # https://atcoder.jp/contests/abc137/submissions/6840855 を参考にした。 q = [] if __name__ == '__main__': n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for i in range(n)] ab = sorted(ab, reverse=True) q = [] answer = 0 f...
p02948
# -*- coding: utf-8 -*- N, M = list(map(int, input().split())) Wlist = [] for i in range(N): A, B = list(map(int, input().split())) Wlist.append([A,B]) Wlist.sort(key=lambda x:x[0]) Ans = 0 for day in range(1,M+1): Best = 0 BestIdx = -1 for i, W in enumerate(Wlist): if W[0] >...
# -*- coding: utf-8 -*- import heapq N, M = list(map(int, input().split())) Wlist = [] for i in range(N): A, B = list(map(int, input().split())) Wlist.append([A,B]) Wlist.sort(key=lambda x:x[0]) h = [] Ans = 0 Index = 0 for day in range(1,M+1): while Index < N: if Wlist[Index][0] <=...
p02948
import sys from collections import deque input = sys.stdin.readline def main(): n,m=list(map(int,input().split())) ab=[list(map(int,input().split())) for _ in range(n)] ab.sort() c=[0]*n ans=0 for i in range(1,m+1): mb=0 mnum=-1 for j in range(n): ...
import sys from heapq import heappush, heappop input = sys.stdin.readline def main(): n,m=list(map(int,input().split())) ab=[] for i in range(n): a,b=list(map(int,input().split())) if a>m: continue ab.append((a,b)) ab.sort(reverse=True) q=[] ...
p02948
import heapq N, M = list(map(int, input().split())) AB = [list(map(int, input().split())) for i in range(N)] AB.sort() ans = 0 candidates = [] now = 0 for i in range(M+1): for j in range(now, N): if AB[j][0] <= i: heapq.heappush(candidates, -AB[j][1]) now = j + 1 else: ...
# イベントソートでもできると思う import heapq N, M = list(map(int, input().split())) event_list = [[m, 10**5] for m in range(1, M+1)] for i in range(N): a, b = list(map(int, input().split())) event_list.append([a, b]) event_list.sort() jobs = [] ans = 0 for event in event_list: if event[1] < 10**5: heapq...
p02948
""" 案件を報酬を受け取るまでにかかる時間で降順ソートしておく。 """ class segTree: def __init__(self,n,identity): if bin(n).count("1") == 1: self.leaves = 2**(n.bit_length()-1) else: self.leaves = 2**n.bit_length() self.identity = identity self.tree = [[self.identity,-1] for i in...
""" Aの値が大きいものからheapqにぶち込んでいけばよい。 """ from heapq import heappop,heappush N,M = list(map(int,input().split())) AB = [list(map(int,input().split())) for _ in range(N)] AB.sort(reverse=True) que = [] for a,b in AB: if M >= a: heappush(que,b) M -= 1 elif que: if que[0] < b: ...
p02948
import sys readline = sys.stdin.readline # 逆順に見ていく # A_iの値が小さい順にheapqに追加していく N,M = list(map(int,readline().split())) from collections import defaultdict tasks = defaultdict(list) for i in range(N): a,b = list(map(int,readline().split())) tasks[a].append(b) import heapq q = [] heapq.heapify(q) a...
import sys readline = sys.stdin.readline N,M = list(map(int,readline().split())) from collections import defaultdict tasks = defaultdict(list) for i in range(N): a,b = list(map(int,readline().split())) tasks[a].append(b) import heapq as hq q = [] ans = 0 for i in range(1, M + 1): newtask = tasks...
p02948
from collections import defaultdict import heapq N,M=list(map(int,input().split())) x=defaultdict(list) for i in range(N): a,b=list(map(int,input().split())) x[a].append(-b) y=[] an=0 for i in range(M+1): y+=x[i] heapq.heapify(y) try: an-=heapq.heappop(y) except: p...
import heapq N,M=list(map(int,input().split())) x={} for i in range(M+1): x[i]=[] for i in range(N): a,b=list(map(int,input().split())) if a>M: continue x[a].append(-b) y=[] an=0 for i in range(M+1): for n in x[i]: heapq.heappush(y,n) try: an-=heapq.heappo...
p02948
import heapq n,m=list(map(int,input().split())) c=[[] for i in range(m+1)] for i in range(n): a,b=list(map(int,input().split())) if a<=m: c[a].append(-b) d=[] heapq.heapify(d) ans=0 for i in range(1,m+1): for j in range(len(c[i])): heapq.heappush(d,c[i][j]) if d!=[]: ...
import heapq n,m=list(map(int,input().split())) c=[[] for i in range(m+1)] for i in range(n): a,b=list(map(int,input().split())) if a<=m: c[a].append(-b) d=[] heapq.heapify(d) ans=0 for i in range(1,m+1): for j in c[i]: heapq.heappush(d,j) if d!=[]: ans+=heapq.heapp...
p02948
mod = 10 ** 9 + 7 from collections import deque import heapq def main(): N, M = iip(False) A = [] for i in range(N): A.append(iip(True)) ret = solve(N, M, A) print(ret) def solve(N, M, A): A = sorted(A, key=lambda x: x[1], reverse=True) sch = list(range(M)) ...
mod = 10 ** 9 + 7 from collections import deque import heapq def main(): N, M = iip(False) A = [] for i in range(N): A.append(iip(True)) ret = solve(N, M, A) print((-ret)) def solve(N, M, A): A = deque(sorted(A, key=lambda x: x[0], reverse=False)) jobs = [] ...
p02948
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush, heapify import math import itertools import random # NO, PAY-PAY #import numpy as np #import statistic...
# -*- coding: utf-8 -*- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush, heapify import math import itertools import random # NO, PAY-PAY #import numpy as np #import statistic...
p02948