input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
N,M=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() dc=[] for i in range(M): B,C=list(map(int,input().split())) dc.append([B,C]) dc.sort(key=lambda x: x[1],reverse=True) bf=False i=0 for l in dc: B,C=l while B>0: if i<N and A[i]<C: A[i]=C ...
N,M=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() dc=[] for i in range(M): B,C=list(map(int,input().split())) dc.append([B,C]) dc.sort(key=lambda x: x[1],reverse=True) bf=False i=0 for l in dc: B,C=l if bf: break while B>0: if i<N and A...
p03038
import bisect N,M = list(map(int,input().split())) A = list(map(int,input().split())) A.sort(reverse=True) D = [] for _ in range(M): D.append(list(map(int,input().split()))) D.sort(key=lambda x:x[1], reverse=True) cnt = 0 ans = [] for d in D: b,c = d[0],d[1] ans += [c for _ in range(b)] cnt += b ...
import bisect N,M = list(map(int,input().split())) A = list(map(int,input().split())) D = [] for _ in range(M): D.append(list(map(int,input().split()))) D.sort(key=lambda x:x[1], reverse=True) cnt = 0 ans = [] for d in D: b,c = d[0],d[1] ans += [c for _ in range(b)] cnt += b if cnt>=N: break...
p03038
from heapq import heapify, heappop, heappush N,M = list(map(int,input().split())) A = list(map(int,input().split())) heapify(A) for i in range(M): B,C = list(map(int,input().split())) for k in range(B): heappush(A,C) a = heappop(A) if a>=C:break print((sum(A)))
from heapq import heapify, heappop, heappush N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [] heapify(A) for i in range(M): B,C = list(map(int,input().split())) BC.append((B,C)) BC.sort(key=lambda x:-x[1]) for S in BC: B,C = S for k in range(B): heappus...
p03038
# coding: utf-8 import re import bisect from datetime import datetime as dt 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())) for i in range(b): A.append(c) A.sort() print((sum(A[len(A)-n:len(A)])))
n,m=list(map(int,input().split())) a = list(map(int,input().split())) bc=[list(map(int,input().split())) for i in [0]*m] a.sort() bc.sort(key=lambda x: x[1], reverse=True) i=0 for b,c in bc: for j in range(i,min(n,i+b)): if a[j] < c: a[j] = c i+=1 else: ...
p03038
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() S.sort(key=lambda x: x[1], reverse=True) X = [0]*(len(A)) idx = 0 for i in range(M): if idx <= N: X[idx:S[i][0]] = [S[i][1]] * S[i][0] idx += S[i]...
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() S.sort(key=lambda x: x[1], reverse=True) idx = 0 for i in range(M): for j in range(idx, min(N, idx + S[i][0])): if A[j] < S[i][1]: A[j] = S[i][...
p03038
N, M = list(map(int, input().split())) A = [int(i) for i in input().split()] for _ in range(M): B, C = list(map(int, input().split())) A.extend([C]*B) A = sorted(A, reverse=True) print((sum(A[:N])))
N, M = list(map(int, input().split())) A = [int(i) for i in input().split()] min_val = sorted(A)[0] for _ in range(M): B, C = list(map(int, input().split())) if min_val <= C: A.extend([C]*B) A = sorted(A, reverse=True) print((sum(A[:N])))
p03038
n, m = list(map(int, input().split())) a = list(map(int, input().split())) l = [] for i in range(m): data = list(map(int,input().split())) l.append(data) l.sort(key=lambda x:x[1]) import heapq heapq.heapify(a) for tmp in l: b=tmp[0] c=tmp[1] for i in range(b): heapq.heappu...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) l = [] for i in range(m): data = list(map(int,input().split())) l.append(data) l.sort(key=lambda x:x[1]) l.reverse() a.sort() b_idx=0 nokori=l[b_idx][0] for i in range(n): if a[i] > l[b_idx][1]: break el...
p03038
n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() ans=sum(a) l=[] for i in range(m): b,c=list(map(int,input().split())) l.append((b,c)) l.sort(key=lambda x:x[1],reverse=True) x=[] for i in range(m): xx=[l[i][1]]*l[i][0] x.extend(xx) c=0 while a[c]<x[c] : ans...
import bisect n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() bc=[] for i in range(m): b,c=list(map(int,input().split())) bc.append([b,c]) bc.sort(key=lambda x:x[1],reverse=True) for i in range(m): for j in range(min(bisect.bisect_left(a,bc[i][1]), bc[i][0])): ...
p03038
n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() bc=[list(map(int,input().split())) for _ in range(m)] bc.sort(key=lambda x:x[1], reverse=True) import bisect i=0 for i in range(m): if bc[i][1]>a[0]: k=min(bc[i][0],bisect.bisect_left(a,bc[i][1])) a[:k]=[bc[i][1]]...
n,m=list(map(int,input().split())) a=list(map(int,input().split())) l=[] for i in range(n): l.append([1,a[i]]) for i in range(m): l.append(list(map(int,input().split()))) l.sort(key=lambda x:x[1], reverse=True) c=0 ans=0 for i in range(n+m): ans+=l[i][1]*l[i][0] c+=l[i][0] if c>n: ...
p03038
from bisect import * N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() data = [] for _ in range(M): B, C = list(map(int, input().split())) data.append((B, C)) data.sort(key=lambda x:x[1], reverse=True) D = [] for B, C in data: i = bisect_left(A, C) if B<=i...
from bisect import * N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() data = [] for _ in range(M): B, C = list(map(int, input().split())) data.append((B, C)) data.sort(key=lambda x:x[1], reverse=True) D = [] for B, C in data: i = bisect_left(A, C) p = min...
p03038
N,M = list(map(int,input().split())) A = list(map(int,input().split())) #counter 辞書(改良版) def counter_imp(A): dic = {} for a in A: dic[a] = dic.get(a,0) + 1 return dic #counter 2次元リスト def counter_list(A): dic = counter_imp(A) C = [] for k in dic: C.append([k,dic[k]]) return...
N,M = list(map(int,input().split())) A = list(map(int,input().split())) def counter_list(A): def counter_dic(A): #counter 辞書 dic = {} for a in A: dic[a] = dic.get(a,0) + 1 return dic dic_ = counter_dic(A) B = [] for k in dic_: B.append([k,dic_[k]]) return B #(発想)数値を全部追加してソート、大きい順に「Aの要...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) C = [] for i in range(M): b, c = list(map(int, input().split())) for i in range(b): C.append(c) A.sort() C.sort(reverse=True) j = 0 while (j < len(C)) and (A[j] < C[j]): j += 1 ans = int(sum(C[:j]) + sum(A[j:])) prin...
import sys from operator import itemgetter def solve(): input = sys.stdin.readline N, M = list(map(int, input().split())) A = [int(a) for a in input().split()] A.sort() change = [[int(i) for i in input().split()] for _ in range(M)] change.sort(key = itemgetter(1), reverse = True) ...
p03038
from operator import itemgetter n,m = list(map(int,input().split())) a_list = list(map(int,input().split())) b_list = [] for i in range(m): b,c = list(map(int,input().split())) b_list.append([b,c]) #b_list[i][枚数、value] a_list.sort() b_list.sort(reverse = True,key = itemgetter(1)) #cについてソート now_position ...
from operator import itemgetter n,m = list(map(int,input().split())) a_list = list(map(int,input().split())) b_list = [] for i in range(m): b,c = list(map(int,input().split())) b_list.append([b,c]) #b_list[i][枚数、value] a_list.sort() b_list.sort(reverse = True,key = itemgetter(1)) #cについてソート sum_list = [] ...
p03038
from collections import* I=lambda:map(int,input().split()) n,m=I() a=Counter(I()) exec("b,c=I();a[c]+=b;"*m) s=0 for k,v in sorted(a.items())[::-1]: if n<v:exit(print(s+k*n)) n-=v;s+=k*v
from collections import* I=lambda:map(int,input().split()) n,m=I() a=Counter(I()) for _ in[0]*m:b,c=I();a[c]+=b s=0 for k,v in sorted(a.items())[::-1]: if n<v:exit(print(s+k*n)) n-=v;s+=k*v
p03038
n,m = list(map(int,input().split())) a = sorted([int(x) for x in input().split()]) for i in range(m): j,k = list(map(int,input().split())) a.extend([k]*j) print((sum(sorted(a,reverse=True)[:n])))
n,m = list(map(int,input().split())) a = sorted([int(x) for x in input().split()]) for i in range(m): j,k = list(map(int,input().split())) if min(a) < k: a.extend([k]*j) a = sorted(a,reverse=True)[:n] print((sum(a)))
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = [] for i in range(M): b, c = list(map(int, input().split())) for j in range(b): B.append(c) A.sort() B.sort(reverse=True) for i in range(min(N, len(B))): if A[i] < B[i]: A[i] = B[i] ans = sum(A...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) count = 0 BC = [] for i in range(M): b, c = list(map(int, input().split())) BC.append((b, c)) A.sort() BC.sort(reverse=True, key=lambda x: x[1]) count = 0 CArr = [] for b, c in BC: if count >= N: break ...
p03038
n,m = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() B=[] C=[] for i in range(m): b,c = list(map(int,input().split())) B.append(b) C.append(c) L = list(zip(C,B)) L.sort(reverse = True) L2 = [] for i in range(m): L2.extend([L[i][0]]*L[i][1]) #print(L2) ans = 0 for i in...
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.extend([c for j in range(b)]) A.sort(reverse=True) print((sum(A[:n])))
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.extend([c for j in range(b)]) A.sort(reverse=True) print((sum(A[:n])))
n,m = list(map(int,input().split())) A = list(map(int,input().split())) CntA = [1 for i in range(n)] for i in range(m): b,c = list(map(int,input().split())) A.append(c) CntA.append(b) Z = list(zip(A,CntA)) Z.sort(reverse=True) ans = 0 for z in Z: if n>z[1]: ans+=z[1]*z[0] n-=z[1] else: ...
p03038
#!/usr/bin/env python3 import sys def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"): x = [[B[i],C[i]] for i in range(M)] x = sorted(x, key=lambda x:x[1], reverse=True) D = [] for i in range(M): D.extend([x[i][1]]*x[i][0]) A.sort() for i in ran...
#!/usr/bin/env python3 import sys def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"): x = [[B[i],C[i]] for i in range(M)] x = sorted(x, key=lambda x: -x[1]) A.sort() dn = 0 for b, c in x: for j in range(b): if(dn >= N): bre...
p03038
import heapq import sys sys.setrecursionlimit(10000) INF = float('inf') N, M = list(map(int, input().split())) A = list(map(int, input().split())) B, C = list(zip(*[list(map(int, input().split())) for _ in range(M)])) heap = A heapq.heapify(heap) for b, c in zip(B, C): for _ in range(b): ...
import sys sys.setrecursionlimit(10000) INF = float('inf') N, M = list(map(int, input().split())) A = list(map(int, input().split())) CB = [list(map(int, reversed(input().split()))) for _ in range(M)] A.sort() CB.sort() ans = 0 for _ in range(N): a = A[-1] if A else -INF c, b = CB[-1] if CB e...
p03038
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] A = [int(x) for x in stdin.readline().rstrip().split()] BC = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)] BC.sort(key=lambda x: x[1], reverse=True) for i in range(M): A = A + [BC[i][1]] * BC[i][0] ...
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] A = [int(x) for x in stdin.readline().rstrip().split()] BC = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)] BC.sort(key=lambda x: x[1], reverse=True) for i in range(M): A.extend([BC[i][1]] * BC[i][0]) ...
p03038
N,M = list(map(int,input().split())) A = list(map(int,input().split())) A = sorted(A) BC = [list(map(int,input().split())) for i in range(M)] BC.sort(key = lambda x:-x[1]) index = 0 for i in range(len(BC)): for j in range(BC[i][0]): if index == len(A) or A[index] >= BC[i][1]: break ...
N,M = list(map(int,input().split())) A = list(map(int,input().split())) A.sort() BC = [list(map(int,input().split())) for i in range(M)] BC.sort(key = lambda x:-x[1]) index = 0 l = len(A) for i in range(len(BC)): for j in range(BC[i][0]): if index == l or A[index] >= BC[i][1]: brea...
p03038
N,M=list(map(int,input().split())) *A,=list(map(int,input().split())) BC=[list(map(int,input().split()))[::-1]for _ in range(M)] L=[0] for c,b in BC: L+=[c]*b ans=sorted(A+L)[::-1] print((sum(ans[:N])))
N,M=list(map(int,input().split())) *A,=list(map(int,input().split())) BC=[list(map(int,input().split()))[::-1]for _ in range(M)] BC=sorted(BC)[::-1] L=[0] for c,b in BC: L+=[c]*b if len(L)-1>N: break ans=sorted(A+L)[::-1] print((sum(ans[:N])))
p03038
from collections import defaultdict N, M = list(map(int, input().split())) A = list(map(int, input().split())) numCnt = defaultdict(int) for a in A: numCnt[a] += 1 for _ in range(M): B, C = list(map(int, input().split())) numCnt[C] += B ans = 0 numList = list(numCnt.items()) numList.sor...
from collections import Counter N, M = list(map(int, input().split())) A = list(map(int, input().split())) cntA = Counter(A) for _ in range(M): B, C = list(map(int, input().split())) cntA[C] += B ans = 0 for val, cnt in sorted(list(cntA.items()), reverse=True): ans += val * min(N, cnt) N -...
p03038
import bisect n, m = list(map(int, input().split())) nums = list(map(int, input().split())) nums.sort() ops = [] for i in range(m): b, c = list(map(int, input().split())) ops.append([b, c]) total = 0 for b, c in sorted(ops, key=lambda x:x[1], reverse=True): if c < nums[0]: break...
n, m = list(map(int, input().split())) nums = list(map(int, input().split())) ops = [] for i in nums: ops.append([1, i]) for i in range(m): b, c = list(map(int, input().split())) ops.append([b, c]) total = 0 sums = [] for b, c in sorted(ops, key=lambda x:x[1], reverse=True): if to...
p03038
import sys # sys.setrecursionlimit(100000) import heapq def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): from collections import Counter n, m = input_int_l...
import sys # sys.setrecursionlimit(100000) import heapq def input(): return sys.stdin.readline().strip() def input_int(): return int(eval(input())) def input_int_list(): return [int(i) for i in input().split()] def main(): from collections import Counter # 計算量 O(n*log_n + ...
p03038
import collections n, m = [ int(v) for v in input().split() ] num_list = [ int(v) for v in input().split() ] total_counter = collections.Counter([]) for i in range(m): b, c = [ int(v) for v in input().split() ] total_counter[c] += b for i in num_list: total_counter[i] += 1 total_counter_2 = ...
import sys input = sys.stdin.readline def swap(a): return ((a[1],a[0])) n, m = [ int(v) for v in input().split() ] num_list = [ (int(v), 1) for v in input().split() ] change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ] total_list = sorted(num_list + change_list, reverse = True...
p03038
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() from bisect import bisect_left b = [] for i in range(m): b.append(list(map(int, input().split()))) b.sort(key=lambda x: x[1], reverse=True) cur = 0 ans = 0 for e in b: t = bisect_left(a[cur:], e[1]) ans += min(t, e[0])...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() from bisect import bisect_left b = [list(map(int, input().split())) for i in range(m)] b.sort(key=lambda x: x[1], reverse=True) cur = 0 ans = 0 for e in b: t = bisect_left(a, e[1]) if t>=cur: ans += min(t-cur, e[0])*e...
p03038
from sys import stdin N,M=[int(x) for x in stdin.readline().rstrip().split()] A=[int(x) for x in stdin.readline().rstrip().split()] data=[] A = sorted(A) for i in range(M): r,q=[int(x) for x in stdin.readline().rstrip().split()] if q >= A[0]: for j in range(r): A.append(q) ans =...
from sys import stdin N,M=[int(x) for x in stdin.readline().rstrip().split()] A=[(int(x),1) for x in stdin.readline().rstrip().split()] data=[] for i in range(M): r,q=[int(x) for x in stdin.readline().rstrip().split()] A.append((q,r)) ans=0 cnt=0 for j in reversed(sorted(A)): cnt+=j[1] ans+=(...
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 += [ c ] * b a.sort() print((sum(a[-N:])))
N, M = list(map( int, input().split() )) a = list( map( int, input().split() ) ) d = [] for i in range( M ): b, c = list(map( int, input().split() )) d += [ c ] * b d.sort() a += d a.sort() print((sum(a[-N:])))
p03038
n, m = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) bc = [list(map(int, input().split())) for _ in range(m)] for i in range(m): listnum=bc[i][0] tplist=[bc[i][1]] templist=tplist*listnum a.extend(templist) a=sorted(a,reverse=True) print((sum(a[:n])))
n, m = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) bc = [list(map(int, input().split())) for _ in range(m)] [a.extend([bc[i][1]]*bc[i][0]) for i in range(m)] print((sum(sorted(a,reverse=True)[:n])))
p03038
n, m = list(map(int, input().split())) a = sorted(list(map(int, input().split()))) bc = [list(map(int, input().split())) for _ in range(m)] [a.extend([bc[i][1]]*bc[i][0]) for i in range(m)] 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)] sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1]) new_ab=[] ans=[] for i in range(m): if len(new_ab)<=n: tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0] new_ab+=tmp_l ...
p03038
import sys from bisect import bisect_left input = sys.stdin.readline N, M = [int(x) for x in input().strip().split()] A = sorted([int(x) for x in input().strip().split()]) BC = [0] * M for m in range(M): BC[m] = tuple([int(x) for x in input().strip().split()]) BC.sort(reverse=True, key=lambda x: x[1]) ...
import sys from bisect import bisect_left input = sys.stdin.readline N, M = [int(x) for x in input().strip().split()] A = sorted([int(x) for x in input().strip().split()]) BC = [0] * M for m in range(M): BC[m] = tuple([int(x) for x in input().strip().split()]) BC.sort(reverse=True, key=lambda x: x[1]) ...
p03038
n,m = list(map(int,input().split())) bc = {} a = list(input().split()) for i in a: if i in bc: bc[i] += 1 else: bc[i] = 1 for i in range(m): b,c = input().split() b = int(b) if c in bc: bc[c] += b else: bc.update({c:b}) key = sorted(bc) for k in range(len(key)): key[k] = i...
n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [] for i in range(m): b,c = list(map(int,input().split())) bc.append((b,c)) bc = sorted(bc,key=lambda x:x[1]) bc.reverse() count = 0 for b,c in bc: count += b a += [c] * b if count >= n: break a.sort() a.reverse() ...
p03038
n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [] for i in range(m): b,c = list(map(int,input().split())) bc.append((b,c)) bc = sorted(bc,key=lambda x:x[1]) bc.reverse() count = 0 for b,c in bc: count += b a += [c] * b if count >= n: break a.sort() a.reverse() ...
import sys def main(): n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [] for i in range(m): b,c = list(map(int,input().split())) bc.append((b,c)) bc = sorted(bc,key=lambda x:x[1]) bc.reverse() count = 0 for b,c in bc: count += b a += [c] * b ...
p03038
n,m = list(map(int,input().split())) a = list(map(int,input().split())) min_a = min(a) bc = [] for _ in range(m): b, c = (int(x) for x in input().split()) bc.append([b,c]) bc = sorted(bc, key=lambda x: -x[1]) memo = [] limit = 0 for i in range(m): a = a + [bc[i][1]]*bc[i][0] li...
n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [] for _ in range(m): b, c = (int(x) for x in input().split()) bc.append([b,c]) bc = sorted(bc, key=lambda x: -x[1]) memo = [] limit = 0 for i in range(m): a += [bc[i][1]]*bc[i][0] limit += bc[i][0] ...
p03038
import heapq n,m = list(map(int,input().split())) a = list(map(int,input().split())) bc = [] for _ in range(m): b, c = (int(x) for x in input().split()) bc.append([b, c]) bc = sorted(bc, key=lambda x: -x[1]) heapq.heapify(a) for i in range(m): count = 0 if bc[i][1] < a[0]: br...
N,M = list(map(int,input().split())) A = list(map(int,input().split())) A.sort(reverse=True) BC = [] for _ in range(M): B, C = (int(x) for x in input().split()) BC.append([B, C]) BC = sorted(BC, key=lambda x: -x[1]) index = 0 ans = 0 while index < M and len(A) and A[-1] < BC[index][1]: b,...
p03038
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 sortsecond = lambda val: val[1] x = [list(map(int, input().split())) for _ in range(m)] x.sort(key=sortsecond) for j in range(m): times = x[-(j+1)][0] number = x[...
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 sortsecond = lambda val: val[1] x = [list(map(int, input().split())) for _ in range(m)] x.sort(key=sortsecond) a.sort() i = 0 for j in range(m): times = x[-(j+...
p03038
from heapq import heapify, heapreplace N,M=[int(a) for a in input().split()] A=[int(a) for a in input().split()] BC=[[int(a) for a in input().split()] for _ in range(M)] heapify(A) for B,C in BC: for _ in range(B): if C<=A[0]: break heapreplace(A, C) print((sum(A)))
from heapq import heapify, heapreplace N,M=[int(a) for a in input().split()] A=sorted([int(a) for a in input().split()]) BC=[[int(a) for a in input().split()] for _ in range(M)] B,C=list(zip(*sorted(BC, key=lambda row: row[1], reverse=True))) i,j=0,0 for k in range(N): if j>=B[i]: i+=1 j=0 ...
p03038
import heapq N,M = list(map(int,input().split(' '))) An = list(map(int,input().split(' '))) heapq.heapify(An) BC_list = [] for i in range(M): BC = list(map(int,input().split(' '))) BC_list.append(BC) BC_list.sort(reverse=True,key=lambda x: x[1]) flag = False for val in BC_list: B = val[0] C ...
import heapq N,M = list(map(int,input().split(' '))) An = list(map(int,input().split(' '))) heapq.heapify(An) BC_list = [] for i in range(M): BC = list(map(int,input().split(' '))) BC_list.append(BC) BC_list.sort(reverse=True,key=lambda x: x[1]) flag = False decided_sum = [] for val in BC_list: ...
p03038
from collections import defaultdict N, M=list(map(int, input().split())) A=list(map(int, input().split())) d=defaultdict(int) for a in A: d[a]+=1 for i in range(M): B, C=list(map(int, input().split())) d[C]+=B index_list=sorted(d) ans=0 ans_size=0 for i in range(len(index_list)-1, -1, -1): card=ind...
import heapq N, M=list(map(int, input().split())) A=list(map(int, input().split())) heapq.heapify(A) BC=[list(map(int, input().split())) for _ in range(M)] BC.sort(key=lambda x:(x[1], x[0]), reverse=True) for b, c in BC: if len(A) and A[0]>=c: break for i in range(b): if len(A) and...
p03038
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from co...
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from co...
p03038
import bisect N, M = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) for _ in range(M): B, C = list(map(int, input().split())) if C >= A[0]: if C >= A[B-1]: if C >= A[N-1]: A = A[B:] + [C]*B else: x = bisect.bi...
N, M = list(map(int, input().split())) A = sorted(map(int, input().split())) BC = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda x:x[1]) D = [] x = 0 for i in range(M-1,-1,-1): if x + BC[i][0] >= N: D += [BC[i][1]]*(N-x) break D += [BC[i][1]]*BC[i][0] x += ...
p03038
from heapq import heappush, heappop N,M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] e = [[int(i) for i in input().split()] for i in range(M)] result = 0 hq = [] for j in A: heappush(hq, (-j)) for i in e: for n in range(i[0]): heappush(hq, (-i[1])) A.sort(re...
import bisect N,M = (int(i) for i in input().split()) A = [int(i) for i in input().split()] e = [[int(i) for i in input().split()] for i in range(M)] result = 0 hoge = min(A) A.sort() for i in e: hoge = bisect.bisect_left(A,i[1]) for j in range(i[0]): A.insert(hoge,i[1]) A.pop(0) ...
p03038
import sys N, M = list(map(int, sys.stdin.readline().split())) a_list = list(map(int, sys.stdin.readline().split())) items = [] for i in range(M): items.append(tuple(map(int, sys.stdin.readline().split()))) from collections import defaultdict tar = defaultdict(int) for a in a_list: tar[a] += 1 ...
import sys N, M = list(map(int, sys.stdin.readline().split())) a_list = list(map(int, sys.stdin.readline().split())) items = [] for i in range(M): items.append(tuple(map(int, sys.stdin.readline().split()))) from heapq import * que = [] for i in range(N): a = a_list[i] heappush(que, (-a, 1)...
p03038
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = [int(_) for _ in input().split()] cb = [0] * m for i in range(m): bb, cc = list(map(int, input().split())) cb[i] = (cc, bb) cb.sort(reverse=True) arr = [] l = 0 for i in range(m): if l + cb[i][1] > 10**5: ...
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = [int(_) for _ in input().split()] cb = [0] * m for i in range(m): bb, cc = list(map(int, input().split())) cb[i] = (cc, bb) cb.sort(reverse=True) arr = [] l = 0 for i in range(m): if l + cb[i][1] > 10**5: ...
p03038
N,M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A.sort() max = 0 BC = [] for i in range(M): b,c = [int(x) for x in input().split()] max += b BC.append([c,b]) BC.sort(reverse = True) str =[] for c,b in BC: str+=[c]*b # print(str) now = 0 for i in ran...
N,M = [int(x) for x in input().split()] A = [int(x) for x in input().split()] A.sort() max = 0 BC = [] for i in range(M): b,c = [int(x) for x in input().split()] max += b BC.append([c,b]) BC.sort(reverse = True) str =[] for c,b in BC: str+=[c]*b # print(str) if(len(str) > N): ...
p03038
N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int,input().split())) for _ in range(M)] ans = [] A.sort() count = 0 for b,c in BC: ans += [c]*b ans.extend(A) ans = sorted(ans,reverse = True) print((sum(ans[:N])))
N,M = list(map(int,input().split())) A = list(map(int,input().split())) BC = [(A[i], 1) for i in range(N)] for _ in range(M): B, C = list(map(int, input().split())) BC.append((C,B)) BC = sorted(BC,reverse = True) ans = 0 a = 0 count = N for c,b in BC: lamb = min(count,b) ans += c * lamb count...
p03038
n,m=list(map(int,input().split())) from collections import deque que=deque(list(map(int,input().split()))) for _ in range(m): b,c=list(map(int,input().split())) que=sorted(que) for i in range(b): if que[0]<c: que.pop(0) que.append(c) else: break...
n,m=list(map(int,input().split())) List=sorted(list(map(int,input().split()))) s=[] for _ in range(m): s.append(list(map(int,input().split()))) s.sort(key=lambda x: x[1], reverse=True) ans=0 j=0 for i in range(m): if j>=n or s[i][1]<=List[j]: break while j<n and s[i][0]>0 and s[i][1]> L...
p03038
import bisect n, m = list(map(int, input().split())) arr = list(sorted(list(map(int, input().split())))) bc = [] for _ in range(m): b, c = list(map(int, input().split())) bc.append([b, c]) bc = list(sorted(bc, key=lambda x: x[1], reverse=True)) ans = 0 for bci in bc: d = bisect.bisect_left(a...
# 書き換える枚数は確定できる # cの大きい順にしたものでaの小さい順にしたものを置き換えるイメージ # なんか尺取っぽくなった n, m = list(map(int, input().split())) arr = sorted(list(map(int, input().split()))) bcs = [] for _ in range(m): bc = list(map(int, input().split())) bcs.append(bc) bcs = sorted(bcs, key=lambda x: x[1], reverse=True) ans = 0 i ...
p03038
from bisect import bisect N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()]) BC = [[int(i) for i in input().split()] for i in range(M)] BC = sorted(BC, key=lambda x:-x[1]) ans = 0 for b, c in BC: i = bisect(A, c) i = min(i, b) A = A[i:] ans += c * i print((an...
from bisect import bisect N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()]) BC = [[int(i) for i in input().split()] for i in range(M)] BC = sorted(BC, key=lambda x:-x[1]) ans = 0 offset=0 for b, c in BC: i = bisect(A, c, lo=offset) i = min(i-offset, b) ans += c...
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())) count = 0 while count < b: a.append(c) count += 1 a.sort(reverse=True) print((sum(a[:n])))
n, m = list(map(int, input().split())) a = list(map(int, input().split())) l = [] for i in range(m): b, c = list(map(int, input().split())) l.append((b, c)) for i in a: l.append((1, i)) l.sort(key=lambda x: x[1], reverse=True) #print(l) count = n ans = 0 for item in l: b, c = item ans ...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) b = [] for i in range(M): b.append(list(map(int, input().split()))) A.sort() b.sort(key=lambda x: x[1], reverse= True) for i in range(M): for j in range(b[i][0]): if A[j] < b[i][1]: A[j] = b[i][1] e...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) b = [] for i in range(M): b.append(list(map(int, input().split()))) ans = 0 A.sort() b.sort(key=lambda x: x[1], reverse=True) j = 0 for i in range(M): if j >= N or b[i][1] <= A[j]: break while j < N and b[i][0] an...
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 = sorted(a + [c] * b, reverse=True)[:n] print((sum(a)))
n,m = list(map(int, input().split())) a = list(map(int, input().split())) bc = [tuple(map(int, input().split())) for _ in range(m)] a.sort() bc.sort(key=lambda x:x[1], reverse=True) idx = 0 res = 0 flag = False for b,c in bc: for _ in range(b): if idx < n and a[idx] < c: res += c ...
p03038
import heapq 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 i in range(b): if A[0] < c: heapq.heappop(A) heapq.heappush(A, c) else: break p...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) D = [] for _ in range(M): d = list(map(int, input().split())) D.append(d) A.sort() D.sort(key=lambda x:x[1], reverse=True) NewCard = [] for d in D: b, c = d NewCard += [c] * b if(len(NewCard) > N): brea...
p03038
from bisect import bisect_left 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) A.sort() bisec = bisect_left ex = A.extend for i in range(M): if BC[i][1]<A[0]: break ...
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) A.sort() n = 0 i = 0 m = 0 while A[i]<BC[n][1]: A[i] = BC[n][1] m = m+1 if m >=BC[n][0]: m = 0 n = ...
p03038
import bisect N, M = list(map(int, input().split())) A_list = sorted( list( int(i) for i in input().split() )) BC_list = sorted( list( list( int(i) for i in input().split() ) for _ in range(M) ), key=lambda x:-x[1] ) n = N for bc in BC_list: for i in range(bc[0]): if bisect.bisect_right(A_list, ...
N, M = list(map(int, input().split())) A_list = sorted( list( int(i) for i in input().split() )) BC_list = sorted( list( list( int(i) for i in input().split() ) for _ in range(M) ), key=lambda x:-x[1] ) change_list = [] for bc in BC_list: change_list += [bc[1]] * bc[0] if len(change_list) >= N : ...
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())) l+=[c]*b l.sort() l=l[::-1] ans=0 #print(a,l) for i in range(n): if i<=len(l)-1: ans+=max(a[i],l[i]) else: ans+=a[i] print(ans)
import sys imput=sys.stdin.readline 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+=[c]*b l.sort() l=l[::-1] ans=0 #print(a,l) for i in range(n): if i<=len(l)-1: ans+=max(a[i],l[i]) else: ...
p03038
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) heapq.heapify(A) for i in range(M): B, C = list(map(int, input().split())) for j in range(B): if A[0] < C: heapq.heapreplace(A, C) else: break ans = sum(A) pr...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) p = [[A[i], 1] for i in range(N)] # Aのカードは各1枚ずつ for i in range(M): B, C = list(map(int, input().split())) p.append([C, B]) # CのカードをB枚追加 p.sort() p.reverse() ans = 0 cnt = N for v, n in p: num = min(cnt, n) # ...
p03038
import heapq n,m=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) heapq.heapify(a) for i in range(m): b,c=list(map(int,input().split())) for j in range(b): tmp=heapq.heappop(a) if tmp<c: heapq.heappush(a,c) else: heapq.heappush(a,tmp) break print...
import heapq n,m=list(map(int,input().split())) a=sorted(list(map(int,input().split()))) heapq.heapify(a) li=[list(map(int,input().split())) for i in range(m)] li=sorted(li,key=lambda x:x[1],reverse=True) for i in range(m): tmp=heapq.heappop(a) if tmp>li[i][1]: heapq.heappush(a,tmp) break e...
p03038
import collections n, m = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 s = 0 for _ in range(m): b, c = list(map(int, input().split())) a += [c] * b ca = collections.Counter(a) cas = sorted(list(ca.items()), key=lambda x: -x[0]) for i in range(n): if n > cnt + ca...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() bc = [list(map(int, input().split())) for _ in range(m)] bc.sort(reverse=True, key=lambda x:x[1]) i = 0 for b,c in bc: for j in range(i, min(n, i+b)): if a[j]<c: a[j] = c i = i+b print((sum(a))...
p03038
n, m = list(map(int, input().split())) a = list(map(int, input().split())) bc = [tuple(map(int, input().split())) for i in range(m)] a.sort() bc.sort(key=lambda x: -x[1]) # print(a) # print(bc) count = 0 end = False for b, c in bc: if end: break if len(a) <= 0: break for j in range(b): ...
n, m = list(map(int, input().split())) a = list(map(int, input().split())) bc = [tuple(map(int, input().split())) for i in range(m)] a.sort() bc.sort(key=lambda x: -x[1]) # print(a) # print(bc) count = 0 idx = -1 end = False for b, c in bc: if idx + b <= n-1 and a[idx+b] < c: count += b * c idx...
p03038
n,m=list(map(int,input().split())) *q, = list(map(int,input().split())) #print(q) l = [] for _ in range(m): b,c = list(map(int,input().split())) for i in range(b): l.append(c) li = q+l print((sum(sorted(li,reverse=True)[:n])))
n,m=list(map(int,input().split())) *q, = list(map(int,input().split())) #print(q) l = [list(map(int,input().split())) for _ in range(m)] l.sort(key=lambda x:x[1], reverse=True) #print(l) for b,c in l: q.extend([c]*b) if len(q) > n*2: break print((sum(sorted(q,reverse=True)[:n])))
p03038
n,m = list(map(int,input().split())) *q, = list(map(int,input().split())) l = [] for _ in range(m): b, c = list(map(int,input().split())) l.extend([c]*b) #print(l) l.sort(reverse=True) for i in l: q.extend([i]) if len(q) > 2*n: break q.sort(reverse=True) print((sum(q[:n])))
n,m = list(map(int,input().split())) *q, = list(map(int,input().split())) l = [list(map(int,input().split())) for _ in range(m)] #print(l) l.sort(key=lambda x:x[1], reverse=True) for b,c in l: q.extend([c]*b) if len(q) > 2*n: break print((sum(sorted(q,reverse=True)[:n])))
p03038
import bisect N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] A.sort() for i in range(M): b, c = [int(_) for _ in input().split()] cnt = 0 for j in range(b): if len(A) <= j: break if A[j] >= c: break cnt += 1 if cnt > 0: # A ...
N, M = [int(_) for _ in input().split()] A = [int(_) for _ in input().split()] A.sort() BC = [] for i in range(M): v = [v for v in input().split()] BC.append((int(v[0]), int(v[1]))) BC.sort(key=lambda x: -x[1]) i = 0 fin = False for b, c in BC: for _ in range(b): if i >= N: ...
p03038
n,m = list(map(int,input().split())) cards = list(map(int,input().split())) from collections import deque cards = deque(cards) for _ in range(m): b,c = list(map(int,input().split())) cards+=[c]*b cards = sorted(cards,reverse=True) total = 0 for i in range(n): total += cards[i] print...
n,m = list(map(int,input().split())) cards = list(map(int,input().split())) import heapq heapq.heapify(cards) for _ in range(m): b,c = list(map(int,input().split())) for _ in range(b): heapq.heappush(cards,c) for _ in range(len(cards) - n): heapq.heappop(cards) print((sum(cards...
p03038
import heapq N, M = list(map(int, input().split())) A = list(map(int, input().split())) heapq.heapify(A) for i in range(M): B, C = list(map(int, input().split())) for i in range(B): heapq.heappush(A, C) 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 _ in range(M)] BC = sorted(BC, key= lambda x:x[1], reverse=True) BC2 = [] for i in range(M): BC2.extend([BC[i][1]] * BC[i][0]) if len(BC2) > N : break A.extend(BC2) A.sort(reverse=True) ...
p03038
def integerCards(n, m, alist, bclist): count = 0 alist.sort() bclist.sort(key=lambda x: x[1], reverse=True) for b, c in bclist: for _ in range(b): if alist[count] < c: alist[count] = c count += 1 if count == n: ...
def integerCards(n, m, alist, bclist): count = 0 alist.sort() bclist.sort(key=lambda x: x[1], reverse=True) for b, c in bclist: for _ in range(b): if alist[count] < c: alist[count] = c count += 1 else: break ...
p03038
import sys input = sys.stdin.buffer.readline import bisect N, M = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) for i in range(M): B, C = list(map(int,input().split())) index = bisect.bisect_left(A,C) if B < index : A = [C] * (B) + A[B:] else: ...
import bisect import itertools N, M = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) D = [] for i in range(M): B, C = list(map(int,input().split())) D.append((B,C)) D.sort(key = lambda x:x[1],reverse = True) cnt = 0 ans = [] for b, c in D: for i in range(b): ...
p03038
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) A = sorted(list(map(int, input().split()))) query = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], ...
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = list(map(int, input().split())) A = list(map(int, input().split())) BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1]) C = [...
p03038
N,M = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A.sort() li = [0] * M for i in range(M): B,C= [int(j) for j in input().split()] lia = [C,B] li[i] = lia li.sort() seq = [] for i in range(M): lia = [li[i][0] for _ in range(li[i][1])] seq += lia for i in range...
n, m = list(map(int, input().split())) A = list(map(int, input().split())) A = sorted(A) cb_dict = {} for _ in range(m): b, c = list(map(int, input().split())) new = {c:b} if c in list(cb_dict.keys()): cb_dict[c] += b else: cb_dict.update(new) cb_dict = sorted(list(cb_dict...
p03038
import copy N,M = list(map(int,input().split())) A = [int(i) for i in input().split()] A.sort() A_copy = copy.deepcopy(A) CB = [] for i in range(M): b,c = list(map(int,input().split())) CB.append([c,b]) CB.sort(reverse = True) tmp = 0 for c,b in CB: for i in range(b): if tmp+i >= N: ...
n,m = list(map(int,input().split())) A = [int(i) for i in input().split()] A.sort() CB = [] for i in range(m): b,c = list(map(int,input().split())) CB.append([c,b]) CB.sort(reverse=True) ans = sum(A) index = 0 for c,b in CB: for i in range(b): if index >=n: print(ans) ...
p03038
N, M = [int(elm) for elm in input().split(" ")] As = [int(elm) for elm in input().split(" ")] Bs = [] Cs = [] for i in range(M): B, C = [int(elm) for elm in input().split(" ")] As += ([C] * B) t = sorted(As, reverse=True) out = sum(t[:N]) print(out)
N, M = [int(elm) for elm in input().split(" ")] As = [int(elm) for elm in input().split(" ")] dic = {} keys= [] for A in As: if A not in keys: dic[A] = 1 keys.append(A) else: dic[A] += 1 Bs = [] Cs = [] for i in range(M): B, C = [int(elm) for elm in input().split...
p03038
N, M = [int(elm) for elm in input().split(" ")] As = [int(elm) for elm in input().split(" ")] dic = {} keys= [] for A in As: if A not in keys: dic[A] = 1 keys.append(A) else: dic[A] += 1 Bs = [] Cs = [] for i in range(M): B, C = [int(elm) for elm in input().split...
N, M = [int(elm) for elm in input().split(" ")] As = sorted([int(elm) for elm in input().split(" ")], reverse=True) BCs = [] for i in range(M): B, C = [int(elm) for elm in input().split(" ")] BCs.append([B, C]) BCs = sorted(BCs, key=lambda x: -x[1]) out = 0 bc_i = 0 count = 0 B, C = BCs[bc...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) B_C = [] for _ in range(M): B, C = list(map(int, input().split())) B_C.append((C, B)) B_C = sorted(B_C, reverse=True) Cs = [] rem = N for c, b in B_C: if rem >= b: Cs += [c]*b else: Cs += [c]*rem ...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) B_C = [] for _ in range(M): B, C = list(map(int, input().split())) B_C.append((C, B)) B_C = sorted(B_C, reverse=True) Cs = [] rem = N for c, b in B_C: if rem >= b: Cs += [c]*b rem -= b else: ...
p03038
N,M=list(map(int,input().split())) A=list(map(int,input().split())) CB=[[0,0] for _ in range(M)] for i in range(M): CB[i][1],CB[i][0]=list(map(int,input().split())) A.sort() CB.sort(reverse=True) #Aを小さい順に見る,Cが大きい順に変更操作をして確定していく cc=0 ans=0 for i in range(N): if cc<M: if A[i]<CB[cc][...
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N,M=MI() A=LI() CB=[[0,0]for _ in range(M)] A.sort() for i in range(M): CB[i]...
p03038
from itertools import chain n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() t=[] for i in range(m): b,c=list(map(int,input().split())) t.append([c]*b) t=list(chain.from_iterable(t)) t.sort(reverse=True) ans=0 for i in range(n): if i<len(t): ans+=max(a[i]...
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() t=[] for i in range(m): for k in range(bc[i][0]): t.append(bc[i][1]) t.sort(reverse=True) ans=0 for i in range(n): if i<len(t): ans+=max(a[i],t[i]) ...
p03038
import bisect n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() for i in range(m): b, c = [int(i) for i in input().split()] idx = bisect.bisect_left(a, c) a[idx:idx]=[c]*b a = a[::-1] print((sum(a[:n])))
import bisect n, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() d = [] cnt = 1 for i in range(n-1): if a[i+1] == a[i]: cnt += 1 else: d.append([a[i], cnt]) cnt = 1 d.append([a[n-1], cnt]) for i in range(m): b, c = [int(i) for i ...
p03038
# TLEを承知で出す n, m = list(map(int, input().split())) nums = sorted([int(i) for i in input().split()])[::-1] for _ in range(m): a, b = list(map(int, input().split())) nums += [b] * a nums = sorted(nums)[::-1] print((sum(nums[:n])))
# from collections import defaultdict # n, m = map(int, input().split()) # nums = [int(i) for i in input().split()] # # num_freq = defaultdict(int) # # for _ in range(m): # b, c = map(int, input().split()) # num_freq[c] += b # # # new_list = [] # for num, freq in sorted(num_freq.items(), key=lambda ...
p03038
N,M=list(map(int, input().split())) import sys def input(): return sys.stdin.readline().strip() 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) from bisect import bisect_left ans=0 for m in range(M): if BC[m][0]<len(...
N,M=list(map(int, input().split())) import sys def input(): return sys.stdin.readline().strip() 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) from bisect import bisect_left ans=0 l=0 for m in range(M): if BC[m][0]...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) BC = [list(map(int, input().split())) for _ in range(M)] for i in range(M): A += [BC[i][1]] * BC[i][0] print(( sum(sorted(A, reverse=True)[:N]) ))
N, M = list(map(int, input().split())) A = list(map(int, input().split())) D = [(A[i], 1) for i in range(N)] for i in range(M): B, C = (list(map(int, input().split()))) D.append((C, B)) D.sort() D.reverse() ans, left = 0, N for (i, j) in D: use = min(j, left) ans += use * i left -= u...
p03038
n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() tmp=[] change=[] for i in range(m): q,r=list(map(int,input().split())) tmp.append([r,q]) tmp.sort(reverse=True) for i in range(0,m): t=0 cnt=0 while t<tmp[i][1]: change.append(tmp[i][0]) t+=1...
n,m=list(map(int,input().split())) a=list(map(int,input().split())) rep=[] for i in range(m): b,c=list(map(int,input().split())) rep.append([c,b]) rep.sort(reverse=True) Card=[0]*n cnt=0 fg=0 while fg<n and cnt<m: tt=0 while tt<rep[cnt][1] and fg+tt <n : Card[fg+tt]=rep[cnt][0] ...
p03038
N, M = list(map(int, input().split())) A = sorted([int(i) for i in input().split()]) min_A = A[0] BC = [[int(i) for i in input().split()] for _ in range(M)] for B, C in BC : if C > min_A : A += [C] * B A = sorted(A)[B:] min_A = A[0] print((sum(A)))
N, M = list(map(int, input().split())) A = [[1, int(i)] for i in input().split()] BC = A + [[int(i) for i in input().split()] for _ in range(M)] BC.sort(key=lambda x: x[1], reverse=True) i = 0 res = 0 for B, C in BC : if i + B <= N : res += C * B i += B else : res += C *...
p03038
import heapq from operator import itemgetter n,m = list(map(int,input().split())) a = list(map(int,input().split())) info = [0] * m for i in range(m): info[i] = list(map(int,input().split())) info = sorted(info,key = itemgetter(1),reverse = True) reinfo = info[0:n] #print(a) heapq.heapify(a) ...
import heapq from operator import itemgetter n,m = list(map(int,input().split())) a = list(map(int,input().split())) info = [0] * m for i in range(m): info[i] = list(map(int,input().split())) info = sorted(info,key = itemgetter(1),reverse = True) #print(a) heapq.heapify(a) #print(a) d = 0 ...
p03038
import cProfile n,m = list(map(int,input().split())) a = list(map(int, input().split())) a.sort() s = [] for i in range(m): b,c = list(map(int,input().split())) s += [c]*b s.sort() s.reverse() d = len(s) #print(a[n-1]) for i in range(n): if s[0] > a[i]: a[i] = s[0] s.rem...
n,m = list(map(int,input().split())) a = list(map(int, input().split())) a.sort() e =0 bc = [] for i in range(m): d = list(map(int,input().split())) bc.append([d[1],d[0]]) e += d[0] #print(a) bc.sort() bc.reverse() #print(bc) #print(e) #print(a[n-1]) j = 0 for i in range(n): ...
p03038
def main(): N, M = list(map(int, input().split())) C = list(map(int, input().split())) C = sorted(C) AB = [list(map(int, input().split())) for i in range(M)] AB = sorted(AB, key=lambda x: x[1], reverse=True) AB = [ab[1] for ab in AB for i in range(ab[0])] index = min([N, len(AB)]) result = 0...
def main(): N, M = list(map(int, input().split())) C = list(map(int, input().split())) C = sorted(C) AB = [list(map(int, input().split())) for i in range(M)] AB = sorted(AB, key=lambda x: x[1], reverse=True) result = 0 i, j = 0, 0 while i < N: A, B = AB[j] if j < M else (0, 0) j +=...
p03038
import heapq n,m = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] bc = [] for i in range(m): bc.append([int(_) for _ in input().split()]) bc = sorted(bc, key=lambda x:x[1]) heapq.heapify(a) for _ in range(m): b,c = bc.pop() for i in range(b): num = heapq.heapp...
import bisect n,m = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] bc = [] for i in range(m): bc.append([int(_) for _ in input().split()]) bc = sorted(bc, key=lambda x:x[1]) a = sorted(a) t = 0 ans = 0 for _ in range(m): b,c = bc.pop() idx = bisect.bisect_left(a, c) ...
p03038
n,k = list(map(int,input().split())) li = list(map(int,input().split())) rc = [list(map(int,input().split())) for i in range(k)] for i in rc: li = li + [i[1]]*i[0] print((sum(sorted(li, reverse=True)[0:n])))
n,k = list(map(int,input().split())) li = list(map(int,input().split())) rc = [list(map(int,input().split())) for i in range(k)] rc.sort(key=lambda x:x[1], reverse=True) tmp = 0 for i in rc: li += [i[1]]*i[0] tmp += i[0] if tmp>n: break print((sum(sorted(li, reverse=True)[0:n])))
p03038
n,m=list(map(int,input().split())) a=[int(_) for _ in input().split()] for iii in range(m): b,c=list(map(int,input().split())) a+=[c]*b a=sorted(a,reverse=True) print((sum(a[0:n])))
from heapq import heappush, heappop n,m=list(map(int,input().split())) hq=[] for _ in input().split(): heappush(hq,(-int(_),1)) for iii in range(m): b,c=list(map(int,input().split())) heappush(hq,(-c,b)) s=0 for iii in range(n): a=heappop(hq) s-=a[0] if a[1]!=1: heappush(hq,(a[0],a[1]-1)) ...
p03038
def main(): N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] for m in range(0, M): tmp = [int(x) for x in input().split()] A.extend([tmp[1]] * min(tmp[0],N)) A.sort() A.reverse() A = A[:N] print((sum(A))) if __name__ == "__main__...
def main(): N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] changes = [] for i in range(M): changes.append([int(e) for e in input().split(" ")]) changes.sort(key=lambda x:(x[1],x[0]),reverse = True) cnt = N for i in changes: A.extend([i[1]] ...
p03038
from operator import itemgetter n, m = list(map(int, input().split())) a = list(map(int, input().split())) op = [list(map(int, input().split())) for _ in range(m)] op.sort(key=itemgetter(1), reverse=True) a.sort() idx = 0 for b, c in op: for i in range(b): if idx < n and a[idx] < c: ...
from operator import itemgetter n, m = list(map(int, input().split())) a = list(map(int, input().split())) op = [list(map(int, input().split())) for _ in range(m)] op.sort(key=itemgetter(1), reverse=True) a.sort() idx = 0 ans = 0 for i in range(n): if idx < m and op[idx][1] > a[i]: ans += op[idx...
p03038
N, M = list(map(int, input().split())) A = list(map(int, input().split())) L = [] cnt = 0 for i in range(M): L.append(list(map(int, input().split()))) sL = sorted(L, key=lambda x:x[1], reverse = True) for i in range(M): if cnt > N: break if L[i][1] <= min(A): pass else: ...
N, M = list(map(int, input().split())) A = list(map(int, input().split())) K = [1] * N L = list(zip(K,A)) for i in range(M): L.append(list(map(int, input().split()))) S = sorted(L, key = lambda x:x[1], reverse = True) sum = 0 cnt = 0 for i in range(N): if N - cnt <= S[i][0]: sum += S[i][1] * (N - cnt) ...
p03038
def main(): from heapq import heapify,heapreplace import sys input = sys.stdin.readline n,m = list(map(int,input().split())) A = list(map(int,input().split())) BC = [list(map(int,input().split())) for _ in range(m)] heapify(A) BC = sorted(BC,key=lambda x:(x[1]),reverse=True) ...
def main(): import sys input = sys.stdin.readline 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) append_list = [] for b,c in BC: if len(app...
p03038
def main(): #import sys #input = sys.stdin.readline 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) append_list = [] for b,c in BC: if len(a...
def main(): import sys input = sys.stdin.readline 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) append_list = [] for b,c in BC: if len(app...
p03038
# D - Integer Cards from operator import itemgetter from collections import deque N, M = list(map(int, input().split())) A = sorted([int(a) for a in input().split()]) BC = [] for i in range(M): b, c = list(map(int, input().split())) BC.append((b, c)) BC = sorted(BC, key=itemgetter(1), reverse=T...
# D - Integer Cards from operator import itemgetter N, M = list(map(int, input().split())) A = sorted([int(a) for a in input().split()]) BC = [] for i in range(M): b, c = list(map(int, input().split())) BC.append([b, c]) BC = sorted(BC, key=itemgetter(1), reverse=True) ans = 0 for i in range...
p03038
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() for i in range(M): b = bc[i][0] c = bc[i][1] a.extend([c for i in range(b)]) a.sort(reverse=True) print((sum(a[:N])))
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) cnt = 0 for i in range(M): b = bc[i][0] c = bc[i][1] a.extend([c for i in range(b)]) cnt += b if cnt > N...
p03038
N,M = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) BC = [] for i in range(M): a = list(map(int,input().split())) BC.append(a) BC = sorted(BC, key = lambda x:x[1],reverse = True) maxc = max([i[1] for i in BC]) Asub = [i for i in A if i <= maxc+1] for b,c in BC: count = ...
def main(): N,M = list(map(int,input().split())) A = sorted(list(map(int,input().split()))) BC = [] for i in range(M): a = list(map(int,input().split())) BC.append(a) BC = sorted(BC, key = lambda x:x[1],reverse = True) sum = 0 for b,c in BC: if sum + b <= N:...
p03038
import sys input = sys.stdin.readline 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]) extend = A.extend [extend([BC[i][1]] * BC[i][0]) for i in range(m)] A = sorted(A, reverse=True) pr...
import sys input = sys.stdin.readline 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]) extend = A.extend [extend([BC[i][1]] * BC[i][0]) for i in range(m)] A.sort(reverse=True) print((sum(A[:...
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]) extend = A.extend [extend([ls[1]] * ls[0]) for ls in BC] A.sort(reverse=True) print((sum(A[:n])))
import sys input = sys.stdin.readline 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]) maxi = n*2 extend = A.extend [extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi] A.sort(reverse=True) ...
p03038
def main(): import heapq n,m = list(map(int,input().split())) a = list(map(int,input().split())) h = [] for i in range(n): heapq.heappush(h,a[i]) for i in range(m): b,c = list(map(int,input().split())) while h[0]<c and b>0: b = b-1 heapq...
def main(): n,m = list(map(int,input().split())) a = list(map(int,input().split())) h = {} for i in range(m): b,c = list(map(int,input().split())) if c not in list(h.keys()): h[c] = b else: h[c]+=b for i in range(n): if a[i] not in l...
p03038