input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
n,m = Is()
a = Is()
for i in range(m):
b,c = Is()
a += ... | import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
n,m = Is()
a = Is()
d = collections.defaultdict(int)
for e in a:... | p03038 |
import bisect
n, m = list(map(int, input().split() ))
values = list(map(int, input().split() ))
values.sort()
for i in range(m):
max_card, num = list(map(int, input().split() ))
num_small = bisect.bisect(values, num)
num_to_change = min(max_card, num_small)
# sort
# values = values[num_to_change:n... | from operator import itemgetter
n, m = list(map(int, input().split() ))
values = list(map(int, input().split() ))
values.sort()
card_change = [list(map(int, input().split() )) for _ in range(m)]
card_change.sort(key = itemgetter(1))
# 変更後の数をkeyとしてソート
# X枚書き換えるとして、Xを全探索する方針で書いてみる
now = sum(values)
ans = sum... | p03038 |
n,m=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr=sorted(arr)
q=[list(map(int,input().split())) for _ in range(m)]
q=sorted(q,reverse=True,key=lambda x:x[0])
q=sorted(q,reverse=True,key=lambda x:x[1])
pos=0
for i in range(n):
if arr[i]<=q[pos][1]:
arr[i]=q[pos][1]
q[pos][0]-=... | n,m=list(map(int,input().split()))
ans=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(m)]
arr=sorted(arr,reverse=True,key=lambda x:x[1])
tmp=0
for cnt,val in arr:
ans+=[val]*cnt
tmp+=cnt
if tmp>=n:
break
ans=sorted(ans,reverse=True)
print((sum(ans[:n]))) | p03038 |
#!/usr/bin/env python3
import sys
import heapq
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
h = []
[heapq.heappush(h,-c) for b,c in zip(B, C) for b_ in range(b)]
[heapq.heappush(h,-a) for a in A]
k = [heapq.heappop(h) for _ in range(N)]
print((sum(k)*-1))
... | #!/usr/bin/env python3
import sys
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
bc = [c for b,c in zip(B, C) for b_ in range(b)]
# print(A+bc)
k = sorted(A+bc)[-N:]
print((sum(k)))
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools... | p03038 |
#!/usr/bin/env python3
import sys
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
bc = [c for b,c in zip(B, C) for b_ in range(b)]
# print(A+bc)
k = sorted(A+bc)[-N:]
print((sum(k)))
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools... | #!/usr/bin/env python3
import sys
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
# bc = [c for b,c in zip(B, C) for b_ in range(b)]
# print(A+bc)
# k = sorted(A+bc)[-N:]
a = [(l, 1) for l in A]
for x, y in zip(C, B):
a.append((x,y))
n = N
... | p03038 |
import heapq
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [0]*M
for i in range(M):
BC[i] = list(map(int, input().split()))
BC.sort(key = lambda x: -x[1])
for i in range(M):
if A[0] > BC[i][1]:
break
for _ in range(BC[i][0]):
... | import heapq
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [0]*M
for i in range(M):
BC[i] = list(map(int, input().split()))
BC.sort(key = lambda x: -x[1])
for B, C in BC:
if A[0] >= C:
break
for _ in range(B):
if A[0] >= C:
... | p03038 |
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Ap = []
for _ in range(M):
B,C = list(map(int,input().split()))
Ap += [C]*B
Ap.sort()
np = len(Ap)
count = 0
i,j = 0,0
while i+j < N:
a = A[N-i-1]
b = Ap[np-j-1] if j<np else 0
if a>=b and i<N:
count += a
i ... | N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
Ap = {}
for _ in range(M):
B,C = list(map(int,input().split()))
if C in list(Ap.keys()):
Ap[C] = Ap[C]+B
else:
Ap[C] = B
Clist = sorted(Ap.keys())
nc = len(Clist)
i,j,k = 0,0,0
count = 0
a = A[N-1]
while i+j < N:... | p03038 |
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
BC = []
for i in [0]*M:
#BC.append(list(map(int,input().split(' '))))
b,c = list(map(int,input().split(' ')))
A.extend([c]*b)
A.sort(reverse=True)
print((sum(A[:N])))
| N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
for i in [0]*M:
b,c = list(map(int,input().split(' ')))
A.extend([c]*b)
A.sort(reverse=True)
print((sum(A[:N])))
| p03038 |
# https://atcoder.jp/contests/abc127/tasks/abc127_d
# 難しいこと考えすぎないこと。数字を書き換えるとは言ってるけどCjをBj枚追加して大きい方からN枚取るのが最適
# 具体的にBj枚追加していくと死ぬので、枚数はタプルでその数とともに保持しておく
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
def read_tuple(H):
'''
H is number of rows
... | import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
def read_a_int():
return int(read())
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
... | p03038 |
def f(n,m):
a = list(map(int,input().split()))
min_a = min(a)
a = [(1,i) for i in a]
b_c = [tuple(map(int,input().split())) for i in range(m)]
a += b_c
a.sort(reverse=True,key=lambda x:x[1])
ans = 0
while True:
if n>a[0][0]:
ans += a[0][0]*a[0][... | def f(n,m):
a = list(map(int,input().split()))
min_a = min(a)
a = [(1,i) for i in a]
b_c = [tuple(map(int,input().split())) for i in range(m)]
a += b_c
a.sort(key=lambda x:x[1])
ans = 0
while True:
if n>a[-1][0]:
ans += a[-1][0]*a[-1][1]
... | p03038 |
def f(n,m):
a = list(map(int,input().split()))
min_a = min(a)
for i in range(m):
b,c = list(map(int,input().split()))
if c>min_a:
a += [c]*b
a.sort()
print((sum(a[len(a)-n:])))
n,m = list(map(int,input().split()))
f(n,m) | from sys import stdin
def f(n,m):
a = [int(x) for x in stdin.readline().split()]
min_a = min(a)
a = [(1,i) for i in a]
b_c = [tuple(map(int,x.split())) for x in stdin.readlines()]
a += b_c
a.sort(key=lambda x:x[1])
ans = 0
while True:
if n>a[-1][0]:
... | p03038 |
from sys import stdin
def f():
n,m = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
min_a = min(a)
a = [(1,i) for i in a]
b_c = [tuple(map(int,x.split())) for x in stdin.readlines()]
a += b_c
a.sort(key=lambda x:x[1])
ans = 0
... | from sys import stdin
def f():
n,m = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
min_a = min(a)
a = [(1,i) for i in a]
b_c = [tuple(map(int,x.split())) for x in stdin.readlines()]
a += b_c
a.sort(key=lambda x:x[1])
ans = 0
... | p03038 |
def check():
N, M = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
reverse=True, key=lambda x:x[1])
index = 0
for cnt, value in sousa:
for i in range(cnt):
... | def check():
N, M = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
reverse=True, key=lambda x:x[1])
index = 0
for cnt, value in sousa:
for i in range(cnt):
... | p03038 |
import heapq
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(M)]
heapq.heapify(a)
for b, c in bc:
for i in range(b):
hq = heapq.heappop(a)
if hq < c:heapq.heappush(a, c)
else:
heapq.he... | import heapq
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])
cnt = True
heapq.heapify(a)
for b, c in bc:
if not cnt: break
for i in range(b):
hq = heapq.heappop(a)
i... | 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(reverse=True)
A = A[0:n]
print((sum(A))) | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [[0, 0] for i in range(m)]
for i in range(m):
b, c = list(map(int, input().split()))
L[i][0] = c
L[i][1] = b
L.sort(reverse=True)
cnt = 0
for i in range(m):
c, b = L[i]
A += [c]*b
cnt += b
if cn... | p03038 |
from collections import deque
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
CB = deque([])
for i in range(M):
B, C = list(map(int, input().split()))
CB.append([C, B])
CB = sorted(CB, reverse=True)
flag = False
for i in CB:
if flag:
break
c = 0
... | from collections import deque
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
CB = deque([])
for i in range(M):
B, C = list(map(int, input().split()))
CB.append([C, B])
CB = sorted(CB, reverse=True)
flag = False
c = 0
I = 0
for i in CB:
I += i[1]
if flag:
... | p03038 |
import heapq
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
def change(A, B, C):
for i in range(B):
tmp = heapq.heappop(A)
if tmp < C:
heapq.heappush(A, C)
else:
heapq.heappush(A, tmp)
break
... | import heapq
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
B = []
C = []
for i in range(M):
tmp_B, tmp_C = list(map(int,input().split()))
B.append(tmp_B)
C.append(tmp_C)
def change(A, B, C):
for i in range(B):
tmp = heapq.heappop(A)
... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
import bisect
A.sort()
for i in range(M):
b, c = list(map(int, input().split()))
idx = bisect.bisect_left(A, c)
#print(A[:idx], A[idx:])
if idx > b:
A = A[b:idx] + [c] * b + A[idx:]
else:
#print("... |
N, M = list(map(int, input().split()))
A = list(map(int, 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)
idx = 0
c = 0
for i in range(N):
if A[i] < CB[idx][0]:
A[i] = CB[idx][0]
c ... | p03038 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
for i in range(0,m):
b, c = list(map(int, input().split()))
for j in range(0,b):
if a[j] < c:
a[j] = c
else:
break
if b != n:
... | #!/usr/bin/python3
# -*- coding: utf-8 -*-
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b_c_hash = {}
c_list = []
for i in range(0,m):
b, c = list(map(int, input().split()))
if c in b_c_hash:
b_c_hash[c] += b
else:
b_c_hash[c] = b
c... | p03038 |
N, M=list(map(int, input().split()))
a=list(map(int, input().split()))
a.sort()
import bisect
for i in range(M):
b, c=list(map(int, input().split()))
t=min(b, bisect.bisect(a,c)) # c以下の要素数
a[:t]=[c]*t
a.sort()
print((sum(a)))
| 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])
i = 0
f=0
for b, c in BC:
for j in range(b):
# 見てるとこがはみ出してないかつ、cより小さい
if i+j<n and A[i+j]<c:
A... | p03038 |
import bisect
N, M = list(map(int, input().split()))
A = [int(_) for _ in input().split()]
B = [0] * M
C = [0] * M
A.sort()
#print(A)
for m in range(M):
b, c = list(map(int, input().split()))
index = bisect.bisect_right(A, c)
#print(f'index >> {index}')
if index > 0:
if index - b <... | import sys
N, M = list(map(int, input().split()))
A = [int(_) for _ in input().split()]
A.sort()
#print(A)
BC = [0] * M
for m in range(M):
BC[m] = list(map(int, input().split()))
BC.sort(key=lambda x: x[1], reverse=True)
#print(BC)
c = 0
for m in range(M):
for t in range(BC[m][0]):
if BC[m]... | p03038 |
N, M = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [0] * M
C = [0] * M
for j in range(M):
B[j], C[j] = [int(a) for a in input().split()]
D = list(zip(C, B))
D = sorted(D, reverse=True) # Cで降順ソート
C, B = list(zip(*D)) # 統合していた配列を元に戻す
# C[0]>= C[1] >= ... >= C[M-1]となるように並び... | N, M = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [0] * M
C = [0] * M
for j in range(M):
B[j], C[j] = [int(a) for a in input().split()]
D = list(zip(C, B))
D = sorted(D, reverse=True) # Cで降順ソート
C, B = list(zip(*D)) # 統合していた配列を元に戻す
# C[0]>= C[1] >= ... >= C[M-1]となるように並び... | p03038 |
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(st... | import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(st... | p03038 |
import sys
import heapq
N,M=list(map(int,input().split()))
alist=list(map(int,input().split()))
cblist=[]
for i in range(M):
B,C=list(map(int,input().split()))
cblist.append((C,B))
cblist.sort(reverse=True)
hq=[]
for a in alist:
heapq.heappush(hq,a)
for C,B in cblist:
for i in range(B):
... | import sys
import heapq
N,M=list(map(int,input().split()))
alist=list(map(int,input().split()))
cblist=[]
for i in range(M):
B,C=list(map(int,input().split()))
cblist.append((C,B))
cblist.sort(reverse=True)
hq=[]
for a in alist:
heapq.heappush(hq,a)
for C,B in cblist:
for i in range(B):
... | p03038 |
n,m = list(map(int,input().split()))
a_n = list(map(int,input().split()))
b_and_c = []
for i in range(m):
b_and_c.append(list(map(int,input().split())))
for i in range(m):
a_n.sort()
for j in range(b_and_c[i][0]):
if a_n[j] < b_and_c[i][1]:
a_n[j] = b_and_c[i][1]
else... | n,m = list(map(int,input().split()))
a_n = list(map(int,input().split()))
b_and_c = []
for i in range(m):
b_and_c.append(list(map(int,input().split())))
a_n.sort()
b_and_c.sort(key = lambda x : x[1], reverse = True)
index = 0
for i in range(m):
if index >= n:
break
elif a_n[index] >= ... | p03038 |
#!/usr/bin/env python3
import sys
import heapq
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
from math import gcd
except Exception:
from fractions import gcd
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "L... | #!/usr/bin/env python3
import sys
import heapq
import bisect
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
from math import gcd
except Exception:
from fractions import gcd
def solve(... | 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 __ in range(b):
mn = heapq.heappop(a)
if mn < c:
heapq.heappush(a, c)
else:
heapq.... | import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
bc = sorted(
[list(map(int, input().split())) for _ in range(m)],
reverse=True,
key=lambda x: x[1],
)
for i in bc:
b, c = i
for _ in range(b):
mn = heapq.heappop(a)
... | p03038 |
d = input().split()
N = int(d[0])
M = int(d[1])
d = input().split()
As = [int(num) for num in d]
As.sort()
def main():
lis = []
for i in range(1, M+1):
d = input().split()
b = int(d[0])
c = int(d[1])
lis.append([c, b])
lis = sorted(lis,key=lambda x:(-x[0], x[... | d = input().split()
N = int(d[0])
M = int(d[1])
d = input().split()
As = [int(num) for num in d]
As.sort()
def main():
lis = []
for i in range(1, M+1):
d = input().split()
b = int(d[0])
c = int(d[1])
lis.append([c, b])
lis = sorted(lis,key=lambda x:(-x[0], x[... | p03038 |
import sys
import os
import bisect
from operator import itemgetter
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
B = [ 0 for _ in range(M)]
for i in range(M):
b,c = list(map(int,input().split()))
B[i] = [b,c]
B = sorted(B,key=itemgetter(1),reverse=True)
for i i... | import sys
import os
import bisect
from operator import itemgetter
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
B = [ 0 for _ in range(M)]
for i in range(M):
b,c = list(map(int,input().split()))
B[i] = [b,c]
B = sorted(B,key=itemgetter(1),reverse=True)
ans = 0... | p03038 |
import sys
from heapq import heapify, heapreplace
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = [int(i) for i in read().split()]
heapify(a)
for _ in range(m):
b, c = list(map(int, read().split()))
for _ in range(b... | import sys
from operator import itemgetter
from heapq import heapify, heapreplace
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = [int(i) for i in read().split()]
bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=item... | p03038 |
import sys
from operator import itemgetter
from heapq import heapify, heapreplace
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = [int(i) for i in read().split()]
bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=item... | import sys
from operator import itemgetter
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = sorted(int(i) for i in read().split())
bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
d = ... | p03038 |
import sys
from operator import itemgetter
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = sorted(int(i) for i in read().split())
bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
d = ... | def main():
n, m = list(map(int, input().split()))
a = sorted(int(i) for i in input().split())
bc = [(0, 0) for _ in range(m)]
for i in range(m):
b, c = list(map(int, input().split()))
bc[i] = (c, b)
bc.sort(reverse=True)
k = 0
d = []
for c, b in bc:
if... | p03038 |
def main():
n, m = list(map(int, input().split()))
a = sorted(int(i) for i in input().split())
bc = [(0, 0) for _ in range(m)]
for i in range(m):
b, c = list(map(int, input().split()))
bc[i] = (c, b)
bc.sort(reverse=True)
k = 0
d = []
for c, b in bc:
if... | import sys
def read():
return sys.stdin.readline().rstrip()
def main():
n, m = list(map(int, read().split()))
a = sorted(int(i) for i in read().split())
bc = [(0, 0) for _ in range(m)]
for i in range(m):
b, c = list(map(int, read().split()))
bc[i] = (c, b)
bc.so... | p03038 |
import heapq
from sys import exit
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
heapq.heapify(A)
ans = sum(A)
for b, c in BC:
for _ in range(b):
if len(A) == 0:
... | def main():
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
ind = 0
for b, c in BC:
for i in range(b):
... | p03038 |
import sys
sys.setrecursionlimit(1000000)
from collections import defaultdict
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
dict = defaultdict(int)
for i in range(M):
B, C = list(map(int, input().split()))
dict[C] += B
idx = 0
for k, v in sorted(list(dict.ite... | N, M = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
ans = 0
j = 0
b = 0
for i in range(N):
if j < M and A[i] < BC[j][1]:
ans += BC[j][1]
b += 1
if... | p03038 |
n,m = list(map(int, input().split()))
a_list = [int(a) for a in input().split()]
a_list.sort()
for i in range(m):
b,c = list(map(int, input().split()))
for j in range(b):
if a_list[j]<c:
a_list[j] = c
else:
break
a_list.sort()
print((sum(a_list))) | n,m = list(map(int, input().split()))
a_list = [int(a) for a in input().split()]
a_list.sort()
bc_list = [0 for _ in range(m)]
for i in range(m):
b,c = list(map(int, input().split()))
bc_list[i] = [b,c]
bc_list.sort(key= lambda x:x[1],reverse=True)
cur = 0
for i in range(m):
b,c = bc_list[i][0],bc... | p03038 |
#!/usr/bin/env python3
import heapq
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)
# print(bc)
heapq.heapify(a)
for b, c in bc:
for i in range(b):
num = he... | #!/usr/bin/env python3
import heapq
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)
# print(bc)
heapq.heapify(a)
for b, c in bc:
for i in range(b):
num = heap... | p03038 |
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(reverse=True, key=lambda x:x[1])
i = 0
ans = []
for b, c in bc:
N = len(ans)
for i in range(b):
if N > n-1: break
if a[N] < c:
... | 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(reverse=True, key=lambda x:x[1])
i = 0
ans = 0
for b, c in bc:
for _ in range(b):
if i > n-1: break
if a[i] < c:
ans += c
... | p03038 |
N,M = list(map(int,input().split()))
a_list = list(map(int,input().split()))
bc_list = []
for _ in range(M):
b,c = list(map(int,input().split()))
bc_list.append((b,c))
a_list = sorted(a_list)
bc_list = sorted(bc_list,key=lambda x: x[1],reverse=True)
count = 0
b_list = []
for b,c in bc_list:
i... | N,M = list(map(int,input().split()))
a_list = list(map(int,input().split()))
bc_list = []
for _ in range(M):
b,c = list(map(int,input().split()))
bc_list.append([b,c])
a_list = sorted(a_list)
bc_list = sorted(bc_list,key=lambda x: x[1],reverse=True)
tmp = 0
for i,a in enumerate(a_list):
if tmp... | 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):
d = heapq.heappop(a)
if d >= c:
heapq.heappush(a, d)
break
else:
... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
aa = [-1] * (2*n)
bc = []
for i in range(m):
b,c = list(map(int,input().split()))
bc.append((c,b))
bc.sort(reverse = True)
i = 0
for j in range(m):
if i >= n:
break
for k in range(bc[j][1]):
... | p03038 |
import sys
N, M = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
action_list = []
for i in range(M):
temp_B, temp_C = list(map(int, sys.stdin.readline().split()))
action_list.append([temp_B, temp_C])
action_list.sort(key = lambda x:x[1])
action_list.rev... | import sys
N, M = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))
action_list = []
B = []
for i in range(M):
temp_B, temp_C = list(map(int, sys.stdin.readline().split()))
action_list.append([temp_B, temp_C])
B.append(temp_B)
action_list.sort(key = l... | p03038 |
n,m = list(map(int,input().split()))
ls = list(map(int,input().split()))
di = [list(map(int,input().split())) for _ in range(m)]
for i in range(m):
ls += [di[i][1]]*di[i][0]
ls.sort()
ls = ls[n*(-1):]
print((sum(ls))) | n,m = list(map(int,input().split()))
ls = list(map(int,input().split()))
di = [list(map(int,input().split())) for _ in range(m)]
mn = min(ls)
for i in range(m):
if di[i][1] > mn:
ls += [di[i][1]]*di[i][0]
ls.sort()
ls = ls[n*(-1):]
print((sum(ls))) | p03038 |
import heapq
n,m = list(map(int,input().split()))
ls = list(map(int,input().split()))
ls = list([x*(-1) for x in ls])
di = [list(map(int,input().split())) for _ in range(m)]
heapq.heapify(ls)
for i,j in di:
for k in range(i):
heapq.heappush(ls,j*(-1))
ans = 0
for l in range(n):
ans += (-1)*he... | n,m = list(map(int,input().split()))
ls = list(map(int,input().split()))
di = [list(map(int,input().split())) for _ in range(m)]
fi = []
for i,j in di:
fi.append([j,i])
for k in ls:
fi.append([k,1])
fi.sort(reverse=True)
ans = 0
cnt = 0
how = 0
while True:
if how + fi[cnt][1] < n:
how ... | p03038 |
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
for b,c in B:A+=[c]*b
print((sum(sorted(A)[-n:]))) | from operator import itemgetter
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
C+=[c]*b
if len(C)>=n:break
print((sum(sorted(A+C)[-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 += [c] * b
a.sort(reverse = True)
print((sum(a[:n]))) | 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(reverse = True)
a = a[:n]
a.sort(reverse = True)
print((sum(a[:n]))) | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
saisyo = min(A)
saidai = max(A)
cb = []
count = 0
memo = 10 **10
for _ in range(M):
b, c = list(map(int, input().split()))
if c > saisyo and count < N: #枝刈り
A += [c] * b
if c > saidai:
if count > N:
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cb = []
for i in A:
cb += [[i,1]]
for _ in range(M):
b, c = list(map(int, input().split()))
cb += [[c, b]]
cb.sort(reverse = True)
#print (cb)
ans = 0
i = 0
j = 0
while i <= N:
a = min(N-i, cb[j][1])
ans +=... | 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 i in range(B):
e = heappop(A)
if e < C:
heappush(A, C)
else:
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
D = {}
for a in A:
if a in D:
D[a] += 1
else:
D[a] = 1
for i in range(M):
B, C = list(map(int, input().split()))
if C in D:
D[C] += B
else:
D[C] = B
K = sorted(list(D.keys()),... | p03038 |
n,m = list(map(int, input().split()))
a = list(map(int,input().split()))
for _ in range(m):
b,c = list(map(int, input().split()))
a += [c]*b
a.sort()
print((sum(a[-n:])))
| from heapq import heappop, heappush
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
pq = []
ans = 0
for a in A:
heappush(pq, [-a, 1])
for _ in range(m):
b,c = list(map(int,input().split()))
heappush(pq, [-c, b])
for i in range(n):
c,b = heappop(pq)
c... | p03038 |
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()
for B,C in BC:
for i in range(N):
if (B==0)or(A[i]>=C):
break
else:
A[i]=C
B-=1
A.sort()
print((sum(A))) | N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
D+=[C]*B
count+=B
if count>=N:
break
D=D[:N]
for i in range(len(D)):
d=D[i]
if A[i]<d:
... | p03038 |
from heapq import heapify, heapreplace
N, M = list(map(int, input("").split(" ")))
A = list(map(int, input("").split(" ")))
A = list(A)
heapify(A)
for i in range(M):
B, C = list(map(int, input("").split(" ")))
for j in range(B):
if A[0] < C:
heapreplace(A, C)
else:
... | N, M = list(map(int, input("").split(" ")))
A = list(map(int, input("").split(" ")))
A = list(A)
A.sort()
potentials = []
for i in range(M):
B, C = list(map(int, input("").split(" ")))
potentials.append((B, C))
potentials.sort(key=lambda x: x[1], reverse=True)
c = 0
for p in potentials:
... | p03038 |
import bisect
n, m = list(map(int, input().split()))
A = sorted(map(int, input().split()))
BC = []
for j 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
for b, c in BC:
i = bisect.bisect_left(A, c)
if i == 0:
... | n, m = list(map(int, input().split()))
A = sorted(map(int, input().split()))
BC = []
for j in range(m):
b, c = list(map(int, input().split()))
BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
D = []
for b, c in BC:
D.extend([c for i in range(b)])
if len(D) >= n:
D =... | p03038 |
import bisect
from collections import deque
n, m = list(map(int, input().split()))
A = deque(sorted(map(int, input().split())))
BC = []
for j in range(m):
b, c = list(map(int, input().split()))
BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
for b, c in BC:
change = 0
for ... | import bisect
from collections import deque
n, m = list(map(int, input().split()))
A = deque(sorted(map(int, input().split())))
BC = []
for j in range(m):
b, c = list(map(int, input().split()))
BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
for b, c in BC:
change = 0
for ... | p03038 |
#-*- coding:utf-8 -*-
import bisect
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
BC = [0]*M
for i in range(M):
BC[i] = [int(n) for n in input().split()]
A.sort() # 昇順ソートO(NlogN)
BC.sort(key=(lambda x: x[1]), reverse=True) # Ciの値で降順ソート
for i in range(M):
b,... | #-*- coding:utf-8 -*-
import bisect
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
BC = [0]*M
for i in range(M):
BC[i] = [int(n) for n in input().split()]
A.sort() # 昇順ソートO(NlogN)
BC.sort(key=(lambda x: x[1]), reverse=True) # Ciの値で降順ソート
st = 0 # 編集開始位置
for i in ... | p03038 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase... | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase... | p03038 |
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline
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):
min_num = heappop(A)
if min_num... | from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
heapify(A)
BC = [tuple(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: x[1], reverse=True)
for i in range(m):
for _ in ra... | p03038 |
from heapq import heappop,heappush,heapify
from collections import deque
import bisect
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [int (i) for i in input().split()]
A.sort()
D = []
P = 0
for i in range(M):
B,C = list(map(int, input().split()))
D.extend([C]*B)
P +... | from heapq import heappop, heappush, heapify
from collections import deque
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
S = []
for i in range(M):
B,C = list(map(int, input().split()))
for j in range(B):
heappush(S,-C)
A.sort()
i = 0
l = len(S)
while i < min(N,l):
q... | p03038 |
from heapq import heappop, heappush, heapify
from collections import deque
import bisect
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
for i in range(M):
B,C = list(map(int, input().split()))
for j in range(B):
idx = bisect... | N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
table = []
for i in range(N):
table.append((A[i],1))
for i in range(M):
b,c = list(map(int, input().split()))
table.append((c,b))
table.sort()
count = 0
ans = 0
while True:
c, b = table.pop()
if b <= N - count:
ans ... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = []
C = []
for i in range(M):
b, c = list(map(int, input().split()))
B.append(b)
C.append(c)
C_arr = []
for i in range(M):
for _ in range(B[i]):
C_arr.append(C[i])
C_arr.sort(reverse=True)
A.sort()
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)
temp = []
for i in range(M):
# CiをBi個追加
temp += [BC[i][1]] * BC[i][0]
if len(temp) > N:
brea... | p03038 |
import heapq
N, M = tuple(map(int, input().split()))
A = list(map(int, input().split()))
B, C = [], []
for _ in range(M):
b, c = tuple(map(int, input().split()))
B.append(b)
C.append(c)
heapq.heapify(A)
for b, c in zip(B, C):
for _ in range(b):
min_val = A[0]
if min_val <... | import heapq
N, M = tuple(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
BC.append(tuple(map(int, input().split())))
BC.sort(key=lambda x: x[1], reverse=True)
heapq.heapify(A)
for (b, c) in BC:
for _ in range(b):
min_val = A[0]
if min_val... | p03038 |
import sys
fin = sys.stdin.readline
N, M = list(map(int, fin().split()))
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]
As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)
BC_ = {}
for num, val in BC:
if val in BC_:
BC_[val] += nu... | import sys
fin = sys.stdin.readline
N, M = list(map(int, fin().split()))
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]
As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)
BC_ = {}
for num, val in BC:
if val in BC_:
BC_[val] += nu... | p03038 |
import math # noqa
import bisect # noqa
import queue # noqa
if __name__ == '__main__':
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
que = queue.PriorityQueue()
for a in A:
que.put(a)
for _ in range(M):
B, C = list(map(int, input().sp... | import math # noqa
import bisect # noqa
import queue # noqa
if __name__ == '__main__':
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = {}
for a in A:
if a not in cnt:
cnt[a] = 1
else:
cnt[a] += 1
for _ in... | p03038 |
N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
b,c = (int(x) for x in input().split())
BC_arr[i][0] = b
BC_arr[i][1] = c
A_arr.sort()
for BC in BC_arr:
Bi = BC[0]
Ci = BC[1]
for j in range(Bi)... | N,M = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]
BC_arr = [[0,0] for _ in range(M)]
for i in range(M):
b,c = (int(x) for x in input().split())
BC_arr[i][0] = b
BC_arr[i][1] = c
A_arr.sort()
BC_arr.sort(key=lambda x:x[1], reverse=True)
break_th = False
j_count =... | p03038 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(0,M):
b,c = list(map(int,input().split()))
for j in range(0,b):
A.append(c)
A.sort()
result = 0
start = len(A)-1
for k in range(start,start-N,-1):
result += A[k]
print(result)
| N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
cards.append((A[i],1))
for i in range(0,M):
b,c = list(map(int,input().split()))
cards.append((c,b))
cards.sort()
cards.reverse()
result = 0
total = N
for num, cnt in cards:
total -... | p03038 |
# 高速版input
import sys
input = sys.stdin.readline
# 二分探索
import bisect
n,m = (int(i) for i in input().split())
a = sorted([int(i) for i in input().split()])
bc = [[int(i) for i in input().split()] for i in range(m)]
for b,c in bc:
idx = bisect.bisect_left(a,c)
a = (a[:idx] + [c]*b + a[idx:])[b:]
... | # 高速版input
import sys
input = sys.stdin.readline
n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
x = []
for b,c in sorted(bc, key=lambda x: x[1], reverse=True):
x.extend([c]*b)
if len(x) > n:
break
... | 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):
p = heapq.heappop(a)
if p >= c:
heapq.heappush(a,p)
break
else:
... | n, m = list(map(int, input().split()))
a = list([[int(x),1] for x in input().split()])
for i in range(m):
b , c = list(map(int,input().split()))
a.append([c,b])
a.sort(reverse = True)
ans = 0
for x,y in a:
if y < n:
ans += x*y
n = n-y
elif y >=n:
ans += x*n
... | p03038 |
import sys
sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
readline = sys.stdin.readline
a = [int(i) for i in readline().split()]
#bc = [[int(i) for i in readline().split()] for _ in range(m)]
import heapq
heapq.heapify(a)
for i in range(m):
# b = bc[i][0]; c = bc[i][1]
b,c ... | import sys
sys.setrecursionlimit(10**6)
n, m = list(map(int, input().split()))
readline = sys.stdin.readline
A = [int(i) for i in readline().split()]
A.sort()
CB = []
for _ in range(m):
b, c = [int(i) for i in readline().split()]
CB.append([c, b])
CB.sort(reverse=True)
idx = 0
c = 0
f... | p03038 |
N,M = list(map(int,input().split()))
A_s = list(map(int,input().split()))
for _ in range(M):
B,C = list(map(int,input().split()))
A_s.extend([C] * B)
A_s = sorted(A_s)
print((sum(A_s[-N:])))
| N,M = list(map(int,input().split()))
A_s = list(map(int,input().split()))
BC_s = []
for _ in range(M):
tempB,tempC = list(map(int,input().split()))
BC_s.append([tempB,tempC])
BC_s = reversed(sorted(BC_s, key=lambda x:x[1]))
D = []
A_s = sorted(A_s)
A_s_size = N
for BC in BC_s:
B = BC[0]
C = BC... | p03038 |
n, m = list(map(int,input().split()))
l = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(m)]
# n,m = 3,2
# l = [5,1,4]
# s = [[2,3],[1,5]]
# l = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
l.sort()
s.sort(key=lambda x: x[1], reverse=True)
idx = 0
for i in range(m):
for j in ran... | n, m = list(map(int,input().split()))
l = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(m)]
# n,m = 3,2
# l = [5,1,4]
# s = [[2,3],[1,5]]
# l = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
l.sort()
s.sort(key=lambda x: x[1], reverse=True)
idx = 0
for i in range(m):
for j in ran... | p03038 |
def main():
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
bcs = [[int(i) for i in input().split()] for _ in range(M)]
bcs.sort(reverse=True,key=lambda c:c[1])
ans = 0
sel = []
for a in A:
if a < bcs[0][1]:
sel.append(a)
... | def main():
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
bcs = [[int(i) for i in input().split()] for _ in range(M)]
bcs.sort(reverse=True,key=lambda c:c[1])
ans = 0
sel = []
for a in A:
if a < bcs[0][1]:
sel.append(a)
... | p03038 |
import heapq
N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
AA = [[a, 1] for a in A]
while 2 <= len(AA) and AA[0][0] == AA[1][0] :
_, cnt = AA.pop(0)
AA[0][1] += cnt
H = []
for aa in AA :
heapq.heappush(H, aa)
for i in range(M) :
#print(H)
B, C =... | N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
A = [(1, a) for a in A]
D = [ tuple(map(int, input().split(' '))) for _ in range(M)]
AD = A + D
AD.sort(key = lambda x : -x[1])
ans = 0
cnt = 0
for ad in AD :
if N < cnt + ad[0] :
ans += ad[1] * (N - cnt)
... | p03038 |
argN,argM = list(map(int,input().split()))
aryA = list(map(int,input().split()))
wkA = aryA[:]
for i in range(argM):
argB,argC = list(map(int,input().split()))
wkA += [argC] * argB
wkA.sort()
wkA.reverse()
print((sum(wkA[:len(aryA)]))) | argN,argM = list(map(int,input().split()))
aryA = list(map(int,input().split()))
aryCB = []
for i in range(argM):
aryBC = list(map(int,input().split()))
#print(aryBC)
aryBC.reverse()
aryCB.append(aryBC[:])
#print(aryCB)
aryCB.sort(reverse=True)
#print(aryCB)
aryD = []
for i in range(len(aryCB)):
... | 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):
x=a[0]
if x<c:
heapq.heappop(a)
heapq.heappush(a, c)
else:
break
print((sum(a))) | 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([b,c])
d=sorted(d, key=lambda x: x[1], reverse=True)
i=0
j=d[0][1]
k=0
while a[i]<j:
a[i]=j
d[k][0]-=1
if d[k][0]==0:
k+=1
if k==m:
br... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
h = []
for a in A:
heapq.heappush(h, a)
for i in range(M):
B, C = list(map(int, input().split()))
for i in range(B):
vmin = heapq.heappop(h)
if vmin < C:
heapq.heappush(h, C)
... | import math
N, M = list(map(int, input().split()))
A = list(map(int, 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)
p = 0
for C, B in CB:
while p < len(A) and A[p] >= C:
p += 1
if p >= len(A):
... | p03038 |
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().spl... | import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().spl... | p03038 |
import heapq
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 i in range(b):
if A[0] < c:
heapq.heappushpop(A, c)
else:
... | import heapq
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [(1, -i) for i in A]
heapq.heapify(A)
for _ in range(M):
b, c = list(map(int, input().split()))
B.append((b,-c))
B.sort(key=lambda x: x[1])
t = 0
i = 0
... | p03038 |
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
B = [0] * M
C = [0] * M
Y = []
for i in range(M):
B[i], C[i] = list(map(int, input().split()))
Y += [C[i]] * B[i]
A.extend(Y)
A.sort(reverse=True)
print((sum(A[:N]))) | 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])
A.sort()
A.reverse()
CB.sort()
CB.reverse()
ans = 0
a_index = 0
cb_index = 0
f = 0
while True:
if f == 1 or A[a_index] >= CB[... | p03038 |
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n,m = MI()
card = LI()
for i in range(m):
b,c = MI()
card += [c]*b
card.sort(reverse = True)
print... | def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, ... | p03038 |
import queue
def integer_cards(N: int, M: int, A: list, queries: list)->int:
que = queue.PriorityQueue()
for a in A:
que.put(a)
for B, C in queries:
for _ in range(B):
x = que.get()
que.put(max(x, C))
res = 0
for _ in range(N):
r... | import queue
def integer_cards(N: int, M: int, A: list, queries: list)->int:
que = queue.PriorityQueue()
for a in A:
que.put(a)
queries.sort(key=lambda x: -x[1])
for B, C in queries:
x = que.get()
que.put(x)
if C <= x:
break
fo... | p03038 |
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7
N,M=rl()
A=rl()
B=[... | import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**... | p03038 |
n, m = list(map(int, input().split()))
cards = list(map(int, input().split()))
for i in range(m):
b, c = list(map(int, input().split()))
cards += ([c] * b)
cards.sort(reverse=True)
print((sum(cards[:n]))) | n, m = list(map(int, input().split()))
cards = list(map(int, input().split()))
for i in range(m):
b, c = list(map(int, input().split()))
cards += ([c] * b)
cards = sorted(cards, reverse=True)[:n]
print((sum(cards))) | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cards = [list(map(int, input().split())) for i in range(M)]
for card in cards:
A += [card[1]]*card[0]
A.sort(reverse=True)
print((sum(A[:N])))
| 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(reverse=True)
print((sum(A[:N])))
| p03038 |
import heapq
N, M = list(map(int, input().split()))
arr = list(map(int, input().split()))
heapq.heapify(arr)
for i in range(M):
B, C = list(map(int, input().split()))
count = 0
while True:
a = heapq.heappop(arr)
if a >= C or B <= count:
heapq.heappush(arr,a)
... | import heapq
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(M)]
heapq.heapify(a)
bc = sorted(bc, reverse=True, key=lambda x: x[1])
for i in range(M):
count = 0
while True:
t = heapq.heappop(a)
if t >= bc[i... | p03038 |
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def main():
N, M = list(map(int, input().split()))
H = []
for i in list(map(int, input().split())):
heapq.heappush(H, [-i, 1])
for i in range(M):
b, c = list(map(int, input().split()))
... | import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def main():
N, M = list(map(int, input().split()))
H = []
for i in list(map(int, input().split())):
heapq.heappush(H, (-i, 1))
for i in range(M):
b, c = list(map(int, input().split()))
... | p03038 |
n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
a = sorted(a)
l = []
for i in range(m):
b, c = list(map(int, input().split()))
x = [c]*b
l += x
a = a+l
a = sorted(a)
a = a[-n:]
print((sum(a))) | n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
a = sorted(a)
l = []
for i in range(m):
l.append(list(map(int, input().split())))
l = sorted(l, reverse=True, key=lambda x: x[1])
b = []
for _ in range(n):
b.append(l[0][1])
l[0][0] -= 1
if l[0][0] == 0:
l.pop(0... | p03038 |
import sys
from collections import deque
input = sys.stdin.readline
N, M = list(map(int, input().split()))
*A, = list(map(int, input().split()))
lis = []
for _ in range(M):
B, C = list(map(int, input().split()))
for _ in range(B):
lis.append(C)
A.sort()
d = deque(A)
lis.sort(reverse=True)
l... | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
*A, = list(map(int, input().split()))
dic = {}
for a in A:
if a in dic:
dic[a] += 1
else:
dic[a] = 1
for _ in range(M):
B, C = list(map(int, input().split()))
if C in dic:
dic[C] += B
e... | p03038 |
import heapq
nm = list([int(x) for x in input().split()])
n = nm[0]
m = nm[1]
a = list([int(x) for x in input().split()])
bc = [list([int(x) for x in input().split()]) for i in range(m)]
head_a = []
for a_item in a:
heapq.heappush(head_a, a_item)
# そーと
bc.sort(key=lambda x: x[1])
bc = list(revers... | import heapq
nm = list([int(x) for x in input().split()])
n = nm[0]
m = nm[1]
a = list([int(x) for x in input().split()])
bc = [list([int(x) for x in input().split()]) for i in range(m)]
head_a = []
for a_item in a:
heapq.heappush(head_a, a_item)
# そーと
bc.sort(key=lambda x: x[1])
bc = list(revers... | p03038 |
N,M=list(map(int,input().split()))
A=[int(i) for i in (input().split(" "))]
BC = [list(map(int,input().split())) for _ in range(M)]
for b,c in BC:
count=0
A.sort()
for i in range(b):
if c<A[i]:
break
else:
A[i]=c
suma=0
#for i in A:
# ... |
N,M=list(map(int,input().split()))
A=[int(i) for i in (input().split(" "))]
A.sort()
BC = [list(map(int,input().split())) for _ 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)
suma=0
#for i in A:
# ... | p03038 |
#!/usr/bin/env python3
import sys
from itertools import chain
def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
A = sorted(A)
bc = sorted([(b, c) for (b, c) in zip(B, C)],
key=lambda x: x[1],
reverse=True)
D = []
for b, c in bc:
... | #!/usr/bin/env python3
import sys
from itertools import chain
class BinarySearcher(object):
def __init__(self, condition, initial_values):
self.condition = condition
self.initial_values = initial_values
# all True
if self.condition(initial_values[0]):
self.... | 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)
D = []
for B, C in BC:
D += [C] * B
A+=D
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 _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
sum_B=0
for B, C in BC:
D += [C] * B
sum_B += B
if sum_B>N:
break
A+=D
A.sort(reverse = True)
print((sum... | p03038 |
N, M=list(map(int, input().split()))
a=list(map(int, input().split()))
k=sorted(a)
for i in range(M):
b, c=list(map(int, input().split()))
if c>k[0]:
for j in range(b):
if c-k[j]>0:
k[j]=c
else:
break
k.sort()
print((sum(k... | N, M=list(map(int, input().split()))
a=list(map(int, input().split()))
a.sort()
card=[]
for i in range(M):
b, c=list(map(int, input().split()))
card.append((c, b))
card.sort(reverse=True)
k=0
for c, b in card:
while k < N and b > 0:
if a[k]<c:
a[k]=c
b-=1
... | p03038 |
N, M=list(map(int, input().split()))
a=list(map(int, input().split()))
a.sort()
card=[]
for i in range(M):
b, c=list(map(int, input().split()))
card.append((c, b))
card.sort(reverse=True)
k=0
for c, b in card:
while k < N and b > 0:
if a[k]<c:
a[k]=c
b-=1
... | n, m=list(map(int, input().split()))
a=list(map(int, input().split()))
a.sort()
change=[]
for i in range(m):
b, c=list(map(int, input().split()))
change.append((c, b))
change.sort(reverse=True)
elem=0
for c, b in change:
while elem<n and b>0:
if a[elem]<c:
a[elem]=c
... | p03038 |
import sys
N, M = list(map(int, input().split()))
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort()
C = []
for _ in range(M):
b, c = list(map(int, input().split()))
C.extend([c] * b)
C.sort(reverse=True)
res = 0
for i in range(N):
if i < len(C):
if A[i] < C[i]:
... | import sys
N, M = list(map(int, input().split()))
A = list(map(int, sys.stdin.readline().rsplit()))
BC = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(M)]
A.sort()
BC.sort(reverse=True, key=lambda x: x[1])
C = []
for b, c in BC:
if len(C) >= N:
break
for _ in range(b):
... | p03038 |
x,y= list(map(int, input().split()))
a = list(map(int, input().split()))
b=[]
for _ in range(y):
b.append(list(map(int, input().split())))
b.sort(key = lambda x: x[1],reverse=True)
for l in b:
a.extend([l[1]]*l[0])
a.sort(reverse=True)
print((sum(a[:x])))
| x,y= list(map(int, input().split()))
a = list(map(int, input().split()))
#print(a)
b=[]
for _ in range(y):
b.append(list(map(int, input().split())))
b.sort(key = lambda x: x[1],reverse=True)
for l in b:
if(len(a)<=x*2):
a.extend([l[1]]*l[0])
#print(len(a))
#print(a)
a.sort(reverse=T... | p03038 |
import heapq
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
heapq.heapify(A)
bc=[]
for i in range(M):
bc.append(list(map(int,input().split())))
for i in range(M):
for j in range(bc[i][0]):
if A[0]<bc[i][1]:
heapq.heappop(A)
heapq.heappush(A,bc[i][1])
else:
... | N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
bc=[]
for i in range(M):
bc.append(list(map(int,input().split())))
bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
for j in range(bc[i][0]):
if inde<=N-1:
nbc[inde]=bc[i][1]
inde+=... | p03038 |
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = sorted([list(map(int, input().split())) for i in range(m)], key =lambda x:x[1])
t = True
cnt = 0
while t == True and cnt < len(bc):
cnt += 1
num = bc[-cnt][0]
large = bc[-cnt][1]
if large > min(a):
for i i... | n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = sorted([list(map(int, input().split())) for i in range(m)], key =lambda x:x[1])
bc.reverse()
flg = 0
cnt = 0
for i in range(n):
if bc[flg][1] >a[i] and flg < m:
a[i] = bc[flg][1]
cnt +=1
if cnt == bc[flg... | p03038 |
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = sorted([list(map(int, input().split())) for i in range(m)], key =lambda x:x[1])
bc.reverse()
flg = 0
cnt = 0
for i in range(n):
if bc[flg][1] >a[i] and flg < m:
a[i] = bc[flg][1]
cnt +=1
if cnt == bc[flg... | n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
bc = sorted([list(map(int, input().split())) for i in range(m)], key =lambda x:x[1])
bc.reverse()
flg = 0
cnt = 0
for i in range(n):
if flg < m and bc[flg][1] >a[i]:
a[i] = bc[flg][1]
cnt +=1
if cnt == bc[flg... | p03038 |
import sys
import heapq
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
n... | import sys
import heapq
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
n... | p03038 |
n, m = list(map(int, input().split()))
cards = sorted(list(map(int, input().split())))
ope = [list(map(int, input().split())) for i in range(m)]
ope.sort(key=lambda x: x[1], reverse=True)
i, j, k = 0, 0, 0
while i < n and j < m and cards[i] < ope[j][1]:
cards[i] = ope[j][1]
i += 1
k += 1
if k >... | n, m = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()])
bc = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
while b:
if i < n and a[i] < c:
a[i] = c
b -= 1
else:
... | p03038 |
from functools import cmp_to_key
n, m = list(map(int, input().split()))
a = [int(e) for e in input().split()]
bc = [[int(e) for e in input().split()] for _ in range(m)]
bc.sort(key = cmp_to_key(lambda x, y: y[1] - x[1]))
t = 0
for b, c in bc:
a.extend([c] * b)
t += b
if t > n:
break
a.sort(reverse ... | 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)
t = 0
for b, c in bc:
a.extend([c] * b)
t += b
if t > n:
break
a.sort(reverse = True)
print((sum(a[:n]))) | p03038 |
# D - Integer Cards
# https://atcoder.jp/contests/abc127/tasks/abc127_d
import sys
n, m = list(map(int, sys.stdin.readline().split()))
cards = list(map(int, sys.stdin.readline().split()))
cards.sort()
set = [list(map(int, sys.stdin.readline().split())) for _ in range(m)]
# combinations.sort(key = lambda ... | # D - Integer Cards
# https://atcoder.jp/contests/abc127/tasks/abc127_d
import sys
n, m = list(map(int, sys.stdin.readline().split()))
cards = list(map(int, sys.stdin.readline().split()))
combinations = [list(map(int, sys.stdin.readline().split())) for _ in range(m)]
cards.sort()
combinations.sort(key=la... | p03038 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.