input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import math import collections import itertools import sys import bisect from heapq import heappop,heappush,heapify sys.setrecursionlimit(10**6) def MAP(): return list(map(int,input().split())) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) MOD = 10**9+7 n,m = MAP() a = MA...
import math import collections import itertools import sys import bisect from heapq import heappop,heappush,heapify sys.setrecursionlimit(10**6) def MAP(): return list(map(int,input().split())) def INT(): return int(eval(input())) def FLOAT(): return float(eval(input())) MOD = 10**9+7 n, m = MAP() a = M...
p03038
from heapq import ( heapify, # 優先度付きキューの生成 heappop, # キューから値を取り出す heappush, # キューに値を格納 heappushpop, # push -> popの順 heapreplace, # pop -> pushの順 ) N, M = list(map(int, input().split())) A = list(map(int, input().split())) A = [-i for i in A] bc = [] for _ in range(M): ...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) dic = {} for i in range(N): tmp = A[i] if tmp in dic: dic[tmp] += 1 else: dic[tmp] = 1 for _ in range(M): B, C = list(map(int, input().split())) if C in dic: dic[C] += B else: ...
p03038
n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [list(map(int,input().split())) for _ in range(m)] bc = sorted(bc,key=lambda x:(x[1])) count=0 for b,c in bc: count += b a.extend([c]*b) if b > n: break print((sum(sorted(a,reverse=True)[:n])))
n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [list(map(int,input().split())) for _ in range(m)] bc = sorted(bc,key=lambda x:(x[1]),reverse=True) count=0 for b,c in bc: count += b a.extend([c]*b) if count >= n: break print((sum(sorted(a,reverse=True)[:n])))
p03038
import sys import heapq input = sys.stdin.readline n,m = list(map(int,input().split())) heap = [int(i) for i in input().split()] heap.sort() for i in range(m): a,b = list(map(int,input().split())) for j in range(a): if heap[0] < b: heapq.heappop(heap) heapq.heappush(heap,b) p...
import sys input = sys.stdin.readline n,m = list(map(int,input().split())) heap = [int(i) for i in input().split()] heap.sort() ans = sum(heap) ml = [] cnt = 0 for i in range(m): a,b = list(map(int,input().split())) ml += [[b,a]] ml.sort(reverse=True) for i in range(m): for j in range(ml[i][1])...
p03038
import sys def input(): return sys.stdin.readline()[:-1] N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC_list = [] for i in range(M): B, C = list(map(int, input().split())) BC_list.append({ 'B': B, 'C': C }) BC_list.sort(reverse=Tru...
import sys def input(): return sys.stdin.readline()[:-1] N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC_list = [] for i in range(M): B, C = list(map(int, input().split())) BC_list.append({ 'B': B, 'C': C }) BC_list.sort(reverse=True,...
p03038
from collections import deque n,m=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) BC=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1]) A=deque(A) for b,c in BC[::-1]: if len(A)==0:break for i in range(b): if A[0]<c: A.append(c) ...
from collections import deque n,m=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) BC=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1]) A=deque(A) for b,c in BC[::-1]: for i in range(b): if A[0]<c: A.append(c) A.popleft() ...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [[c]*b for b, c in [list(map(int, input().split())) for _ in range(M)]] R=sum(BC,[]) T=sorted(A+R,reverse=True) print((sum(T[:len(A)])))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [[c]*b for b, c in [list(map(int, input().split())) for _ in range(M)]] R=sum(BC,[]) if len(R)>len(A): R=sorted(R,reverse=True)[:len(A)] T=sorted(A+R,reverse=True) print((sum(T[:len(A)])))
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [[c]*b for b, c in [list(map(int, input().split())) for _ in range(M)]] R=sum(BC,[]) if len(R)>len(A): R=sorted(R,reverse=True)[:len(A)] T=sorted(A+R,reverse=True) print((sum(T[:len(A)])))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [list(map(int, input().split())) for _ in range(M)] BC.sort(key=lambda x:x[1],reverse=True) R=[] n=0 for i in BC: R = R+[i[1]]*i[0] n = n + i[0] if n >= N: break R=sorted(A+R, reverse=True)[:N] print((s...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [list(map(int, input().split())) for _ in range(M)] BC.sort(key=lambda x:x[1],reverse=True) R=[] n=0 for i in BC: R = R+[i[1]]*i[0] n = n + i[0] if n >= N: break R=sorted(A+R, reverse=True)[:N] print((s...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [list(map(int, input().split())) for _ in range(M)] A.sort(reverse=True) BC.sort(key=lambda x:x[1],reverse=True) R=[] n=0 for i in range(M): R.extend([BC[i][1]]*BC[i][0]) n = n + BC[i][0] if n >= N: break ...
p03038
n, m = tuple(map(int, input().split())) x = sorted(list(map(int, input().split()))) y = [tuple(map(int, input().split())) for i in range(m)] for b,c in y: while x[b-1] > c and b > 0: b -= 1 x[0:b] = [c]*b x.sort() print((sum(x)))
n, m = tuple(map(int, input().split())) x = sorted(list(map(int, input().split()))) y = [list(map(int, input().split())) for i in range(m)] y.sort(key = lambda x: x[1], reverse=True) y_pos = 0 for index, value in enumerate(x): b = y[y_pos][0] c = y[y_pos][1] if value < c: x[index] = c y[y_pos][0] ...
p03038
n,m=list(map(int,input().split())) *a,=list(map(int,input().split())) l=[list(map(int,input().split()))[::-1] for _ in range(m)] a.sort() d=[] e=0 for c,b in sorted(l)[::-1]: d+=[c]*b e+=b if e>n:break for i,(x,y) in enumerate(zip(a,d)): if x<y:a[i]=y print((sum(a)))
n,m=list(map(int,input().split())) a=list(map(int,input().split())) Z=[list(map(int,input().split()))[::-1] for _ in range(m)] d=[] e=0 a.sort() Z.sort(reverse=True) for c,b in Z: d+=[c]*b e+=b if e>n: break for i , (x,y) in enumerate(zip(a,d)): if x<y: a[i]=y print((s...
p03038
import heapq import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) heapq.heapify(A) for _ in range(M): b, c = list(map(int, input().split())) for _ in range(b): n = heapq.heappop(A) ...
import heapq import sys input = sys.stdin.readline def main(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) heapq.heapify(A) BC = [] for _ in range(M): b, c = list(map(int, input().split())) BC.append([c*(-1), b]) heapq.heapify(BC...
p03038
import heapq N, M = list(map(int, input().split())) A_LIST = list(map(int, input().split())) BC_LIST = [] heapq.heapify(A_LIST) for i in range(M): b, c = list(map(int, input().split())) BC_LIST.append([b, c]) BC_LIST.sort(reverse=True, key=lambda x: x[1]) # C降順にソート for b, c in BC_LIST: for _ in...
N, M = list(map(int, input().split())) A_LIST = list(map(int, input().split())) BC_LIST = [] for i in range(M): b, c = list(map(int, input().split())) BC_LIST.append([b, c]) card_dict = {} for a in A_LIST: if a in card_dict: card_dict[a] += 1 else: card_dict[a] = 1 for b, c i...
p03038
import heapq n,m=list(map(int,input().split())) a=sorted(list(map(int, input().split()))) bc=[list(map(int, input().split())) for _ in range(m)] bc.sort(key=lambda x:x[1]) heapq.heapify(a) for b,c in bc: for j in range(b): amin=heapq.heappop(a) if amin<c: heapq.heappush(a,c) else: ...
def main(): import heapq n,m=list(map(int,input().split())) a=sorted(list(map(int, input().split()))) bc=[list(map(int, input().split())) for _ in range(m)] bc.sort(key=lambda x:-x[1]) heapq.heapify(a) for b,c in bc: for j in range(b): amin=heapq.heappop(a) if...
p03038
import heapq n, m = list(map(int, input().split())) cards = list(map(int, input().split())) heapq.heapify(cards) queries = [] for i in range(m): q = list(map(int, input().split())) queries.append(q) for q in queries: b, c = q cnt = 0 while cnt < b: heapq.heappushpop(cards...
import heapq n, m = list(map(int, input().split())) cards = list(map(int, input().split())) cards.sort() queries = [] for i in range(m): q = list(map(int, input().split())) queries.append(q) queries.sort(key=lambda x: x[1]) queries.reverse() ans = 0 pos = 0 for q in queries: b, c = q ...
p03038
def s0():return eval(input()) def s1():return input().split() def s2(n):return [eval(input()) for x in range(n)] def s3(n):return [input().split() for _ in range(n)] def s4(n):return [[x for x in s] for s in s2(n)] def n0():return int(eval(input())) def n1():return [int(x) for x in input().split()] def n2(n):r...
def s0():return eval(input()) def s1():return input().split() def s2(n):return [eval(input()) for x in range(n)] def s3(n):return [input().split() for _ in range(n)] def s4(n):return [[x for x in s] for s in s2(n)] def n0():return int(eval(input())) def n1():return [int(x) for x in input().split()] def n2(n):r...
p03038
def binary_search(cards,n,number): low=0 high=len(cards)-1 while high-low>1: mid=(low+high)//2 base=cards[mid] if base==number: for i in range(n): cards.insert(mid,number) return cards,mid if base<number: low=mi...
from heapq import heappush,heappop def main(): inp1=list([int(x) for x in input().split()]) cards=list([int(x) for x in input().split()]) cards_heap=[] for i in cards: heappush(cards_heap,i) N=inp1[0] M=inp1[1] B=[] C=[] for i in range(M): changes=list...
p03038
from bisect import bisect n, m = list(map(int, input().split())) *a, = list(map(int, input().split())) a.sort() BC = [] for _ in range(m): b, c = list(map(int, input().split())) BC.append((b, c)) BC = sorted(BC, key=lambda x: x[1], reverse=True) ans = 0 num = 0 for b, c in BC: idx = bisect(a[n...
n, m = list(map(int, input().split())) a = [(1, int(i)) for i in input().split()] for _ in range(m): b, c = list(map(int, input().split())) a.append((b, c)) a = sorted(a, key=lambda x: x[1]) ans = 0 t = 0 while t < n: b, c = a.pop() p = min(b, n-t) ans += p * c t += p print(ans)
p03038
import bisect N, M = list(map(int, input().split())) *a, = list(map(int, input().split())) BC = [] for _ in range(M): b, c = list(map(int, input().split())) BC.append((b, c)) a.sort() BC = sorted(BC, key=lambda x: x[1], reverse=True) ans = 0 for b, c in BC: idx = bisect.bisect_right(a, c) ...
N, M = list(map(int, input().split())) a = [(1, int(i)) for i in input().split()] for _ in range(M): b, c = list(map(int, input().split())) a.append((b, c)) a = sorted(a, key=lambda x: x[1]) ans = 0 t = 0 while t < N: b, c = a.pop() p = min(b, N-t) ans += p * c t += p print(ans)
p03038
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() heapq.heapify(A) CB = [] for i in range(M): b, c = list(map(int, input().split())) CB.append([c, b]) CB.sort() D = [] for c, b in CB: D += [c]*b for i in range(N): if D: d = D.pop() g...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) CB = [] for i in range(M): b, c = list(map(int, input().split())) CB.append([c, b]) D = [[a, 1] for a in A] + CB D.sort() ans = 0 while N > 0: c, b = D.pop() ans += min(N, b)*c N -= b print(ans)
p03038
from operator import itemgetter N,M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A.sort() BC = [[int(x) for x in input().split()]for _ in range(M)] BC.sort(key = itemgetter(1),reverse=True) x = 0 for i in BC: y = 0 while(x+y<len(A) and y<i[0]): if(A[x+y]<i[1]): ...
from operator import itemgetter import sys sys.setrecursionlimit(1000000) N,M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A.sort() BC = [[int(x) for x in input().split()]for _ in range(M)] BC.sort(key = itemgetter(1),reverse=True) x = 0 bc_ind = 0 ans = 0 for ind,i in enumer...
p03038
#!/usr/bin/env python3 N, M = list(map(int, input().rstrip().split())) A = list(map(int, input().rstrip().split())) B = [] C = [] for _ in range(M): b, c = list(map(int, input().rstrip().split())) B.append(b) C.append(c) Index = sorted(list(range(M)), key=lambda i: C[i], reverse=True) sum = ...
#!/usr/bin/env python3 N, M = list(map(int, input().rstrip().split())) A = list(map(int, input().rstrip().split())) B = [] C = [] for _ in range(M): b, c = list(map(int, input().rstrip().split())) B.append(b) C.append(c) Index = sorted(list(range(M)), key=lambda i: C[i], reverse=True) sum = ...
p03038
#!/usr/bin/env python3 N, M = list(map(int, input().rstrip().split())) A = list(map(int, input().rstrip().split())) B = [] C = [] for _ in range(M): b, c = list(map(int, input().rstrip().split())) B.append(b) C.append(c) Index = sorted(list(range(M)), key=lambda i: C[i], reverse=True) sum = ...
#!/usr/bin/env python3 N, M = list(map(int, input().rstrip().split())) A = list(map(int, input().rstrip().split())) B = [] C = [] for _ in range(M): b, c = list(map(int, input().rstrip().split())) B.append(b) C.append(c) Index = sorted(list(range(M)), key=lambda i: C[i], reverse=True) sum = ...
p03038
import math import fractions import copy #以下てんぷら def j(q): if q==1: print("YES") elif q == 0:print("NO") exit(0) rem = pow(10,9)+7 """ def ct(x,y): if (x>y):print("+") elif (x<y): print("-") else: print("?") """ def ip(): return int(eval(input())) def printrow(a): for...
import math import fractions import copy #以下てんぷら def j(q): if q==1: print("YES") elif q == 0:print("NO") exit(0) rem = pow(10,9)+7 """ def ct(x,y): if (x>y):print("+") elif (x<y): print("-") else: print("?") """ def ip(): return int(eval(input())) def printrow(a): for...
p03038
N, M = [int(i) for i in input().strip().split()] A = [int(i) for i in input().strip().split()] A.sort() for i in range(M): B, C = [int(i) for i in input().strip().split()] is_changed = False for j in range(0, B): if A[j] < C: A[j] = C is_changed = True else:...
N, M = [int(i) for i in input().strip().split()] A = [int(i) for i in input().strip().split()] A.sort() BC = [[0, 0] for _ in range(M)] for j in range(M): BC[j][0], BC[j][1] = [int(i) for i in input().strip().split()] BC.sort(key=lambda x: x[1]) res = 0 cnt = 0 i = N - 1 j = M - 1 while True: if...
p03038
from heapq import heapify, heappop, heappush def solve(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) heapify(A) for _ in range(M): B, C = list(map(int, input().split())) for _ in range(B): if A[0] < C: heappop...
from operator import itemgetter def solve(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [[] for _ in range(M)] for i in range(M): BC[i] = list(map(int, input().split())) BC.sort(key=itemgetter(1), reverse=True) change = [] for b...
p03038
N,M=list(map(int,input().split())) A=list(map(int,input().split())) import heapq heapq.heapify(A) for i in range(M): b,c=list(map(int,input().split())) for j in range(b): val=heapq.heappop(A) if val<c: heapq.heappush(A,c) else: heapq.heappush(A,val) break print((sum(A)...
N,M=list(map(int,input().split())) A=list(map(int,input().split())) Q=[None]*M for i in range(M): b,c=list(map(int,input().split())) Q[i]=[b,c] Q=sorted(Q,key=lambda x:x[1])[::-1] A=sorted(A) ind=0 for i in range(len(Q)): b,c=Q[i] for p in range(b): if ind+p>=len(A): print((sum(A)...
p03038
#import math #import copy #import sys #import bisect #input = sys.stdin.readline mod=10**9+7 def swap(a,b): c=a a=b b=c return a,b def factorial(x): #階乗計算 n=1 for i in range(x): n=(n*(i+1))%mod return n def gcd(a, b): if b == 0: return a else: ...
#import math #import copy #import sys #import bisect #input = sys.stdin.readline mod=10**9+7 def swap(a,b): c=a a=b b=c return a,b def factorial(x): #階乗計算 n=1 for i in range(x): n=(n*(i+1))%mod return n def gcd(a, b): if b == 0: return a else: ...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() L = [] for i in range(M): b, c = list(map(int, input().split())) _ = [c, b] L.append(_) L.sort() L.reverse() c = 0 D = [] while c < N and len(L) > 0: for i in range(L[0][1]): D.append(L[0][0]) c += 1 del L[0] ...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() L = [] for i in range(M): b, c = list(map(int, input().split())) L.append((c, b)) L = sorted(L, reverse = True) L.append((0, N)) temp = 0 sum = 0 for i in range(M + 1): for j in range(L[i][1]): if A[temp] < L[i][0]: ...
p03038
n, m = list(map(int, input().split(' '))) aaa = list(map(int, input().split(' '))) r = 100000 cccbbb = [] for i in range(m): b, c = list(map(int, input().split(' '))) cccbbb += [c] * b aaa = sorted(aaa) cccbbb = sorted(cccbbb)[::-1] len_cccbbb = len(cccbbb) len_aaa = len(aaa) #print(aaa) #print(cccb...
n, m = list(map(int, input().split(' '))) aaa = list(map(int, input().split(' '))) aaa = sorted(aaa) len_aaa = len(aaa) cccbbb = [] for i in range(m): b, c = list(map(int, input().split(' '))) cccbbb += [c] * b cccbbb = sorted(cccbbb)[::-1] if len(cccbbb) > len(aaa): cccbbb = cccbbb[:l...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) opes = [tuple(map(int, input().split())) for _ in range(M)] D = [C for B, C in opes for _ in range(B)] D = sorted(D, reverse=True)[:N] A.sort() for i, d in enumerate(D): if A[i] >= d: break A[i] = d print((sum(A))...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) opes = [tuple(map(int, input().split())) for _ in range(M)] opes.sort(key=lambda x:-x[1]) D = [] lenD = 0 for B, C in opes: D += [C]*B lenD += B if lenD >= N: break A.sort() for i, d in enumerate(D[:N]): ...
p03038
# coding:utf-8 import math import re def main(params): n,m = params[0] a = params[1] tmpA = [] for i in a: i = int(i) tmpA.append(i) a = tmpA a.sort() a.reverse() r = [] for g in params[2:]: b = int(g.split()[0]) c = int(g.split()[1...
# coding:utf-8 import math import re def main(params): n,m = params[0] a = params[1] tmpA = [] for i in a: i = int(i) tmpA.append(i) a = tmpA a.sort() a.reverse() r = {} for g in params[2:]: b = int(g.split()[0]) c = int(g.split()[1...
p03038
from heapq import heapify, heappush, heappop import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) a = heapify(A) B = [0] * M C = [0] * M for i in range(M): B[i], C[i] = list(map(int, input().split())) cb = sorted(zip(C, B), reverse=True) for...
from heapq import heapify, heappush, heappop import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() B = [0] * M C = [0] * M for i in range(M): B[i], C[i] = list(map(int, input().split())) cb = sorted(zip(C, B), reverse=True) cnt = 0 ...
p03038
from heapq import heapify, heappush, heappop import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() B = [0] * M C = [0] * M for i in range(M): B[i], C[i] = list(map(int, input().split())) cb = sorted(zip(C, B), reverse=True) cnt = 0 ...
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = [0] * M C = [0] * M for i in range(M): B[i], C[i] = list(map(int, input().split())) cb = sorted(zip(C, B), reverse=True) exchange = [] for c, b in cb: exchange.extend([c] * b) ...
p03038
import bisect N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int,input().split())) for _ in range(M)] for b,c in BC: A += [c] * b # print(A) # print(sorted(A)) # print(sorted(A)[-N:]) print((sum(sorted(A)[-N:])))
N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int,input().split())) for _ in range(M)] for b,c in BC: A += [c] * b # print(A) # print(sorted(A)) # print(sorted(A)[-N:]) print((sum(sorted(A)[-N:])))
p03038
import sys from collections import deque readline = sys.stdin.readline n, m = list(map(int, readline().split())) a = sorted(list(map(int, readline().split()))) bc = [] for _ in range(m): b, c = list(map(int, readline().split())) for _ in range(b): bc.append(c) bc.sort(key=lambda x: -x) dbc ...
import sys from collections import deque readline = sys.stdin.readline n, m = list(map(int, readline().split())) a = sorted(list(map(int, readline().split()))) bc = [] for _ in range(m): b, c = list(map(int, readline().split())) bc.append([b * c, c]) bc.sort(key=lambda x: -x[1]) dbc = deque(bc) for...
p03038
#!/usr/bin/env python3 import sys INF = float("inf") def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort() # 昇順 O(NlongN) BC = list(zip(B, C)) BC.sort(key=lambda x: x[1], reverse=True) # 降順 MlogM Cs = [] for b, c in BC: # M ...
#!/usr/bin/env python3 import sys INF = float("inf") def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort() # 昇順 O(NlongN) BC = list(zip(B, C)) BC.sort(key=lambda x: x[1], reverse=True) # 降順 MlogM Cs = [] for b, c in BC: # M ...
p03038
import bisect import sys input = sys.stdin.readline from collections import deque def solve(): n,m = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) a.sort() tmp = deque([]) for i in range(m): r,l = (int(i) for i in input().split()) tmp.append((l,r)) tmp= ...
import bisect import sys input = sys.stdin.readline from collections import deque def solve(): n,m = (int(i) for i in input().split()) a = list(int(i) for i in input().split()) a = deque(sorted(a)) tmp = deque([]) for i in range(m): r,l = (int(i) for i in input().split()) tmp.append((l,...
p03038
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq input = sys.stdin.readline # bisect_left(lists, 3) # bisect_right(lists, 3) # heapq.heapify(a) #リストaのheap化 # heapq.heappush(a,x) #heap化されたリストaに要素xを追加...
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq input = sys.stdin.readline # bisect_left(lists, 3) # bisect_right(lists, 3) # heapq.heapify(a) #リストaのheap化 # heapq.heappush(a,x) #heap化されたリストaに要素xを追加...
p03038
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline from bisect import bisect_left n, m = list(map(int, input().split())) a = list( map(int, input().split())) a.sort() bc = [tuple(map(int,input().split())) for i in range(m)] bc = sorted(bc, reverse=True, key=lambda x: x[1]) cnt = 0 fo...
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline from bisect import bisect_left n, m = list(map(int, input().split())) a = list( map(int, input().split())) a.sort() bc = [tuple(map(int,input().split())) for i in range(m)] bc = sorted(bc, reverse=True, key=lambda x: x[1]) i = 0 for ...
p03038
def d_integer_cards(N, M, A, Operation_info): from bisect import bisect_left from collections import deque a = deque(sorted(A)) Operation_info.sort(key=lambda x: x[1], reverse=True) tmp = [] for b, c in Operation_info: index = bisect_left(a, c) if index > 0: ...
def d_integer_cards(N, M, A, Operation_info): # Aの要素は1回選ぶことができるとみなす # 値C_iはB_i回選ぶことができるとみなす selected_num = [[1, a] for a in A] + Operation_info selected_num.sort(key=lambda x: x[1], reverse=True) # 値yをx回選ぶことを、選んだ値の個数がNになるまで繰り返す select = 0 ans = 0 for x, y in selected_num: ...
p03038
from collections import deque N, M = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) A_que = deque(A) for i in range(M): B, C = list(map(int, input().split(" "))) for j in range(B): A_que.append(C) A = list(A_que) A.sort(reverse=True) print((sum(A[0:N])))
N, M = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) A.sort() D = [] for i in range(M): B, C = list(map(int, input().split(" "))) D.append((C, B)) #D = list(D_dict) D.sort(reverse=True) D_index = 0 D_index_max = len(D) ans = 0 ct_D_i = 0 ct_D_i_max = D[0][1] ...
p03038
from collections import deque n,m=list(map(int,input().split())) a=deque(list(map(int,input().split()))) #a=deque(a) for i in range(m): b,c=list(map(int,input().split())) l=[c for _ in range(b)] a.extend(l) a=list(a) #print(a) a.sort(reverse=1) a=a[:n] print((sum(a))) #print(a)
from collections import deque n,m=list(map(int,input().split())) a=deque(list(map(int,input().split()))) bc=[list(map(int,input().split())) for _ in range(m)] bc.sort(key=lambda x: x[1]) bc=bc[::-1] l=0 for b,c in bc: if l>n: break else: d=[c]*b a.extend(d) l+=b a=list(a) #print...
p03038
ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) n, m = nm() a = nl() for i in range(m): b, c = nm() a += [c] * b print((sum(sorted(a, reverse=True)[:n])))
ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) n, m = nm() a = sorted(nl()) pos = 0 changer = [] for i in range(m): b, c = nm() changer.append((c, b)) changer = sorted(changer)[::-1] for i in range(m): c...
p03038
import sys from collections import deque from copy import copy from bisect import bisect_right, bisect_left N,M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() BC=[] for m in range(M): b,c = list(map(int, input().split())) BC.append([b,c]) BC.sort(key=lambda bc: b...
import sys from collections import deque from copy import copy from bisect import bisect_right, bisect_left N,M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() A = deque(A) BC=[] for m in range(M): b,c = list(map(int, input().split())) BC.append([b,c]) BC.sort(ke...
p03038
from collections import defaultdict n,m=list(map(int,input().split())) A=[int(i) for i in input().split()] A.sort() D=defaultdict(int) for i in range(m): b,c=list(map(int,input().split())) D[c]+=b D=sorted(list(D.items()),key=lambda x:x[0],reverse=True) DD=[0]*n ct=0 for x,y in D: for i in range(y): ...
from collections import defaultdict from collections import Counter n,m=list(map(int,input().split())) A=[int(i) for i in input().split()] AA=dict(Counter(A)) D=defaultdict(int) for i in range(m): b,c=list(map(int,input().split())) D[c]+=b for x in list(AA.keys()): D[x]+=AA[x] D=sorted(list(D.items()),...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) for i in range(M): B, C = list(map(int, input().split())) A = A + [C,]*B A.sort(reverse=True) sum = 0 for i in range(N): sum = sum + A[i] print(sum)
N, M = list(map(int, input().split())) A = list(map(int, input().split())) Nd = {} for i in range(M): B, C = list(map(int, input().split())) if C in list(Nd.keys()): Nd[C] = Nd[C] + B else: Nd[C] = B for a in A: if a in list(Nd.keys()): Nd[a] = Nd[a] + 1 else: Nd[a] = 1 ...
p03038
# ABC127 D-Integer Cards from operator import itemgetter N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int, input().split())) for _ in range(M)] BC.sort(key=itemgetter(1),reverse=True) # print(A) # print('sort',BC) for i in range(M): x = 0 while x < BC[i][0]:...
# ABC127 D-Integer Cards from operator import itemgetter N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int, input().split())) for _ in range(M)] A.sort() BC.sort(key=itemgetter(1),reverse=True) # print(A) # print('sort',BC) c = 0 for i in range(M): for j in rang...
p03038
# ABC127 D-Integer Cards from operator import itemgetter N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int, input().split())) for _ in range(M)] A.sort() BC.sort(key=itemgetter(1),reverse=True) # print(A) # print('sort',BC) c = 0 for i in range(M): for j in rang...
# ABC127 D-Integer Cards from operator import itemgetter N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int, input().split())) for _ in range(M)] A.sort() BC.sort(key=itemgetter(1),reverse=True) c = 0 for i in range(M): for j in range(BC[i][0]): if A[c] ...
p03038
n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[] for i in range(m): bb,cc=list(map(int,input().split())) b.append([cc,bb]) a.sort() b.sort(reverse=True) i=0 j=0 while i<n: if j==m: break if b[j][1]>0: if a[i]<b[j][0]: a[i]=b[j][0] ...
n,m=list(map(int,input().split())) a=list(map(int,input().split())) bc=[list(map(int,input().split())) for i in range(m)] a.sort() bc.sort(key=lambda x: x[1],reverse=True) # print(a) # print(bc) i=0 for b,c in bc: tb=b while tb>0: if n==i: break if a[i]>=c: break a[i]=c t...
p03038
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) change = [] for m in range(M): B, C = list(map(int, input().split())) change.append((B, C)) change.sort(key=lambda x: -x[1]) change2 = [] for c in change: change2.extend([c[1]] * c[0]) if len(change2...
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) # 交換できるカードを大きい順にリスト化する exchange1 = [] for m in range(M): B, C = list(map(int, input().split())) exchange1.append((B, C)) exchange1.sort(key=lambda x: -x[1]) exchange2 = [] for c in exchange1: exchange2.ext...
p03038
import sys import heapq n,m=list(map(int,sys.stdin.readline().split())) a=list(map(int,sys.stdin.readline().split())) a.sort for i in range(m): b,c=list(map(int,sys.stdin.readline().split())) t=[c]*b a=list(heapq.merge(a,t)) print((sum(heapq.nlargest(n,a))))
n,m=list(map(int,input().split())) a=list(map(int,input().split())) bc=[list(map(int,input().split())) for i in range(m)] bc.sort(key=lambda x:x[1],reverse=True) for b,c in bc: a.extend([c]*b) if len(a)>2*n: break a.sort(reverse=True) print((sum(a[:n])))
p03038
N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()]) B = [] for _ in range(M): b, c = list(map(int, input().split())) B += [c] * b B.sort(reverse = True) x = min(N, len(B)) for i in range(x): A[i] = max(A[i], B[i]) print((sum(A)))
N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()]) C = sorted([[int(i) for i in input().split()] for i in range(M)], reverse = True, key = lambda x: x[1]) cnt = 0 B = [] for i in range(M): if cnt > N: break B += [C[i][1]] * C[i][0] cnt += C[i...
p03038
s=input().split() n=int(s[0]) m=int(s[1]) s=input().split() l=list(map(int, s)) for i in range(m): s=input().split() l.extend([int(s[1])]*int(s[0])) l.sort() print((sum(l[-n:])))
s=input().split() n=int(s[0]) m=int(s[1]) s=input().split() l=list(map(int, s)) num=min(l) for i in range(m): s=input().split() a=int(s[1]) if a>num: l.extend([a]*int(s[0])) l.sort() print((sum(l[-n:])))
p03038
import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) heapq.heapify(a) b = [] for i in range(m): u, v = list(map(int, input().split())) for j in range(u): b.append(-v) heapq.heapify(b) while len(b) > 0: x = heapq.heappop(a) y = heapq.heappop(b) ...
import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) heapq.heapify(a) for i in range(m): u, v = list(map(int, input().split())) for j in range(u): if v > a[0]: heapq.heappushpop(a, v) print((sum(a)))
p03038
N,M=list(map(int,input().split())) A=list(map(int,input().split())) tmp,count,l0=A[0],1,[] for i in range(1,N): if tmp==A[i]: count+=1 else: l0.append([tmp,count]) tmp=A[i] count=1 l0.append([tmp,count]) BC=[] for i in range(M): BC.append(list(map(int,input().split()))) BC.sort(key=l...
N,M=list(map(int,input().split())) A=list(map(int,input().split())) BC=[] for i in range(M): BC.append(list(map(int,input().split()))) A.sort(reverse=True) BC.sort(key=lambda x:x[1],reverse=True) ans=sum(A) for i in range(M): for _ in range(BC[i][0]): if A==[]: print(ans) exit() if ...
p03038
def main(): import sys input = sys.stdin.readline from bisect import bisect_left,bisect N, M = list(map(int, input().split())) A = list(map(int, input().split())) S = [list(map(int, input().split())) for i in range(M)] A.sort() A = A[::-1] S = sorted(S, key=lambda x: x...
def main(): import sys input = sys.stdin.readline from bisect import bisect_left,bisect N, M = list(map(int, input().split())) A = list(map(int, input().split())) S = [list(map(int, input().split())) for i in range(M)] A.sort() A = A[::-1] S = sorted(S, key=lambda x: x...
p03038
import bisect N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) ans = sum(A) for _ in range(M): b, c = list(map(int, input().split())) if c <= A[0]: continue index = bisect.bisect_left(A, c) index = min(index, b) for i in range(index): ...
N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) bc = [list(map(int, input().split())) for _ in range(M)] ans = sum(A) bc = sorted(bc, key=lambda i: i[1], reverse=True) i = 0 for b, c in bc: for _ in range(b): if A[i] > c: break ans += ...
p03038
import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 add = [] mini = 0 cb = [None]*m for i in range(m): b, c = list(map(int, input().split())) cb[i] = (c, b) cb.sort(reve...
import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) a = list(map(int, input().split())) cb = [None]*m for i in range(m): b, c = list(map(int, input().split())) cb[i] = (c, b) cb.sort(reverse=True) add = [] count = 0 ...
p03038
import heapq N, M = list(map(int, input().split())) A = list([int(x) for x in input().split()]) heapq.heapify(A) for i in range(M): b, c = list(map(int, input().split())) for j in range(b): d = heapq.heappushpop(A, c) if c == d: break print((sum(A)))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) exc = [] for i in range(M): exc.append(list(map(int, input().split()))) exc.sort(key=lambda x: x[1], reverse=True) e = [] count = 0 for i in range(M): e += [exc[i][1]] * exc[i][0] count += exc[i][0] if count >= N: break...
p03038
from collections import Counter n, m = list(map(int, input().split())) a = Counter(list(map(int, input().split()))) bc = [list(map(int, input().split())) for i in range(m)] b = {} ans = 0 for i, j in bc: if j in b: ref = b[j] b[j] = ref + i else: b[j] = i d = Counter(a)...
n, m = list(map(int, input().split())) l = [(a, 1) for a in list(map(int, input().split()))] for i in range(m): b, c = list(map(int, input().split())) l.append((c, b)) l = sorted(l)[::-1] ans = 0 for i, j in l: if j < n: ans += i*j n -= j else: ans += n*i b...
p03038
from heapq import heappushpop, heapify n,m=list(map(int,input().split())) a=list(map(int,input().split())) heapify(a) gomi=a[0] bc=[] for _ in range(m): b,c=list(map(int,input().split())) bc.append((c,b)) bc.sort(reverse=True) for i in bc: c,b=i if gomi>c: break for i in ...
import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) heapq.heapify(a) CB=[] for _ in range(m): b, c = list(map(int, input().split())) CB.append((c, b)) CB.sort(reverse=True) for c, b in CB: if a[0] >= c: break for _ in range(b): if a[0] >...
p03038
N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) L = [tuple(map(int, input().split())) for _ in range(M)] L.sort(key=lambda x: x[1], reverse=True) flag = True num = 0 while flag: if num >= M: break for i in range(L[num][0]): if L[num][1] > A[0]: ...
N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) L = [tuple(map(int, input().split())) for _ in range(M)] L.sort(key=lambda x: x[1], reverse=True) flag = True num = 0 now = 0 while flag: if num >= M: break for i in range(L[num][0]): if now < N and...
p03038
N,M=list(map(int,input().split())) A=list(map(int,input().split())) B=[] for m in range(M): b,c=list(map(int,input().split())) B+=[c]*b A=sorted(A) B=sorted(B)[::-1] Max=0 for i in range(N+1): New=sum(A[i:])+sum(B[:i]) if New>Max: Max=New print(Max)
def main(A,B,N): A=sorted(A) B=sorted(B)[::-1] K=len(B) R=min(N,K) for i in range(R): if A[i]>B[i]: return sum(B[:i]+A[i:]) return sum(B[:R]+A[R:]) N,M=list(map(int,input().split())) A=list(map(int,input().split())) B=[] for m in range(M): b,c=list(map(int,...
p03038
def main(A,D,N): K=min(N,len(D)) for i in range(K): if A[i]>D[i]: return sum(D[:i]+A[i:]) return sum(D[:K]+A[K:]) N,M=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() CB=[] for m in range(M): b,c=list(map(int,input().split())) CB.append([c,b]...
N,M=list(map(int,input().split())) A=list(map(int,input().split())) BC=[] for m in range(M): b,c=list(map(int,input().split())) BC.append([b,c]) A.sort() BC.sort(key=lambda x:x[1],reverse=True) D=[] for [b,c] in BC: D+=[c]*b if len(D)>N: break if len(D)<N: D+=[0]*(N-len...
p03038
import bisect import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int,input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) class Counter: def __init__(self): self.dict = {} def ad...
import sys sys.setrecursionlimit(10**9) def mi(): return list(map(int,input().split())) def ii(): return int(eval(input())) def isp(): return input().split() def deb(text): print(("-------\n{}\n-------".format(text))) class Counter: def __init__(self): self.dict = {} def add(self,x): ...
p03038
import heapq class mcf_graph_int_cost: """ costが整数の時の高速化。 """ def __init__(self, n): self.n = n self.log = (n.bit_length() + 7) // 8 * 8 self.mask = (1 << self.log) - 1 self.pos = [] self.g = [[] for _ in range(n)] def add_edge(self, from_, ...
import heapq class mcf_graph_int_cost: """ 頂点数、及び、costの総和が、4294967295 (== (1 << 32) - 1) を超えない前提下での高速な実装。 後者は超えても一応動く。 """ def __init__(self, n): self.n = n self.pos = [] self.g = [[] for _ in range(n)] def add_edge(self, from_, to, cap, cost): ...
p02562
from heapq import heappop, heappush, heapify class MinCostFlow(): def __init__(self, n): self.n = n self.graph = [[] for _ in range(n)] self.pos = [] def add_edge(self, fr, to, cap, cost): assert 0 <= fr < self.n assert 0 <= to < self.n m = len(self.p...
from heapq import heappop, heappush, heapify class MinCostFlow(): def __init__(self, n): self.n = n self.graph = [[] for _ in range(n)] self.pos = [] def add_edge(self, fr, to, cap, cost): #assert 0 <= fr < self.n #assert 0 <= to < self.n m = len(self...
p02562
#-------最強ライブラリMinCostFlow(Python)------ #速度確認 import heapq # numeric_limitsわかんね NUMERIC_LIMITS = 10 ** 18 class mcf_graph: pos = [] def __init__(s): None def __init__ (s, n): s._n = n s.g = [[] for _ in range(n)] def add_edge(s, frm, to, cap, cost): m = len(s.pos) s.pos....
import heapq # numeric_limitsわかんね NUMERIC_LIMITS = 10 ** 18 class mcf_graph: pos = [] def __init__ (s, n): s._n = n s.g = [[] for _ in range(n)] def add_edge(s, frm, to, cap, cost): m = len(s.pos) s.pos.append([frm, len(s.g[frm])]) s.g[frm].append(s._edge(to, len(s.g[to]), cap, ...
p02562
import heapq # numeric_limitsわかんね NUMERIC_LIMITS = 10 ** 18 class mcf_graph: def __init__ (s, n): s._n = n s.g = [[] for _ in range(n)] s.pos = [] def add_edge(s, frm, to, cap, cost): m = len(s.pos) s.pos.append([frm, len(s.g[frm])]) s.g[frm].append(s._edge(to, len(s.g[to]), c...
import heapq # numeric_limitsわかんね NUMERIC_LIMITS = 10 ** 18 class mcf_graph: def __init__ (s, n): s._n = n s.g = [[] for _ in range(n)] s.pos = [] def add_edge(s, frm, to, cap, cost): m = len(s.pos) s.pos.append([frm, len(s.g[frm])]) s.g[frm].append(s._edge(to, len(s.g[to]), c...
p02562
from heapq import heappush, heappop class MinCostFlow: INF = 10**18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] se...
from heapq import heappush, heappop class MinCostFlow: INF = 10**18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): forward = [to, cap, cost, None] backward = forward[3] = [fr, 0, -cost, forward] se...
p02562
import heapq class mcf_graph: def __init__(self, n=0): self._n = n self.g = [[] for _ in range(n)] self.pos = [] def add_edge(self, frm, to, cap, cost): m = len(self.pos) e1 = self._edge(to, cap, cost) e2 = self._edge(frm, 0, -cost) e1.rev ...
import heapq class mcf_graph: def __init__(self, n=0): self._n = n self.g = [[] for _ in range(n)] self.pos = [] def add_edge(self, frm, to, cap, cost): m = len(self.pos) e1 = self._edge(to, cap, cost) e2 = self._edge(frm, 0, -cost) e1.rev ...
p02562
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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1)...
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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1)...
p02562
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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1)...
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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1)...
p02562
import sys input=sys.stdin.readline import heapq n,q=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] L1=[] for i in range(n): L1.append([l[i][0]-l[i][2],1,l[i][2]]) L1.append([l[i][1]-l[i][2],-1,l[i][2]]) for i in range(q): L1.append([int(eval(input())),2,0]) L1.sort...
import sys input=sys.stdin.readline import heapq n,q=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(n)] L1=[] for i in range(n): L1.append((l[i][0]-l[i][2],1,l[i][2])) L1.append((l[i][1]-l[i][2],-1,l[i][2])) for i in range(q): L1.append((int(eval(input())),2,0)) L1.sort...
p03033
import sys from heapq import * input = sys.stdin.readline def main(): n, q = list(map(int, input().split())) key = [] for i in range(n): s, t, x = list(map(int, input().split())) l, r = max(0, s-x), max(0, t-x) key.append((l, 1, x)) key.append((r, -1, x)) ...
import sys from heapq import * input = sys.stdin.readline def main(): n, q = list(map(int, input().split())) key = [] for i in range(n): s, t, x = list(map(int, input().split())) l, r = max(0, s-x), max(0, t-x) key.append((l, 1, x)) key.append((r, -1, x)) ...
p03033
from heapq import heapify, heappush, heappop INF = 1001001001 N, Q = list(map(int, input().split())) STXs = [tuple(map(int, input().split())) for _ in range(N)] Ds = [int(eval(input())) for _ in range(Q)] #S-X, T-X, X future_block = [(S - X, T - X, X) for S, T, X in STXs] future_block.append((INF, INF, IN...
from heapq import heapify, heappush, heappop INF = 1001001001 N, Q = list(map(int, input().split())) STXs = [tuple(map(int, input().split())) for _ in range(N)] Ds = [int(eval(input())) for _ in range(Q)] #S-X, T-X, X future_block = [(S - X, T - X, X) for S, T, X in STXs] future_block.append((INF, INF, IN...
p03033
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdi...
import sys import itertools # import numpy as np import time import math import heapq from collections import defaultdict from collections import Counter sys.setrecursionlimit(10 ** 7) INF = 10 ** 18 MOD = 10 ** 9 + 7 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdi...
p03033
import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, X, 1) L[2 * i + 1] = (T-X, X, -1) for i in range(Q): D = int(eval(input())) L[2 * N + i] = (D, 10**9+1, 0) L.sort() Xs = set([]) X...
import sys input = sys.stdin.readline import heapq N, Q = (int(i) for i in input().split()) L = [0] * (2 * N + Q) for i in range(N): S, T, X = (int(i) for i in input().split()) L[2 * i] = (S-X, 1, X) L[2 * i + 1] = (T-X, -1, X) for i in range(Q): D = int(eval(input())) L[2 * N + i] = (D...
p03033
def main(): import sys import heapq N, Q = list(map(int, sys.stdin.readline().split())) events = [] for i in range(N): s, t, x = list(map(int, sys.stdin.readline().split())) events.append((s - x, 1, x)) # 通行止め追加 events.append((t - x, -1, x)) # 通行止め削除 ev...
def main(): import sys import heapq N, Q = list(map(int, sys.stdin.readline().split())) events = [] for i in range(N): s, t, x = list(map(int, sys.stdin.readline().split())) events.append((s - x, 1, x)) # 通行止め追加 events.append((t - x, -1, x)) # 通行止め削除 fo...
p03033
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline N,Q = list(map(int,input().split())) q = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: q.append((s-x,1,x)) # xで死ぬ q.append((t-x,0,x)) # xで死ななくなる for i in range(Q): d = int(eval(input())) q....
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline N,Q = list(map(int,input().split())) q = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: q.append((s-x,1,x)) # xで死ぬ q.append((t-x,0,x)) # xで死ななくなる for i in range(Q): d = int(eval(input())) q....
p03033
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N,Q = list(map(int,input().split())) task = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: task.append((t-x,0,x)) # xで止まらなくなる ...
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N,Q = list(map(int,input().split())) task = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: task.append((t-x,0,x)) # xで止まらなくなる ...
p03033
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N,Q = list(map(int,input().split())) task = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: task.append((t-x,0,x)) # xで止まらなくなる ...
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N,Q = list(map(int,input().split())) task = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: task.append((t-x,0,x)) # xで止まらなくなる ...
p03033
#D in [S_i-X_i,T_i-X_i) → Xiで止まる import sys input = sys.stdin.readline from heapq import heappop,heappush from collections import defaultdict N,Q = list(map(int,input().split())) task = [] STX = [[int(x) for x in input().split()] for _ in range(N)] for s,t,x in STX: task.append((t-x,0,x)) # xで止まらなくなる ...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappush, heappop from collections import defaultdict N,Q = list(map(int,readline().split())) data = list(map(int,read().split())) S = data[:3*N:3] T = data[1:3*N:3] X = da...
p03033
#!/usr/bin/env python """<https://github.com/cheran-senthil/PyRival>""" import collections import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from builtins import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: _str = str ...
#!/usr/bin/env python """<https://github.com/cheran-senthil/PyRival>""" import collections import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from builtins import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip else: _str = str ...
p03033
#13:12 n,q = list(map(int,input().split())) import heapq import sys input = sys.stdin.readline event = [] for _ in range(n): s,t,x = list(map(int,input().split())) heapq.heappush(event,[s-x,t-x,x]) t = 0 now = [] for _ in range(q): d = int(eval(input())) if event: while event[0][0] <= d: ...
#13:12 n,q = list(map(int,input().split())) import heapq import sys input = sys.stdin.readline event = [] for _ in range(n): s,t,x = list(map(int,input().split())) heapq.heappush(event,(s-x,t-x,x)) t = 0 now = [] for _ in range(q): d = int(eval(input())) if event: while event[0][0] <= d: ...
p03033
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Jun 15 16:58:00 2019 @author: YudNK """ import bisect as bs N, Q = map(int, input().split()) E = [] for i in range(N): s, t, x = map(int, input().split()) a = [s - x, t - x, x] #イベント E.append(a) E.sort(key = lambda x: x[2]) ...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Jun 15 16:58:00 2019 @author: YudNK """ import bisect as bs N, Q = map(int, input().split()) E = [] for i in range(N): s, t, x = map(int, input().split()) a = [s - x, t - x, x] #イベント E.append(a) E.sort(key = lambda x: x[2]) ...
p03033
N, Q = list(map(int, input().split())) X = [list(map(int, input().split())) for _ in range(N)] X.sort(key = lambda x: x[2]) X.append([-1, 1, X[-1][2] + 1]) def quitConst(t): nextx = [x for x in X if x[1] > t + x[2] or x[0] == -1] return nextx def startConst(t): nextx = [x for x in X if x[0] <= t + x[2] ...
from bisect import bisect_left as bl N, Q = map(int, input().split()) X = [list(map(int, input().split())) for _ in range(N)] X.sort(key = lambda x: x[2]) Y = [int(input()) for _ in range(Q)] res = [-1] * Q jump = [-1] * Q for s,t,x in X: l=bl(Y,s - x) r=bl(Y,t - x) while l < r: s = jump[l] if...
p03033
if __name__ == '__main__': N,Q=list(map(int,input().split())) events=[list(map(int,input().split())) for _ in range(N)] D=[int(eval(input())) for i in range(Q)] ans=[-1]*Q skip=[-1]*Q events.sort(key=lambda x:x[2]) import bisect for S,T,X in events: right=bisect.bisect_l...
import bisect import sys input = sys.stdin.readline n, q = list(map(int, input().split())) events = [list(map(int, input().split())) for _ in range(n)] events.sort(key=lambda x: x[2]) departures = [int(eval(input())) for _ in range(q)] ans = ['-1'] * q skip = [-1] * q for start, end, pos in events:...
p03033
if __name__ == '__main__': N,Q=list(map(int,input().split())) events=[list(map(int,input().split())) for _ in range(N)] D=[int(eval(input())) for i in range(Q)] ans=["-1"]*Q skip=[-1]*Q events.sort(key=lambda x:x[2]) import bisect for S,T,X in events: right=bisect.bisect...
if __name__ == '__main__': import sys input=sys.stdin.readline N,Q=list(map(int,input().split())) events=[list(map(int,input().split())) for _ in range(N)] D=[int(eval(input())) for i in range(Q)] ans=["-1"]*Q skip=[-1]*Q events.sort(key=lambda x:x[2]) import bisect for...
p03033
from bisect import bisect_left, bisect_right from operator import itemgetter import sys input = sys.stdin.readline INF = float("inf") def main(): N, Q = list(map(int, input().split())) constructions = [None] * N for i in range(N): S, T, X = list(map(int, input().split())) const...
from bisect import bisect_left, bisect_right from operator import itemgetter import sys input = sys.stdin.readline def main(): N, Q = list(map(int, input().split())) constructions = [None] * N for i in range(N): S, T, X = list(map(int, input().split())) constructions[i] = (S, T,...
p03033
import sys input=sys.stdin.readline from collections import deque from heapq import heappush,heappop import re def int_raw(): return int(eval(input())) def ss_raw(): return input().split() def ints_raw(): return tuple(map(int, ss_raw())) def main(): N ,Q = ints_raw() origST ...
import sys input=sys.stdin.readline from collections import deque from heapq import heappush,heappop import re def int_raw(): return int(eval(input())) def ss_raw(): return input().split() def ints_raw(): return tuple(map(int, ss_raw())) def main(): N ,Q = ints_raw() origST ...
p03033
from heapq import heappush,heappop n,q=list(map(int,input().split())) e=[] for i in range(n): s,t,x=list(map(int,input().split())) e.append((s-x,1,x)) e.append((t-x,-1,x)) for i in range(q): d=int(eval(input())) e.append((d,2,0)) e.sort() s=set() a=[] for time_,type_,x_ in e: if type_==1: ...
import sys from heapq import heappush,heappop input=sys.stdin.readline n,q=list(map(int,input().split())) e=[] for i in range(n): s,t,x=list(map(int,input().split())) e.append((s-x,1,x)) e.append((t-x,-1,x)) for i in range(q): d=int(eval(input())) e.append((d,2,0)) e.sort() s=set() a=[] for tim...
p03033
import sys input = sys.stdin.readline def main(): n, q = list(map(int, input().split())) V = [] for i in range(n): s, t, x = list(map(int, input().split())) V.append((s-x, x, 1)) #1: insert V.append((t-x, x, 0)) #0: delete D = [] for i in range(q): ...
import sys input = sys.stdin.readline def main(): n, q = list(map(int, input().split())) V = [] for i in range(n): s, t, x = list(map(int, input().split())) V.append((s-x, x, 1)) #1: insert V.append((t-x, x, 0)) #0: delete D = [] for i in range(q): ...
p03033
from bisect import bisect_left, bisect_right class LazySegmentTree: INF = float("inf") def __init__(self, n): self.n = 1 << (n-1).bit_length() self.data = [self.INF] * (self.n*2) self.lazy = [None] * (self.n*2) def build(self, data): for i, x in enumerate(da...
import sys input = lambda: sys.stdin.readline() from bisect import bisect_left, bisect_right class LazySegmentTree: INF = float("inf") def __init__(self, n): self.n = 1 << (n-1).bit_length() self.data = [self.INF] * (self.n*2) self.lazy = [None] * (self.n*2) def bu...
p03033
import heapq import sys sys.setrecursionlimit(10 ** 7) n,q=list(map(int,input().split())) event=[] for _ in range(n): s,t,x=list(map(int,input().split())) event.append([s-x,1,x]) event.append([t-x,-1,x]) for i in range(q): event.append([int(eval(input())),2,i]) event.sort() ans=[0]*q...
import heapq import sys sys.setrecursionlimit(10 ** 7) n,q=list(map(int,input().split())) event=[] for _ in range(n): s,t,x=list(map(int,input().split())) event.append((s-x,1,x)) event.append((t-x,-1,x)) for i in range(q): event.append((int(eval(input())),2,i)) event.sort() ans=[0]*q...
p03033
from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) n,q=list(map(int,input().split())) event=[] for _ in range(n): s,t,x=list(map(int,input().split())) event.append((s-x,1,x)) event.append((t-x,-1,x)) for i in range(q): event.append((int(eval(input())),2,i)) ev...
def main(): from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) n,q=list(map(int,input().split())) event=[] for _ in range(n): s,t,x=list(map(int,input().split())) event.append((s-x,1,x)) event.append((t-x,-1,x)) for i in rang...
p03033
def main(): from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) n,q=list(map(int,input().split())) event=[] for _ in range(n): s,t,x=list(map(int,input().split())) event.append((s-x,1,x)) event.append((t-x,-1,x)) for i in rang...
from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, Q = list(map(int, readline().split())) STX = [[int(x) for x in readline().split()] for _ in range(N)] EVENT = [] for s, t...
p03033
def main(): from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n,q=list(map(int,readline().split())) stx = [[int(x) for x in readline().spli...
def main(): from heapq import heappush, heappop import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n,q=list(map(int,readline().split())) stx = [[int(x) for x in readline().spli...
p03033
"""Sorted List ============== :doc:`Sorted Containers<index>` is an Apache2 licensed Python sorted collections library, written in pure-Python, and fast as C-extensions. The :doc:`introduction<introduction>` is the best way to get started. Sorted list implementations: .. currentmodule:: sortedcontainers * :class...
"""Sorted List ============== :doc:`Sorted Containers<index>` is an Apache2 licensed Python sorted collections library, written in pure-Python, and fast as C-extensions. The :doc:`introduction<introduction>` is the best way to get started. Sorted list implementations: .. currentmodule:: sortedcontainers * :class...
p03033