input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import bisect
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
for _ in range(m):
l.append(list(map(int, input().split())))
a.sort()
l.sort(key=lambda x: x[1], reverse=True)
focus = 0
for b, c in l:
for j in range(focus, focus+b):
if j < n: a[j] = max(... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
for _ in range(m):
l.append(list(map(int, input().split())))
a.sort()
l.sort(key=lambda x: x[1], reverse=True)
focus = 0
for b, c in l:
for j in range(focus, min(focus+b, n)):
a[j] = max(c, a[j])
focus... | p03038 |
import sys
input = sys.stdin.readline
def sol():
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = sorted([list(map(int,input().split())) for i in range(M)],key = lambda x:-x[1])
cnt = 0
t = []
for a,b in tmp:
t=t+[b]*a
cnt+= a
i... | import sys
input = sys.stdin.readline
def sol():
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])
t = []
for a,b in tmp:
t+=[b]*a
if len(t) >=N:
... | 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, reverse=True, key=lambda x: x[1]) # Cの値で降順にソートされる
cnt = 0
com = []
for b, c in BC:
cnt += b
if cn... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
magic = [list(map(int, input().split())) for _ in range(M)]
magic = sorted(magic, key=lambda x: -x[1])
hold = []
now = 0
for k, v in magic:
hold.extend([v]*k)
now += k
if now >= N:
break
A.extend(hold)
A.sort(re... | p03038 |
import heapq
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def ii(): return int(stdin.readline())
def li(): return list(map(int, stdin.readline().split()))
N, M = tuple(li())
A = list(li())
heapq.heapify(A)
def update(pq, k, val):
# update pq in place
for _ in range(k):
cu... | import heapq
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def ii(): return int(stdin.readline())
def li(): return list(map(int, stdin.readline().split()))
N, M = tuple(li())
A = list(li())
heapq.heapify(A)
def update(pq, k, val):
# update pq in place
for _ in range(k):
cu... | p03038 |
import heapq
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
for n in range(M):
B, C = list(map(int,input().split()))
for b in range(B):
if C > A[0]:
heapq.heappushpop(A,C)
else:
break
print((sum(A)))
| import heapq
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
ls_BC = []
for m in range(M):
ls_BC.append(list(map(int,input().split())))
#print(ls_BC)
ls_BC = sorted(ls_BC, key=lambda x: x[1],reverse=True)
#print(ls_BC)
for B,C in ls_BC:
for b in range(B):
... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
cand = sorted(a)
ps = [c for b, c in sorted(p, key = lambda x : x[1], reverse = True) for _ in range(b)]
ans = 0
for candi, psi in zip(cand, ps):
ans += max(candi, psi)
ans += s... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
p = [list(map(int, input().split())) for i in range(m)]
cand = sorted(a)
ps = sorted(p, key = lambda x : x[1], reverse = True)
i = 0
ans = 0
def calc():
global i
for b, c in ps:
for d in range(b):
if i + d... | p03038 |
from operator import itemgetter
def main():
n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append((b, c))
asorted = sorted(alist)
bc = sorted(bc, key=itemgetter(1... | from operator import itemgetter
def main():
n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append((b, c))
xy = [(1, ai) for ai in alist] + bc
rest = n
total = ... | p03038 |
import sys
from collections import Counter
from bisect import insort_left
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
A = Counter(list(map(int, input().split())))
A = sorted([[a, c] for a, c in list(A.items())])
for i in range(M):
B, C =... | from operator import itemgetter
N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]
q = sorted(A+BC, key=itemgetter(1), reverse=True)
ans = 0
i = 0
while N:
n = min(q[i][0], N)
ans += q[i][1] * 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)]
pool = []
for Ai in A:
pool.append(Ai)
for Bi, Ci in BC:
for _ in range(Bi):
pool.append(Ci)
pool.sort(key=lambda x: -x)
print((sum(pool[:N]))) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
table = {}
for Ai in A:
table[str(Ai)] = 0
for Bi, Ci in BC:
table[str(Ci)] = 0
for Ai in A:
table[str(Ai)] += 1
for Bi, Ci in BC:
table[str(Ci)] += ... | p03038 |
from collections import defaultdict as dd
def main():
a = dd(int)
n, m = [int(i) for i in input().split()]
for i in input().split():
a[int(i)] += 1
for _ in range(m):
b, c = [int(i) for i in input().split()]
for _ in range(b):
a[c]+=1
res = 0
cn... | def main():
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append((b, c))
total = 0
for num, v in sorted(bc, key=lambda x: -x[1]):
total += num
a... | p03038 |
n,m,*t=list(map(int,open(0).read().split()))
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
while a and b and c>a[-1]:m+=c;b-=1;a.pop()
print((m+sum(a))) | n,m,*t=list(map(int,open(0).read().split()))
a=sorted(t[:n])[::-1]
m=0
for c,b in sorted(zip(t[n+1::2],t[n::2]))[::-1]:
while a and c>a[-1]and b:m+=c;b-=1;a.pop()
print((m+sum(a))) | p03038 |
n,m,*t=list(map(int,open(0).read().split()))
s=sorted
a=s(t[:n])[::-1]
i=n
for c,b in s(list(zip(t[n+1::2],t[n::2])))[::-1]:
while c>a[i-1]and i*b:a[i-1]=c;b-=1;i-=1
print((sum(a))) | n,m,*t=list(map(int,open(0).read().split()))
s=sorted
a=s(t[:n])[::-1]
i=n
for c,b in s(list(zip(t[n+1::2],t[n::2])))[::-1]:
while(c>a[i-1])*i*b:a[i-1]=c;b-=1;i-=1
print((sum(a))) | p03038 |
n,m,*t=list(map(int,open(0).read().split()))
s=sorted
a=s(t[:n])[::-1]
i=n
for c,b in s(list(zip(t[n+1::2],t[n::2])))[::-1]:
while(c>a[i-1])*i*b:i-=1;a[i]=c;b-=1
print((sum(a))) | n,m,*t=list(map(int,open(0).read().split()))
s=sorted
a=s(t[:n])[::-1]
for c,b in s(list(zip(t[n+1::2],t[n::2])))[::-1]:
while(c>a[n-1])*n*b:n-=1;a[n]=c;b-=1
print((sum(a))) | p03038 |
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [-1 * x for x in a]
heapq.heapify(a)
for _ in range(m):
b, c = list(map(int, input().split()))
for i in range(b):
heapq.heappush(a, -1 * c)
ans = 0
for i in range(n):
ans += -1 * heapq.heappop(a)... | import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
lst = []
for _ in range(m):
b, c = list(map(int, input().split()))
lst.append((b, c))
lst = sorted(lst, key = lambda x: -x[1])
flag = False
for b, c in lst:
for _ in range(b):
min_n... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)
d = []
while l and len(d) <= n:
bc = l.pop(0)
d.extend([bc[1]]*bc[0])
ret = 0
for i in range(n):
if d an... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)
res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
if pos_2 == m or a[pos_1] > l[pos_2][1]:
res += a[pos_1]... | p03038 |
n,m = list(map(int, input().split()))
a = list(map(int,input().split()))
bclist = [list(map(int,input().split())) for _ in range(m)]
all = a
for bc in bclist:
for i in range(bc[0]):
all.append(bc[1])
all.sort()
print((sum(all[(len(all)-n):]))) | n,m = list(map(int, input().split()))
a = list(map(int,input().split()))
bclist = [list(map(int,input().split())) for _ in range(m)]
bclist=sorted(bclist, key = lambda x:x[1], reverse=True)
all = []
for i in range(m):
all.extend([bclist[i][1]]*bclist[i][0])
if len(all) >n:
break
all.e... | p03038 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M = list(map(int,readline().split()))
A=[int(x) for x in readline().split()]
BC=[]
for i in range(M):
BC +=[list(map(int,readline().split()))]
BC = sorted(BC, key=lambda x: x[1],reverse = T... | N,M=list(map(int,input().split()))
A=[int(x) for x in input().split()]
CB=[]
for i in range(M):
B,C = list(map(int,input().split()))
CB +=[[C,B]]
for j in range(N):
CB +=[[A[j],1]]
CB=sorted(CB,reverse = True)
count = 0
result =0
i=0
while count<N:
count +=CB[i][1]
result +=CB[i][0]*CB[i][... | p03038 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): ret... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A_dict = {}
#Aをhash
for i in A:
if i in A_dict:
A_dict[i] += 1
else:
A_dict[i] = 1
for i in range(M):
b, c = list(map(int, input().split()))
for j in range(b):
#最小値がc以上なら何もしない
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A_dict = {}
#Aをhash
for i in A:
if i in A_dict:
A_dict[i] += 1
else:
A_dict[i] = 1
for i in range(M):
b, c = list(map(int, input().split()))
if c in A_dict:
A_dict[c] += b
else:
... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append([b, c])
sorted_a = sorted(a)
sorted_bc = sorted(bc, key=lambda x: x[1])
que = []
for b, c in sorted_bc:
que += [c]*b
c = que.pop() ... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append([b, c])
a = sorted(a)
bc = sorted(bc, key=lambda x: x[1])
que = []
for b, c in bc:
que += [c]*b
c = que.pop()
ans = 0
i = 0
while T... | p03038 |
#AのリストにCのリストを加えて大きい順に並べ替えてNまでの和を求める
N,M = list(map(int,input().split()))
#Aの入力
A_list = list(map(int,input().split()))
#Aの末尾にCのリストを追加する
for i in range(M):
bi,ci = list(map(int,input().split()))
for j in range(bi):
A_list.append(ci)
#A_Listを大きい順に並べ替える
A_list=sorted(A_list,reverse=True... |
#AのリストにCのリストを加えて大きい順に並べ替えてNまでの和を求める
N,M = list(map(int,input().split()))
#Aの入力
A_list = list(map(int,input().split()))
C_list = []
#Cのリストに追加する
for i in range(M):
bi,ci = list(map(int,input().split()))
C_list.append([bi,ci])
#C_listをCの値でソート
C_list=sorted(C_list, reverse=True, key=lambda x:x[1... | p03038 |
#AのリストにCのリストを加えて大きい順に並べ替えてNまでの和を求める
N,M = list(map(int,input().split()))
#Aの入力
A_list = list(map(int,input().split()))
C_list = []
#Cのリストに追加する
for i in range(M):
bi,ci = list(map(int,input().split()))
C_list.append([bi,ci])
#C_listをCの値でソート
C_list=sorted(C_list, reverse=True, key=lambda x:x[1... |
#AのリストにCのリストを加えて大きい順に並べ替えてNまでの和を求める
N,M = list(map(int,input().split()))
#Aの入力
A_list = list(map(int,input().split()))
C_list = []
#Cのリストに追加する
for i in range(M):
bi,ci = list(map(int,input().split()))
C_list.append([bi,ci])
#C_listをCの値でソート
C_list=sorted(C_list, reverse=True, key=lambda x:x[1... | p03038 |
def slove():
import sys, heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
a = list(map(int, input().rstrip('\n').split()))
bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
heapq.heapify(a)
for b, c in bc:
for i in range... | def slove():
import sys, heapq
input = sys.stdin.readline
n, m = list(map(int, input().rstrip('\n').split()))
a = list(map(int, input().rstrip('\n').split()))
bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
heapq.heapify(a)
bc = sorted(bc, key=lambda x: x[1], rev... | p03038 |
import bisect
from operator import itemgetter
n, m = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = sorted([ list(map(int, input().split())) for _ in range(m) ], key=itemgetter(1))
for i in range(m):
b, c = BC[i]
t = bisect.bisect_left(A, c)
if t > b:
A = A[b:t] + [c... | from operator import itemgetter
n, m = list(map(int, input().split()))
A = [(1, i) for i in map(int, input().split())]
BC = [ tuple(map(int, input().split())) for _ in range(m) ]
XY = sorted(A + BC, reverse=True, key=itemgetter(1))
c = n
now = 0
ans = 0
while c > 0 and now < n+m:
x, y = XY[now]
t = min(c,... | p03038 |
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
for m in range(M):
B,C = list(map(int,input().split()))
if A[0]<C:
A+=B*[C]
A = sorted(A)[::-1]
print((sum(A[:N]))) | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for m in range(M)]
BC = sorted(BC,key=lambda x:x[1])[::-1]
for b,c in BC:
A.extend(b*[c])
if 2*N<len(A):
break
A = sorted(A)[::-1]
print((sum(A[:N]))) | p03038 |
n,m = list(map(int, input().split()))
List = list(map(int, input().split()))
List.sort()
cand = []
for _ in range(m):
b,c = list(map(int,input().split()))
for i in range(b):
cand.append(c)
cand.sort()
cand = cand[::-1]
chan = []
for i in range(min(len(List),len(cand))):
if cand[i] >=List[i]:
... | n,m = list(map(int, input().split()))
List = list(map(int, input().split()))
List.sort()
cand = []
for _ in range(m):
b,c = list(map(int,input().split()))
cand.append((b,c))
bc = sorted(cand, key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
while b:
if i < n and List[i] < c:
... | p03038 |
import collections
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
ac = collections.Counter(a)
for i in range(m):
b, c = list(map(int, input().split()))
x = sorted(ac.items())
j = 0
while b:
y = x[j]
if y[0] < c:
if y[1] < b:
... | from operator import itemgetter
import bisect
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1), reverse=True)
bi = [bisect.bisect_left(a, bc[i][1]) for i in range(m)]
ans = 0
did = 0
for i in r... | p03038 |
N,M = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
B = [0]*M
for j in range(M):
B[j] = list(map(int,input().split(" ")))
tmp = sorted(B,key=lambda x:x[1],reverse=True)
A.sort()
r = 0
for i in tmp:
for k in range(r,N,1):
if i[1] > A[k] and i[0] > 0:
A[k] = i[1]
i[0] -... | N,M = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
B = [0]*M
for j in range(M):
B[j] = list(map(int,input().split(" ")))
tmp = sorted(B,key=lambda x:x[1],reverse=True)
A.sort()
r = 0
for i in tmp:
for k in range(r,N,1):
if i[1] > A[k] and i[0] > 0:
A[k] = i[1]
i[0] -... | p03038 |
N,M = list(map(int,input().split()))
X = {}
for i in map(int,input().split()):
if i in list(X.keys()):
X[i] += 1
else:
X[i] = 1
for _ in range(M):
b,c = list(map(int,input().split()))
if c in list(X.keys()):
X[c] += b
else:
X[c] = b
K = sorted(list(X.ke... | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(M)]
A.sort()
X.sort(key=lambda x:-x[1])
j = 0
for i in range(N):
if X[j][1] < A[i]:
break
else:
X[j][0] -= 1
A[i] = X[j][1]
if X[j][0] == 0:
... | p03038 |
import bisect
N, M = list(map(int, input().split()))
cards = list(map(int, input().split()))
cards.sort()
ops = []
for i in range(M):
B, C = list(map(int, input().split()))
ops.append({"B": B, "C": C})
ops.sort(key=lambda o: o["C"], reverse=True)
#print(cards)
#print(ops)
left = 0
for op in op... | import bisect
N, M = list(map(int, input().split()))
cards = list(map(int, input().split()))
cards.sort()
ops = []
for i in range(M):
B, C = list(map(int, input().split()))
ops.append({"B": B, "C": C})
ops.sort(key=lambda o: o["C"], reverse=True)
#print(cards)
#print(ops)
left = 0
for op in op... | 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 i,j in BC:
for k in range(i):
if A[k] < j:
A[k] = j
else:
break
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)]
A.sort()
S_BC = sorted(BC,key=lambda x:x[1],reverse=True)
index = 0
flag = 0
for Bj,Cj in S_BC:
for k in range(Bj):
if len(A) >= index+1:
if A[index] < Cj... | p03038 |
#coding:utf-8
import sys
N,M=list(map(int,input().split()))
A=[-1]*(3*(10**5))
p=0
A=list(map(int,input().split()))
Q=[]
for i in range(M):
b,c=list(map(int,sys.stdin.readline().split()))
Q.append((c,b))
Q.sort();Q.reverse();
A.sort()
A.reverse()
for c,b in Q:
if A[-1] < c:
... | #coding:utf-8
import sys
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
b,c=list(map(int,sys.stdin.readline().split()))
Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
if b+n<=N:
s+=c*b
n+=... | p03038 |
import sys
import bisect
def main():
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = []
for _ in range(m):
bc.append(list(map(int,input().split())))
a.sort()
a = tuple(a)
bc.sort(key=lambda x: x[1], reverse=True)
num = 0
an... | import sys
def main():
input = sys.stdin.readline
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = []
for _ in range(m):
bc.append(list(map(int,input().split())))
a.sort()
a = tuple(a)
bc.sort(key=lambda x: x[1], reverse=True)
... | p03038 |
#python3
from heapq import heappop, heappush
def main():
n, m = list(map(int, input().split()))
hq = []
for i in input().split():
heappush(hq, (-int(i), 1))
for _ in range(m):
b, c = list(map(int, input().split()))
heappush(hq, (-c, b))
ans = 0
for i in rang... | #python3
def main():
n, m = list(map(int, input().split()))
cards = [(int(i), 1) for i in input().split()]
for _ in range(m):
b, c = list(map(int, input().split()))
cards.append((c, b))
cards.sort(reverse=True)
ans = 0
sumv = 0
for i in range(n):
v = cards[... | p03038 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush, heapify
def main():
N, M = list(map(int, readline().split()))
A = [int(i) for i in readline().split()]
heapify(A)
for _ in range(M):
... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush, heapify
def main():
N, M = list(map(int , readline().split()))
hp = [(-int(i), 1) for i in readline().split()]
heapify(hp)
for _ in range(M):... | p03038 |
n, m = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()], reverse=True)
cs = []
for _ in range(m):
b, c = list(map(int, input().split()))
cs += [c] * b
cs = sorted(cs, reverse=True)
ind_a, ind_c = 0, 0
ans = 0
for i in range(n):
if len(cs)-1 >= ind_c:
... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc.append((b, c))
bc = sorted(bc, key=lambda x: x[1], reverse=True)
cnt = 0
for b, c in bc:
cnt += b
a += [c] * b
if cnt >= n:
br... | 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)
for chenge in BC:
kaisuu = chenge[0]; value = chenge[1]
cnt = 0
for i in range(len(A)):
if A[i] < value:
... | 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)
i = 0
for bc in BC:
for _ in range(bc[0]):
if i > len(A)-1:
break
if A[i] > bc[1]:
b... | p03038 |
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)]
for j in range(m):
new_a = sorted(a)
for b in range(bc[j][0]):
if new_a[b] < bc[j][1]:
new_a[b] = bc[j][1]
a = new_a
print((sum(a))) | 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)]
bc = sorted(bc, key=lambda x: (x[1]), reverse=True)
count = 0
for b, c in bc:
count += b
a.extend([c]*b)
if count >= n:
break
print((sum(sorted(a,reve... | p03038 |
N,M=list(map(int, input().split()))
A=list(map(int, input().split()))
A=sorted(A)
L=[[0,0] for _ in range(M)]
for i in range(M):
b,c=list(map(int, input().split()))
L[i][0]=b
L[i][1]=c
L=sorted(L,reverse=True, key=lambda x: x[1])
X=[]
for l in L:
b=l[0]
c=l[1]
n=min(b,N-len(X))
... | 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 a in A:
L.append((1,a))
L=sorted(L, reverse=True, key=lambda x: x[1])
ans=0
count=N
for l in L:
n,v=l
ans+=v*min(count, n)
count-=... | p03038 |
import heapq
N,M=list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
l = []
for i in range(M):
tmp = list(map(int,input().split()))
l.append([tmp[1],tmp[0]])
l.sort(reverse=True)
for i,j in l:
for I in range(j):
Q = heapq.heappop(A)
if Q<i :
heapq.hea... | N,M=list(map(int,input().split()))
A = list(map(int,input().split()))
l = []
for i in range(M):
tmp = list(map(int,input().split()))
l.append([tmp[1],tmp[0]])
l.sort(reverse=True)
for i,j in l:
A.extend([i]*j)
if len(A)>2*N:break
A.sort(reverse=True)
print((sum(A[:N]))) | p03038 |
N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
b, c = list(map(int, input().split()))
for _ in range(b):
L.append(c)
L.sort(reverse=True)
idx = 0
for i in range(N):
if (idx > len(L) - 1):
break
if (A[i] < L[idx]):
... | N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
b, c = list(map(int, input().split()))
L.append([b, c])
L.sort(key=lambda x: x[1], reverse=True)
# 変更前のカードの枚数
# 変更後のカードの枚数
# をそれぞれ保存しておく
idx = 0
for i in range(N):
if (idx > len(L) - 1):
... | p03038 |
from heapq import heapify, merge, nlargest
from operator import itemgetter
n, m = list(map(int, input().split()))
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
heapify(aa)
bcbc.sort(key=itemgetter(1), reverse=True)
for b, c in bcbc :
cc = [c]*min(b, n)
... | from operator import itemgetter
n, m = list(map(int, input().split()))
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
bcbc.extend([[1, a] for a in aa])
bcbc.sort(key=itemgetter(1), reverse=True)
count = 0
s = 0
for b, c in bcbc :
if count + b >= n :
... | p03038 |
import bisect
# N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
# [3, 10],
# [4, 30],
# [1, 4]
# ]
N,M = list(map(int,input().split()))
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
BRR.append(list(map(int,input().split())))
def calculate(n, m, arr, b... | # N, M = 10, 3
# ARR = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
# BRR = [
# [3, 10],
# [4, 30],
# [1, 4]
# ]
N,M = list(map(int,input().split()))
ARR = list(map(int,input().split()))
BRR = []
for i in range(M):
BRR.append(list(map(int,input().split())))
def calculate(n, m, arr, brr):
r... | p03038 |
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
for m in range(M):
B, C = list(map(int, input().split()))
count = 0
for i in range(B):
if As[i] < C:
count += 1
else:
break
As[0:count] = []
#print(As)
index = N-count
for i in range(N-c... | N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
BCs = []
for m in range(M):
B, C = list(map(int, input().split()))
BCs.append((B, C))
BCs.sort(key=lambda BC: -BC[1])
#print(BCs)
index = 0
for m in range(M):
B, C = BCs[m]
for i in range(B):
if index >= N:
... | p03038 |
n,m = list(map(int,input().split()))
A = sorted(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)
Cs = sorted(C)
CS = Cs[::-1]
ans = 0
if len(CS)<n:
CS = CS +[0]*(n-m+1)
for i in range(n):
ans += max(A[i],CS[i])... | n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
l=sorted([list(map(int,input().split())) for i in range(m)],reverse=True,key=lambda x: x[1])
c_l=[]
for b,c in l:
c_l+=[c]*b
if len(c_l)>=n:
break
for i in range(min(n,len(c_l))):
a[i]=max(a[i],c_l[i])
print((sum(a)... | 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):
a = heapq.heappop(A)
if a < c:
heapq.heappush(A, c)
else:
... | 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, key = lambda x : x[1], reverse=True)
for b, c in BC:
for i in range(b):
a = heapq.heappop(A)
if a < c:
... | 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)]
b, c = [list(i) for i in zip(*bc)]
sum_b = sum(b)
for i in range(m):
add = [c[i] for _ in range(b[i])]
a.extend(add)
a.sort()
a = a[sum_b:]
print((sum(a))) | n, m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc = sorted(bc, key = lambda x : x[1], reverse=True)
sum_b = 0
for b, c in bc:
sum_b += b
a += [c] * b
if n < sum_b:
break
a.sort(reverse=True)
a = a[:n]
p... | p03038 |
from sys import stdin
from collections import deque
N, M = list(map(int, stdin.readline().rstrip().split()))
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
A = deque(A)
Y = []
for _ in range(M):
b, c = [int(x) for x in stdin.readline().rstrip().split()]
Y.extend([c] * b)
Y.sort()
Y ... | from sys import stdin
from collections import deque
from operator import itemgetter
N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort()
A = deque(A)
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
X.sort(key=it... | p03038 |
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
op = [list(map(int, input().split())) for _ in range(M)]
cards = sorted(A)
op.sort(key=lambda x: -x[1])
i = 0
for m in range(M):
b, c = op[m]
for _ in range(b):
if cards[... | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
op = [list(map(int, input().split())) for _ in range(M)]
cards = sorted(A)
op.sort(key=lambda x: -x[1])
i = 0
for m in range(M):
b, c = op[m]
for _ in range(b):
if cards[... | p03038 |
import heapq
n, m = list(map(int, input().split()))
a = [ -int(x) for x in input().split() ]
bc = []
heapq.heapify(a)
for _ in range(m):
b, c = list(map(int, input().split()))
bc += [ (b, c) ]
bc.sort(key=lambda x: -x[1])
min_a = min(a)
for b, c in bc:
if c < min_a:
min_a = c
... | n, m = list(map(int, input().split()))
a = sorted([ int(x) for x in input().split() ], reverse=True)
bc = []
for _ in range(m):
b, c = list(map(int, input().split()))
bc += [ (b, c) ]
bc.sort(key=lambda x: -x[1])
i, j, cnt, ans = 0, 0, 0, 0
while cnt < n:
if j < m and a[i] < bc[j][1]:
... | 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)]
for b,c in bc:
a.extend([c]*b)
a.sort(reverse=True)
print((sum(a[:n]))) | N, M = list(map(int, input().split()))
A = [[1, int(i)] for i in input().split()]
for i in range(M):
b, c = list(map(int, input().split()))
A.append([b, c])
total = 0
D = []
A = sorted(A, key=lambda x:x[1], reverse=True)
for b, c in A:
if len(D) >= N:
break
D.extend([c]*b)
print((s... | 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:
cnt = 0
for _ in range(b):
p = heapq.heappop(A)
if p > c:
heapq.heappush(A, p)
... | N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = [list(map(int, input().split())) for _ in range(M)]
# n番目の要素でソートsort
BC = sorted(BC, reverse=True, key=lambda x: x[1])
m = A[0]
D = []
for b, c in BC:
if c > m:
_ = [D.append(c) for i in range(b)]
else:... | 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()
bc.sort(key=lambda x:x[1],reverse=True)
d = []
for i in bc:
for j in range(i[0]):
d.append(i[1])
#print(d)
if len(d) < n:
for i in range(n-len(d)):
... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
for i in a:
bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
d = min(i[0],n)
# print(d)
ans += i[1] * d
n -= d
print(a... | p03038 |
import os, sys, re, math
N, M = [int(s) for s in input().split(' ')]
cards = [int(s) for s in input().split(' ')]
cards.sort()
bc_ary = []
for i in range(M):
bc_ary.append([int(s) for s in input().split(' ')])
for bc in bc_ary:
cnt = 0
idx = 0
while idx < N and cnt < bc[0]:
mi... | import os, sys, re, math, heapq
N, M = [int(s) for s in input().split(' ')]
dic = {}
cards = [int(s) for s in input().split(' ')]
for c in cards:
if c in dic:
dic[c] += 1
else:
dic[c] = 1
for i in range(M):
b,c = [int(s) for s in input().split(' ')]
if c in dic:
... | p03038 |
from heapq import heappop, heappush
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]
h = []
for x in a:
heappush(h, x)
for b, c in bc:
for _ in range(b):
temp = heappop(h)
if temp >= c:
... | from heapq import heappop, heappush
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]
bc.sort(reverse=True)
h = []
for x in a:
heappush(h, x)
for b, c in bc:
for _ in range(b):
temp = heappop(h)
... | p03038 |
#TLE
N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
for i in range(M):
b, c = list(map(int, input().split()))
a_list += [c] * b
a_list.sort(reverse = True)
print((sum(a_list[:N])))
| #TLE
N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
written_nums = []
for i in range(M):
b, c = list(map(int, input().split()))
written_nums.append((c, b))
written_nums.sort(reverse = True)
append_list = []
for c, b in written_nums:
append_list += [c for _ in r... | p03038 |
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
list2=[]
for _ in range(M):
B,C=list(map(int,input().split()))
if C>min(list1):
list2+=[C]*B
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM) | N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
list2=[1]
for _ in range(M):
B,C=list(map(int,input().split()))
if C>min(list2) and len(list2)>N:
list2+=[C]*B
else:
list2+=[C]*B
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM) | p03038 |
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
list2=[]
for _ in range(M):
B,C=list(map(int,input().split()))
list2+=[C]*B
list2.sort(reverse=True)
list2=list2[:N]
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM) | N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
list2=[]
for _ in range(M):
B,C=list(map(int,input().split()))
list2+=[C]*B
list2.sort(reverse=True)
list2=list2[:N]
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM) | p03038 |
import sys
input = sys.stdin.readline
import heapq
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
for _ in range(M):
B,C=list(map(int,input().split()))
list1+=[C]*B
list1=heapq.nlargest(N,list1)
SUM=sum(list1)
print(SUM) | import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
for _ in range(M):
B,C=list(map(int,input().split()))
if len(list1)<N or min(list1)<C:
list1+=[C]*B
if len(list1)>N:
for i in range(len(list1)-N):
list1.remove(min(list1))
S... | p03038 |
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
for _ in range(M):
B,C=list(map(int,input().split()))
list1+=[C]*B
while len(list1)>=N+1:
list1.remove(min(list1))
SUM=sum(list1)
print(SUM) | import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
for _ in range(M):
B,C=list(map(int,input().split()))
list1+=[C]*B
for _ in range(B):
list1.remove(min(list1))
SUM=sum(list1)
print(SUM) | p03038 |
import sys
input = sys.stdin.readline
N,M=list(map(int,input().split()))
list1=list(map(int,input().split()))
list2=list(set(list1))
listBC=[[list2[i],list1.count(list2[i])] for i in range(len(list2))]
listC=[list2[i] for i in range(len(list2))]
for _ in range(M):
B,C=list(map(int,input().split()))
listBC+... | N,M = list(map(int, input().split()))
listA = list(map(int, input().split()))
listA.sort()
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
for i in range(M):
B, C = listBC[i][0], listBC[i][1]
listA += [C]*B
countB += ... | p03038 |
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return ... | import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return ... | 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)
l = []
[l.extend([i[1]] * i[0]) for i in bc]
for i in range(min(len(a),len(l))):
a[i]=max(a[i],l[i])
print((sum(a))) | 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)
l = []
for i in bc:
l.extend([i[1]] * i[0])
if len(l) > len(a):
break
for i in range(min(len(a),len(l))):
a[... | p03038 |
#-------------------------------------------------------------------
import sys
def p(*a):
s=" ".join(map(str,a))
#print(s)
sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
N, M = list(map(int, input().split())) # "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
A ... | #-------------------------------------------------------------------
import sys
def p(*a):
s=" ".join(map(str,a))
#print(s)
sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
N, M = list(map(int, input().split())) # "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
A ... | p03038 |
import bisect
n,m = list(map(int, input().split()))
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x:(-x[1]))
for b,c in bc:
index = bisect.bisect_left(a, c)
d = min(index,b)
for j in range(d):
a[j] = c
a.sort()
... | n,m = list(map(int, input().split()))
a = sorted(list(map(int,input().split())))
d = [list(map(int, input().split())) for _ in range(m)]
d.sort(key=lambda x:(-x[1]))
e = []
for b,c in d:
e += [c]*b
if len(e) >= n:
break
e = sorted(e)[::-1]
ans = 0
j = 0
for i in range(n):
if j < len(e):... | p03038 |
n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
for i in range(m):
b,c = list(map(int,input().split()))
a.extend([c]*b)
a.sort()
print((sum(a[len(a)-n:]))) | n,m = list(map(int,input().split()))
a = [[1,int(i)] for i in input().split()]
bc = [[int(i) for i in input().split()] for j in range(m)]
x = a+bc
x.sort(key=lambda y:y[1])
total = 0
ans = 0
for i in reversed(list(range(n+m))):
if total >= n:
break
else:
ans += x[i][1]*min(n-total,x[i... | p03038 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,m = na()
a = na()
for i in range(m):
b,c = na()
a += [c]*b
aa = list(rev... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,m = na()
a = na()
for i in range(m):
b,c = na()
for j in range(b):
... | p03038 |
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,m = na()
a = sorted(na())
k = 0
import heapq
for i in range(m):
b,c = na()
k += b
for j in range... | import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
n,m = na()
a = na()
bc = [na() for i in range(m)]
bc.sort(key=lambda x:x[1])
for b,c in bc[::-1]:
a.extend([c]... | p03038 |
from bisect import bisect_left
def main():
n, m = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
s = 0
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
for b, c in bc:
idx = bisect_le... | def main():
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
arr = []
sum_b = 0
for b, c in bc:
arr += [c] * b
sum_b += b
... | p03038 |
import sys
from heapq import heapify, heappushpop
from operator import itemgetter
if sys.platform =='ios':
sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]
def main():
N, M = MAP()
A = MAP()
BC = [MAP() ... | import sys
from heapq import heapify, heappop
from operator import itemgetter
if sys.platform =='ios':
sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]
def main():
N, M = MAP()
A = MAP()
BC = [MAP() for ... | p03038 |
import bisect
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
for i in range(M):
B,C = list(map(int, input().split()))
insert_index = bisect.bisect_left(A,C)
if insert_index == 0 and C > A[0]:
A[0] = C
continue
elif insert_index == 0:
... | N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
BC = []
for i in range(M):
BC.append(list(map(int, input().split())))
BC.sort(key=lambda x: x[1],reverse=True)
bc = 0
a = 0
ans = 0
for i in range(N):
if (bc < M) and (BC[bc][1] >= A[a]):
a... | p03038 |
from bisect import bisect_left
N, M = list(map(int, input().split()))
d = dict()
A = list(map(int, input().split()))
for i in range(N):
d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
B, C = list(map(int, input().split()))
d[C] = d.get(C, 0) + B
ans = 0
keys = sorted(list(d.keys()), reverse = True)
fo... | N, M = list(map(int, input().split()))
d = dict()
A = list(map(int, input().split()))
for i in range(N):
d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
B, C = list(map(int, input().split()))
d[C] = d.get(C, 0) + B
ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
kosuu = min(N, d.ge... | p03038 |
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
for i in range(M):
Bi, Ci = list(map(int, input().split()))
A.extend([Ci] * Bi)
print((sum(sorted(A, reverse=True)[:N]))) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(M):
Bi, Ci = list(map(int, input().split()))
A.extend([Ci] * Bi)
print((sum(sorted(A, reverse=True)[:N]))) | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(M):
Bi, Ci = list(map(int, input().split()))
A.extend([Ci] * Bi)
print((sum(sorted(A, reverse=True)[:N]))) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
card = {}
for a in A:
if a not in card:
card[a] = 1
else:
card[a] += 1
for i in range(M):
Bi, Ci = list(map(int, input().split()))
if Ci not in card:
card[Ci] = Bi
else:
card[Ci]... | p03038 |
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math
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... |
import sys
def input():
return sys.stdin.readline().strip()
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()
sumb = 0
change = []
while sumb <= N and len(CB) > 0:
... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = list([int(x) for x in input().split()])
heapq.heapify(A)
for i in range(M):
B, C = list(map(int, input().split()))
for i in range(B):
tmp = heapq.heappop(A)
if tmp < C:
heapq.heappush(A, C)
else:
... | N, M = list(map(int, input().split()))
A = list([int(x) for x in input().split()])
Q = []
for i in range(M):
Q.append(tuple(map(int, input().split())))
A.sort()
Q.sort(key=lambda x: x[1], reverse=True)
cur = 0
for i in range(M):
cnt = Q[i][0]
while cnt > 0 and cur < N:
if A[cur] >... | p03038 |
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]
numArray = [[0]*2]*num2
for index3 in range(num2):
numArray[index3] = [int(j) for j in input().split()]
for index1 in range(num2):
num4 = 0
num3.sort()
#numArray[index1].sort()
for index2 in rang... | num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]
numArray = [[0]*2]*num2
for index3 in range(num2):
numArray[index3] = [int(j) for j in input().split()]
numArray.sort(key=lambda x:(-x[1]))
fg1 = True
for index1 in range(num2):
for index2 in range(numArray... | 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()))
i=0
while i<b:
a=heapq.heappop(A)
if a>=c:
heapq.heappush(A,a)
break
heapq.heappush(... | N,M=list(map(int,input().split()))
A=sorted(list(map(int,input().split())))
bc=[list(map(int,input().split())) for _ in range(M)]
bc.sort(key=lambda x: x[1],reverse=True)
D=[0]*N
i=0
for b,c in bc:
cnt=0
while i<N and cnt<b:
D[i]=c
i+=1
cnt+=1
if i==N:
break
... | 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)]
minA = min(A)
C = [[j]*i for i,j in BC if j > minA]
for i in range(len(C)):
A = A[:N]
if C[i][0] > min(A):
A.extend(C[i])
A.sort(reverse=True)
print((su... | 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)
idx = 0
for b, c in BC:
for j in range(idx, min(N, idx + b)):
if A[j] < c:
A[j] = c
idx += b
print((sum(A)))
| p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
bc = list(map(int, input().split()))
BC.append(bc)
BC = sorted(BC, key=lambda x:x[1], reverse=True)
for b, c in BC:
A = sorted(A)
if A[0] >= c:
break
for i in range(b):
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
bc = list(map(int, input().split()))
BC.append(bc)
BC = sorted(BC, key=lambda x:x[1], reverse=True)
cnt = 0
for b, c in BC:
A += [c] * b
cnt += b
if cnt >= N:
break
A.sort(rever... | p03038 |
n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
num = 0
ans_lis=[]
for x,y in zip(alis,clis):
if x>=y:
ans_lis.append(x)
... | n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
ans__ ... | p03038 |
n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
ans__ ... | n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis = [x for y in clis for x in y]
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(al... | p03038 |
n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis = [x for y in clis for x in y]
l = len(clis)
clis.sort(reverse=True)
alis.sort()
ans = 0
for x,y in zip(alis,clis):
ans += max(x,y)
if... | n,m = list(map(int,input().split()))
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
for x in alis:
lis.append([1,x])
lis.sort(reverse=True,key=lambda x:x[1])
ans = 0
for x in lis:
(number,point) = x
if number >= n:
number = n
ans += ... | p03038 |
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
bc=[]
for i in range(m):
b,c=list(map(int,input().split()))
bc+=[c]*b
num=min(len(bc),n)
bc=sorted(bc,reverse=True)[:num]
ans=sum(a)
temp=sum(a)
for i in range(n):
if num<=i:conti... | import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
bc=[list(map(int,input().split())) for i in range(m)]
bc=sorted(bc,reverse=True,key=lambda x:x[1])
c=[]
cnt=0
for B,C in bc:
for i in range(B):
if cnt==n:break
cnt+=1
... | p03038 |
def main():
N,M = list(map(int,input().split()))
A = [i for i in map(int,input().split())]
targetList = []
for i in range(M):
B,C = list(map(int,input().split()))
tmpList = [C for _ in range(B) ]
targetList += tmpList
targetList.sort(reverse=True)
new... |
def main():
N,M = list(map(int,input().split()))
A = [i for i in map(int,input().split())]
A.sort()
tmpC = 0
targetList = []
for i in range(M):
element = list(map(int,input().split()))
targetList.append(element)
targetList.sort(key=lambda x:x[1],reverse=Tru... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
b, c = list(map(int, input().split()))
A.extend([c] * b)
A = sorted(A, reverse=True)
print((sum(A[:N]))) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
BC.append(list(map(int, input().split())))
BC = sorted(BC, key=lambda x:x[1],reverse=True)
for b, c in BC:
A.extend([c] * b)
if len(A)>=2*N:
break
A = sorted(A, reverse=True)
print((sum(A[:N]))) | p03038 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
#変えられるカードを格納
change_card = []
for _ in range(M):
B,C = list(map(int,input().split()))
for _ in range(B):
change_card.append(C)
change_card.sort()
for i in range(N):
if max(change_card) > A[i]:
... | 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 = sorted(BC,key=lambda x: x[1])
BC_sort_index = M-1
for i in range(N):
if BC_sort[BC_sort_index][1] > A[i]:
A[i] = BC_sort[BC_sort_in... | p03038 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]
P = sorted(([[1,A[i]] for i in range(N)] + L),key=lambda x: x[1],reverse=True)
ans = 0
rest = N
for cost,value in P :
K = min(cost, rest)
K = max(0,K)
ans += K * valu... | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(M)]
for i in range(N) :
L.append([1,A[i]])
L = sorted(L, key=lambda x: x[1], reverse=True)
ans = 0
for i in range(len(L)) :
number, point = L[i]
if number > N... | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [[0]*2]*m
for i in range(m):
bc[i] = list(map(int,input().split()))
std = sorted(bc, key=lambda x: x[1], reverse=True)
for i in range(m):
if min(a) >= std[i][1]:
break
for j in range(std[i][0]):
a[a.index(min(a)... | #5618213
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
for b,c in bc:
a.extend([c]*b)
if len(a) > n*2:
break
a.sort(reverse=True)
print((sum(a[:n]))) | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
addable = []
for m in range(M):
B, C = list(map(int, input().split()))
addable += [C] * B
addable.sort()
addable = addable[-len(A):]
NA = A + addable
NA.sort()
print((sum(NA[-len(A):])))
| N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
p = [(A[i], 1) for i in range(N)]
for m in range(M):
B, C = list(map(int, input().split()))
p.append((C, B))
p.sort()
p.reverse()
ans = 0
for v, n in p:
use = min(N, n)
ans += use * v
N -= use
i... | p03038 |
N, M = list(map(int, input().split()))
A_array = list(map(int, input().split()))
BC_array = [list(map(int, input().split())) for _ in range(M)]
BC_array = sorted(BC_array, key=lambda x: -x[1])
B_count = 0
for B, C in BC_array:
A_array = A_array + [C] * B
B_count += B
if B_count >= N:
break
... | N, M = list(map(int, input().split()))
A_array = sorted(map(int, input().split()))
BC_array = [list(map(int, input().split())) for _ in range(M)]
BC_array = sorted(BC_array, key=lambda x: x[1])
plus_count = 0
ans = 0
a_index = N - 1
bc_index = M - 1
while plus_count != N:
if A_array[a_index] <= BC_arra... | p03038 |
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
res = []
for _ in range(M):
B, C = list(map(int,input().split()))
res += [C]*B
X = A+res
X.sort(reverse = True)
print((sum(X[: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])
for B, C in BC:
A.extend([C]*B)
if len(A) > N*2:
break
A.sort(reverse = True)
print((sum(A[:N]))) | p03038 |
from heapq import heapify, heappush, heappop
(N, M), *AB = [list(map(int, s.split())) for s in open(0)]
A = AB[0]
heapify(A)
for b, c in AB[1:]:
while b > 0 and c > A[0]:
a = heappop(A)
heappush(A, c)
b -= 1
print((sum(A))) | (N, M), *AB = [list(map(int, s.split())) for s in open(0)]
A = sorted(AB[0])
D = []
for b, c in sorted(AB[1:], key=lambda x: (-x[1], x[0])):
D.extend([c] * b)
if len(D) >= N:
D = D[:N]
break
D = D[::-1]
for i in range(N):
if not D or D[-1] <= A[i]:
break
A[i] = D.pop(... | p03038 |
import bisect
n, m = list(map(int, input().split()))
ls = sorted(map(int, input().split()))
ls2 = [list(map(int, input().split())) for _ in range(m)]
ls2.sort(key=lambda x: (x[1], x[0]), reverse=True)
left = 0
res = 0
for b, c in ls2:
if left == n or c <= ls[left]:
break
i = bisect.bisect(ls... | n, m = list(map(int, input().split()))
ls = sorted(map(int, input().split()))
ls2 = [list(map(int, input().split())) for _ in range(m)]
ls2.sort(key=lambda x: (x[1], x[0]), reverse=True)
left = 0
right = 0
index = 0
res = 0
while left < n:
if index == len(ls2):
break
b, c = ls2[index]
if... | 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 _ in range(B):
heapq.heappushpop(A, C)
print((sum(A)))
if __name__... | def main():
N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
updates = list()
for _ in range(M):
B, C = list(map(int, input().split(' ')))
updates.append((B, C))
updates.sort(key=lambda x: x[1], reverse=True)
for B, C in updates:
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)]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
d = []
i = 0
while len(d) <= n and i < len(bc):
d += ([bc[i][1]] * bc[i][0])
i += 1
if len(d) > n:
d = d[: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 = []
i = 0
while len(d) <= n and i < len(bc):
d += ([bc[i][1]] * bc[i][0])
i += 1
if len(d) > n:
d = d[:n]
a += d... | 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)
a.sort()
i = 0
for b, c in bc:
for _ in range(b):
if i < n and a[i] < c:
a[i] = c
i += 1
... | 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(reverse=True, key=lambda x: x[1])
li = []
l = 0
i = 0
while i < m and l < n:
b, c = bc[i]
li += [c] * b
i += 1
l += b
a += li
a.sort(reverse=True... | p03038 |
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
BC.append(inpl())
BC.sort(key=lambda x: -x[1])
t = 0
S = 0
for B,C in BC:
f = t
t = f + B
if t > N:
t = N
if f >= N:
break
if C >= A[t-1]:
S += (t-... | inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
BC.append(inpl())
BC.sort(key=lambda x: -x[1])
D = []
for B, C in BC:
if len(D) >= N:
break
d = [int(C)]*B
D += d
D.sort(reverse=True)
lenD = len(D)
if lenD > N:
l... | 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.extend([C]*B)
print((sum(sorted(A)[-N:]))) | 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.extend([C]*B)
A = sorted(A)[-N:]
print((sum(A))) | 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.extend([C]*B)
A = sorted(A)[-N:]
print((sum(A))) | N, M = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
BC_list = []
for _ in range(M):
B, C = list(map(int, input().split(' ')))
BC_list.append((B, C))
BC_list = sorted(BC_list, key= lambda x: x[1], reverse=True)
for b, c in BC_list:
A.extend([c]*b)
if len(A) > 2*N:
... | p03038 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.