input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
info=[]
for i in range(m):
b,c=list(map(int,input().split()))
info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
global b
for i in range(s):
b.app... | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
info=[]
for i in range(m):
b,c=list(map(int,input().split()))
info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
global b
for i in range(s):
b.app... | p03038 |
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()))
for i in range(b):
a_list.append(c)
a_list.sort()
print((sum(a_list[::-1][0:n]))) | n,m = list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = []
for i in range(m):
b_list.append(list(map(int,input().split())))
b_list.sort(key=lambda x: x[1],reverse=True)
cnt = 0
for i in range(m):
for j in range(b_list[i][0]):
if cnt > n:
br... | p03038 |
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(m):
a, b = list(map(int, input().split()))
for _ in range(a):
A.append(b)
A = sorted(A)
print((sum(A[-n:]))) | 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)
D = list(zip(C, B))
D = sorted(D)
C, B = list(zip(*D))
C = reversed(C)
B = reversed(B)
total = 0
for i, j in zip(C, B... | p03038 |
import bisect
n, m = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
ope = []
d = []
for i in range(m):
ope.append(list(map(int,input().split())))
ope = sorted(ope,key = lambda x:-x[1])
for b,c in ope:
if len(d) == n:
break
elif len(d) + b > n:
for i... | import bisect
n, m = list(map(int, input().split()))
arr = sorted(list(map(int, input().split())))
ope = []
d = []
for i in range(m):
ope.append(list(map(int,input().split())))
ope = sorted(ope,key = lambda x:-x[1])
i = 0
ok = True
for b,c in ope:
for rep in range(b):
if i >= n or arr[i] > c... | p03038 |
import sys
import bisect
N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
for _ in range(M):
b, c = list(map(int, sys.stdin.readline().split()))
x = bisect.bisect_left(A, c)
y = min(x, b)
A = [c] * y + A[y:]
if x != y:
A.sort()
print((sum(A))) | import sys
import bisect
N, M = list(map(int, input().split()))
A = sorted(map(int, input().split()))
CB = [None] * M
for i in range(M):
b, c = list(map(int, sys.stdin.readline().split()))
CB[i] = (c, b)
CB.sort(reverse=True)
i = 0
ans = 0
for c, b in CB:
x = bisect.bisect_left(A, c, i)
c... | p03038 |
import heapq
import sys
input = sys.stdin.readline
def readlines(n):
for _ in range(n):
b, c = list(map(int, input().split()))
yield b, c
def main():
_, M = list(map(int, input().split()))
A = list(map(int, input().split()))
total = sum(A)
heapq.heapify(A)
for b... | import heapq
import sys
input = sys.stdin.readline
from operator import itemgetter
def readlines(n):
for _ in range(n):
b, c = list(map(int, input().split()))
yield b, c
def main():
_, M = list(map(int, input().split()))
A = list(map(int, input().split()))
total = sum(A)
... | p03038 |
from collections import Counter
from heapq import heapify, heappop, heappush
class Data:
def __init__(self, value, count):
self.value = value
self.count = count
def __lt__(self, other):
return self.value > other.value
# 降順に取り出す
N, M = list(map(int, input().split())... | from heapq import heapify, heappush, heappop
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
hq = list([(-x, 1) for x in a])
heapify(hq)
for _ in range(M):
b, c = list(map(int, input().split()))
heappush(hq, (-c, b))
rest = N
ans = 0
while rest > 0 and hq:
mv, b... | p03038 |
from heapq import heapify, heappush, heappop
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
hq = list([(-x, 1) for x in a])
heapify(hq)
for _ in range(M):
b, c = list(map(int, input().split()))
heappush(hq, (-c, b))
rest = N
ans = 0
while rest > 0 and hq:
mv, b... | from heapq import heappop, heappush
n, m = list(map(int, input().split()))
a = tuple(map(int, input().split()))
hq = []
for aa in a:
heappush(hq, (-aa, 1))
for _ in range(m):
b, c = list(map(int, input().split()))
heappush(hq, (-c, b))
rest = n
ans = 0
while rest > 0:
num, cnt = heap... | p03038 |
def main():
from collections import Counter
from operator import itemgetter
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
ctr = Counter(a)
for _ in range(M):
b, c = list(map(int, input().split()))
... | def main():
from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
ctr = defaultdict(int)
for x in A:
ctr[x] += 1
for _ in range(M):
... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)
a.sort()
d = []
loop = 0
while True:
for b, c in bc:
d.extend([c] * b)
loop += 1
... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)
a.sort()
for b, c in bc:
if c > a[0]:
for i in range(b):
if c > a[0]:
... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)
a.sort()
for b, c in bc:
if c > a[0]:
for i in range(b):
if c > a[0]:
... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)
a.sort()
a_count = 0
for b, c in bc:
if c > a[a_count]:
for i in range(b):
if ... | p03038 |
from io import StringIO
from collections import *
from functools import *
import sys
def main(inputs):
# n = int(next(inputs))
# n, k = map(int, next(inputs).split())
# xs = list(map(int, next(inputs).split()))
n, m = list(map(int, next(inputs).split()))
an = list(map(int, next(inputs).... | from io import StringIO
from collections import *
from functools import *
import sys
def main(inputs):
# n = int(next(inputs))
# n, k = map(int, next(inputs).split())
# xs = list(map(int, next(inputs).split()))
n, m = list(map(int, next(inputs).split()))
an = list(map(int, next(inputs).... | p03038 |
from heapq import heapify,heappop,heappush
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
heapify(A)
for j in range(M):
B = []
for i in range(BC[j][0]):
b = heappop(A)
if b < BC[j][1]:
b ... | #要修正 方針は合っているようだが・・・
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])
pt,card,index = 0,BC[0][1],0
while True:
for i in range(BC[index][0]):
if pt < N:
... | p03038 |
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a=sorted(a)
k=[[int(i) for i in input().split()] for i in range(m)]
k=sorted(k,key=lambda x:-x[1])
now=0
flag=True
for x,y in k:
if flag:
for i in range(x):
if flag and i+now<n:
... | def main():
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a=sorted(a)
k=[[int(i) for i in input().split()] for i in range(m)]
k=sorted(k,key=lambda x:-x[1])
now=0
flag=True
for x,y in k:
if flag:
... | p03038 |
n,m = list(map(int,input().split()))
a = [i for i in map(int,input().split())]
bc = [[i for i in map(int,input().split())] for j in range(m)]
a.sort(reverse=True)
bc.sort(key=lambda x: x[1], reverse=True)
arr = []
j = 0
for i in range(n):
arr.append(bc[j][1])
bc[j][0]-=1
if bc[j][0]==0:
j += 1
... | n,m = list(map(int,input().split()))
a = [i for i in map(int,input().split())]
bc = [[i for i in map(int,input().split())] for j in range(m)]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(n):
if a[i] < bc[j][1]:
a[i]=bc[j][1]
bc[j][0]-=1
if bc[j][0]==0:
j += 1
... | p03038 |
N, M = list(map(int, input().split()))
A_list = list(map(int, input().split()))
A_list.sort()
BC_list = [list(map(int, input().split())) for _ in range(M)]
BC_list = [BC_list[i][1] for i in range(M) for _ in range(BC_list[i][0])]
A_list.extend(BC_list)
A_list.sort()
print((sum(A_list[-N:])))
| N, M = list(map(int, input().split()))
A_list = list(map(int, input().split()))
A_list.sort()
BC_list = [list(map(int, input().split())) for _ in range(M)]
BC_list = sorted(BC_list, key=lambda x: x[1])
ans = 0
count = 0
i = N-1
m = M-1
while count < N:
if A_list[i] < BC_list[m][1]:
for _ in r... | 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(reverse=True)
print((sum(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 += [C]*B
A.sort(reverse=True)
A = A[:N]
print((sum(A))) | p03038 |
import copy
n, m = [int(i) for i in input().split()]
ans = []
a = list(map(int, input().split()))
for i in range(len(a)):
ans.append([1, a[i]])
b = []
c = []
for i in range(m):
d, e = [int(i) for i in input().split()]
ans.append([d, e])
ans1 = sorted(ans, key=lambda x: x[1], reverse = True)
... | import copy
n, m = [int(i) for i in input().split()]
ans = []
a = list(map(int, input().split()))
for i in range(len(a)):
ans.append([1, a[i]])
for i in range(m):
d, e = [int(i) for i in input().split()]
ans.append([d, e])
ans1 = sorted(ans, key=lambda x: x[1], reverse = True)
cnt = 0
ans2 = ... | p03038 |
from operator import itemgetter
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=itemgetter(1))
for i in range(m):
k = 0
a.sort()
while k<bc[i][0] and a[k]<bc[i][1]:
a[k] = bc[i][1]
k +=... | 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)
k=0
for i in range(m):
j=0
while j<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
a[k+j] = cb[i][0]
... | p03038 |
n,m=list(map(int,input().split()))
a = list(map(int, input().split()))
d=[]
for i in range(m):
b,c = list(map(int, input().split()))
d.extend([c]*b)
d.sort(reverse=True)
if len(d)>n:d=d[:n]
a.extend(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)]
#print(bc)
bc=sorted(bc,key= lambda x:x[1],reverse=True)
#print(bc)
bc2=[]
for i in range(m):
bc2.extend([bc[i][1]]*bc[i][0])
if len(bc2)>n: break
#print(bc2)
a.extend(bc2)
... | p03038 |
#7 Integer Cards
n,m = list(map(int,input().split()))
a = list( map(int,input().split()))
bc=[[0]*2 for _ in range(m)]
for i in range(m):
bc[i] = list(map(int,input().split()))
a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
import bisect
ans=[]
for (bb,cc) in bc:
idx = bisect.bisect(a,cc)
... | n,m = list(map(int,input().split()))
a = list( map(int,input().split()))
bc=[[0]*2 for _ in range(m)]
for i in range(m):
bc[i] = list(map(int,input().split()))
a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
nokori=n
bc2=[]
for (bb,cc) in bc:
if bb<=nokori:
bc2.extend([cc]*bb)
n... | p03038 |
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
bc=[]
import heapq
heapq.heapify(a)
for _ in range(m):
b,c=list(map(int,input().split()))
for _ in range(b):
temp=heapq.heappop(a)
if temp<c:
heapq.heappush(a,c)
else:
heapq.hea... | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
#bc=[]
import heapq
heapq.heapify(a)
bc=[]
for _ in range(m):
b,c=list(map(int,input().split()))
bc.append((c,b))
bc.sort(reverse=True)
for item in bc:
b=item[1]
c=item[0]
for _ in range(b):
temp=h... | p03038 |
from bisect import bisect_left, bisect_right
def readinput():
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
c=[]
for _ in range(m):
bb,cc=list(map(int,input().split()))
b.append(bb)
c.append(cc)
return n,m,a,b,c
def main(n,m,a,b,c... | from bisect import bisect_left, bisect_right
def readinput():
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
c=[]
for _ in range(m):
bb,cc=list(map(int,input().split()))
b.append(bb)
c.append(cc)
return n,m,a,b,c
def main(n,m,a,b,c... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
cards = []
for _ in range(m):
b, c = list(map(int, input().split()))
cards.append([c, b])
cards.sort()
ans = 0
for i, num in enumerate(a):
if not cards:
break
c, b = cards.pop()
if c > num:
... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
x = []
for _ in range(m):
b, c = list(map(int, input().split()))
x.append([b, c])
x.sort(key=lambda p: p[1], reverse=True)
ret = 0
for b, c in x:
if not a:
break
if c > a[-1]:
... | p03038 |
from operator import itemgetter
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = []
for i in range(M):
tmp = list(map(int,input().split()))
BC.append(tmp)
A.sort(reverse=True)
BC.sort(key=itemgetter(1),reverse=True)
l = 0
r = N-1
flg = False
for k in range(M):
#... | from operator import itemgetter
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = []
for i in range(M):
tmp = list(map(int,input().split()))
BC.append(tmp)
A.sort(reverse=True)
BC.sort(key=itemgetter(1),reverse=True)
l = 0
r = N-1
flg = False
for k in range(M):
#... | p03038 |
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
B =[]
C =[]
l = [list(map(int,input().split())) for i in range(M)]
A.sort()
l = sorted(l,key = lambda x:x[1])
flag =False
for i in l[::-1]:
for j in A[:i[0]]:
k = i[1]
if j<k:
if len(A)>1:
... | N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
l = [list(map(int,input().split())) for i in range(M)]
A.sort()
l = sorted(l,key = lambda x:x[1])
ind =0
for b,c in l[::-1]:
mx = min(N,ind+b)
for i in range(ind,mx):
if c>A[i]:
A[i] = c
if mx==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)]
A.sort()
BC.sort(key=lambda bc: bc[1], reverse=True)
update_bc = [0 for _ in range(N)]
cnt = 0
for b, c in BC:
for i in range(b):
if cnt < N:
update_b... | 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 bc: bc[1], reverse=True)
update_bc = [0 for _ in range(N)]
cnt = 0
for b, c in BC:
for i in range(b):
if cnt < N:
update_b... | p03038 |
import bisect
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b, c = [], []
heapq.heapify(a)
for i in range(m):
v1, v2 = list(map(int, input().split()))
b.append(v1)
c.append(v2)
for i in range(m):
cnt = 0
while True:
if cnt == b[i]:
... | import bisect
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
#b, c = [], []
bc = []
heapq.heapify(a)
for i in range(m):
bc.append(list(map(int, input().split())))
# v1, v2 = map(int, input().split())
# b.append(v1)
# c.append(v2)
bc.sort(key = lambd... | p03038 |
from bisect import bisect_left
from operator import itemgetter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
X = []
for _ in range(M):
b, c = list(map(int, input().split()))
X.append((b, c))
X = sorted(X, key=itemgetter(1), reverse=True)
for b, c in X:
B... | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
x = [c] * b
D.extend(x)
count... | p03038 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
D += [c] * b
count += b
if co... | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
A.extend([c] * b)
count += b
... | p03038 |
import heapq
n, m = list(map(int,input().split()))
a = [(-x, x) for x in map(int,input().split())]
heapq.heapify(a)
sum_a = 0
for i in range(m):
b,c = list(map(int,input().split()))
for j in range(b):
heapq.heappush(a,(-c, c))
for i in range(n):
sum_a += heapq.heappop(a)[1]
print(sum_a) | 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):
heapq.heappush(a,c)
if min(a) > c:
break
print((sum(heapq.nlargest(n, 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)]
hq = []
for i in range(N):
heapq.heappush(hq, A[i])
for bc in BC:
for i in range(bc[0]):
tmp = heapq.heappop(hq)
if tmp < bc[1]:
... | 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 = list(reversed(sorted(BC, key=lambda x:x[1])))
#print(BC)
hq = []
for i in range(N):
heapq.heappush(hq, A[i])
flag = False
for bc in BC:
for i in ra... | p03038 |
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)
CB = []
for i in range(M):
b, c = [int(x) for x in input().split()]
CB.append((c, b))
CB.sort(reverse... | # N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A.sort(reverse=True)
CB = []
for i in range(M):
b, c = [int(x) for x in input().split()]
CB.append((c, b))
CB.sort(reverse... | p03038 |
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
a, b = max(a, b), min(a, b)
while a % b > 0: a, b = b, a % b
return b
def solve():
N, M = list(map(int... | import sys
from operator import itemgetter
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [int(a) for a in input().split()]
A.sort()
C = [[int(i) for i in input().split()] for _ in range(M)]
C.sort(key=itemgetter(1), reverse = True)
counter = 0
... | p03038 |
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
BC = [[int(x) for x in input().split()] for _ in range(M)]
BC = sorted(BC, reverse = True, key = lambda x:x[1])
N2 = N
D = []
for i in BC:
temp = min(N2,i[0])
D += [i[1]] * temp
N2... | import sys
input = lambda : sys.stdin.readline().rstrip()
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, reverse=True, key=lambda x: x[1])
cnt = n
for b, c in bc:
if cnt <= b:
f... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
cards = A.copy()
for b, c in BC:
cards += [c] * b
print((sum((sorted(cards)[::-1])[:N])))
| N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
cards = {}
for a in A:
if not a in cards:
cards[a] = 1
else:
cards[a] += 1
for b, c in BC:
if not c in cards:
cards[c] = b
else:
cards[c] += b
count, sum_ca... | p03038 |
import itertools
N,M = (int(i) for i in input().split())
A = sorted([int(i) for i in input().split()])
accum = list(itertools.accumulate(A))
e = []
for k, v in sorted([[int(i) for i in input().split()] for i in range(M)], key=lambda x: -x[1]):
for _ in range(k):
e.append(v)
for i in range(min(len(e)... | N,M = (int(i) for i in input().split())
A = sorted([int(i) for i in input().split()])
e,p = [(0,0)],0
for k, v in sorted([[int(i) for i in input().split()] for i in range(M)], key=lambda x: -x[1]):
e.append((e[p][0]+k,v))
p+=1
p = 1
for i in range(min(e[-1][0],len(A))):
B,C = e[p]
if A[i]<C:
... | p03038 |
import sys
from heapq import merge
N, M = list(map(int, sys.stdin.readline().split()))
A = sorted([-i for i in list(map(int, sys.stdin.readline().split()))])
BC = sorted([list(map(int, sys.stdin.readline().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
card_list1 = []
for i in range(M):
tm... | import sys
N, M = list(map(int, sys.stdin.readline().split()))
A = [[1, i] for i in list(map(int, sys.stdin.readline().split()))]
BC = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
card_list = A + BC
sorted_cards = sorted(card_list, key=lambda x: x[1], reverse=True)
n = 0
cards_sum = 0
for ... | p03038 |
import sys
def intinput():
return list(map(int,sys.stdin.readline().split()))
n,m=intinput()
a = list(intinput())
a.sort()
l = []
for i in range(m):
b,c=intinput()
for j in range(b):
l.append(c)
l.sort(reverse=1)
sum=0
for i in range(len(a)):
try:
sum += max(a[i],l[i])... | import sys
def intinput(): return list(map(int,sys.stdin.readline().split()))
n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
b,c=intinput()
a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
k = min(cnt,y)
res += k*x
cnt -= k
prin... | p03038 |
import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
ans += a
BC = []
for _ in range(M):
B, C = list(map(int... | import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
BC = []
for _ in range(M):
B, C = list(map(int, input().split())... | p03038 |
import sys
def main():
input = sys.stdin.readline
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 = sorted(A, key=lambda x: -x)
return sum(A[:N])
if __name__ == '... | 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):
b, c = list(map(int, input().split()))
BC.append((b, c))
BC = sorted(BC, key=lambda x: -x[1])
n = 0
for b... | p03038 |
N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
D = [list(map(int,input().split())) for k in range(M)]
D = sorted(D, key = lambda x: -x[1])
now = 0
for d in D:
for k in range(now,now+d[0]):
if now == N:
break
if A[k] < d[1]:
A[k] =... | N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
L = [list(map(int,input().split())) for k in range(M)]
L = sorted(L,key=lambda x: -x[1])
now = 0
for e in L:
if now == N:
break
while True:
if A[now] < e[1] and e[0] > 0:
A[now] = e[1]
... | p03038 |
N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
L = []
for k in range(M):
B, C = list(map(int,input().split()))
L.append([B,C])
L = sorted(L,key=lambda x: -x[1])
ans = 0
i = 0
for k in range(N):
if i < M:
if A[k] < L[i][1]:
L[i][0] -= 1
... | N, M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
D = [list(map(int,input().split())) for k in range(M)]
D = sorted(D, key = lambda x: -x[1])
D.append([10**9+1,-1])
t = 0
ans = 0
for k in range(N):
if A[k] < D[t][1]:
ans += D[t][1]
D[t][0] -= 1
if D[... | p03038 |
from collections import Counter
def merge_dict_add_values(d1, d2):
return dict(Counter(d1) + Counter(d2))
n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
mydict={}
mydict[a[0]]=1
for i in range(1,len(a)):
d2={}
d2[a[i]]=1
mydict=merge_dict_add_values(mydict, d2)... | import heapq
h = []
n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
for i in a:
heapq.heappush(h, [(-1)*i,1])
for i in range(m):
b,c=(int(i) for i in input().split())
heapq.heappush(h, [(-1)*c,b])
num=0
data=0
while num <= n:
v=heapq.heappop(h)
data+=v[0]... | p03038 |
import sys
from heapq import heapify, heappush, heappop
N,M=list(map(int, sys.stdin.readline().split()))
A=list(map(int, sys.stdin.readline().split()))
heapify(A)
for _ in range(M):
b,c=list(map(int, sys.stdin.readline().split()))
for i in range(b):
if A[0]<c:
heappop(A)
heappush(A, c)
else... | import sys
N,M=list(map(int, sys.stdin.readline().split()))
A=list(map(int, sys.stdin.readline().split()))
A.sort()
B=[ list(map(int, sys.stdin.readline().split())) for _ in range(M)]
B.sort(key=lambda x: x[1], reverse=True)
i=0
for b,c in B:
for i in range(i,N):
if A[i]<c and 0<b:
A[i]=c
b... | p03038 |
# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop, heapify
from collections import Counter,defaultdict
dp=defaultdict(lambda: 0)
N,M=list(map(int, sys.stdin.readline().split()))
A=list(map(int, sys.stdin.readline().split()))
BC=defaultdict(lambda: 0)
for _ in range(M):
b,c=list(map(int... | # -*- coding: utf-8 -*-
import sys
N,M=list(map(int, sys.stdin.readline().split()))
A=list(map(int, sys.stdin.readline().split()))
B=[ list(map(int, sys.stdin.readline().split())) for _ in range(M) ]
B.sort(key=lambda x:-x[1] )
n=N
L=[] #Bから降順でN個選ぶ
for cards,value in B:
if cards<=n: #カード全てがn枚に収まる場合... | p03038 |
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def... | import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def... | p03038 |
import sys
import bisect
from collections import defaultdict
ans=0
#n=int(input())
n,m=list(map(int,input().split()))
a=[(1,int(i)) for i in input().split()]
b=[0]*m
c=[0]*m
for i in range(m):
b[i],c[i]=list(map(int,input().split()))
a.append((b[i],c[i]))
#a=sorted(a,reverse=True,key=lambda x:x[... | ans=0
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))
a=sorted(a,key=lambda x:x[1])
t=0
while t<n:
k,x=a.pop()
ans+=x*min(k,n-t)
t+=k
print(ans) | 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)]
#print(N,M)
#print(A)
#print(BC)
#print("---")
A = sorted(A)
times = [bc[0] for bc in BC]
values = [bc[1] for bc in BC]
values, times = list(zip(*sorted(zip(values, times),revers... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
#print(N,M)
#print(A)
#print(BC)
#print("---")
A = sorted(A)
BC = sorted(BC, key = lambda x: -x[1])
D = []
for bc in BC :
for i in range(bc[0]) :
if len(D) < N :
... | 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)]
L = []
# cnt_sum = 0
# min_num = BC[0][1]
# for i in range(M):
# cnt = BC[i][0]
# for j in range(N):
# if cnt_sum <= N:
# L.append(BC[i][1])
# ... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
L = []
BC.sort(key=lambda x:x[1], reverse=True)
A.sort()
# ans = sum(A)
ans = 0
# flag = False
cnt = 0
# for k in range(N):
# if k <= len_L-1:
# if flag and L[k] ... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0] * (m)
c = [0] * (m)
for i in range(m):
b[i], c[i] = list(map(int, input().split()))
d = []
for i in range(m):
for j in range(b[i]):
d.append(c[i])
a.extend(d)
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 _ in range(m):
b, c = list(map(int, input().split()))
a.append((b, c))
a = sorted(a, key=lambda x: x[1])
res = 0
idx = 0
while idx < n:
b, c = a.pop()
p = min(b, n-idx)
res += p * c
idx += p
print(... | p03038 |
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.r... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x) - 1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.r... | p03038 |
from heapq import heappop, heappush, heapify
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]
List = sorted(List, reverse=True, key=lambda x: x[1])
heapify(A)
i = 0
while i<M:
m = min(A)
tmp = List[i][1]
c... | from heapq import heappop, heappush, heapify
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]
List = sorted(List, reverse=True, key=lambda x: x[1])
heapify(A)
i = 0
while i<M:
m = heappop(A)
heappush(A, m)
... | p03038 |
from bisect import bisect_left
from collections import deque
from itertools import islice
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
cards = {}
for i in range(N):
cards[As[i]] = cards.get(As[i], 0) + 1
# sorted_keys = deque(sorted(cards.keys()))
sorted_keys = list(sorte... | N, M = list(map(int,input().split()))
As = sorted(list(map(int,input().split())))
di = {}
for i in range(M):
b, c = list(map(int,input().split()))
di[c] = di.get(c, 0) + b
keys = list(sorted(list(di.keys()), reverse=True))
ichi = 0
for i in range(N):
try:
if keys[ichi] > As[i]:
... | p03038 |
from collections import Counter
import heapq
n,m = list(map(int,input().split()))
l = list(map(int,input().split()))
hq = sorted(tuple(Counter(l).items()), key=lambda x:x[0])
heapq.heapify(hq)
# print(hq)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])
for... | import sys
import heapq
input = sys.stdin.readline
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])
for b,c in BC:
for i in range(b):
a = heapq.heappop(A)
... | p03038 |
import sys
import heapq
input = sys.stdin.readline
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])
for b,c in BC:
for i in range(b):
a = heapq.heappop(A)
... | import sys
input = sys.stdin.readline
n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split())) for i in range(m)]
BC = sorted(BC,key=lambda x:-x[1])
cnt = 0
flag = True
while True:
for b,c in BC:
A += [c]*b
cnt += b
if cnt > ... | 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
print((sum(sorted(A,reverse=True)[:n]))) | n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]
bc = sorted(bc,key=lambda x:-x[1])
sub = []
for i in range(m):
sub += [bc[i][1]] * bc[i][0]
if len(sub) > n:
break
A += sub
print((sum(sorted(A,reverse=True)[:n]))) | p03038 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, s... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, s... | p03038 |
from heapq import heapify, heappush, heappop
class HeapQue(object):
def __init__(self, iterable, max_heap=False):
self.sign = -1 if max_heap else 1
sequence = [self.sign * number for number in iterable]
heapify(sequence)
self.heapque = sequence
def push(self, item):
... | from heapq import heapify, heappush, heappop
N, M = list(map(int, input().split()))
q = list(map(int, input().split()))
heapify(q)
pairs = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda t: t[1], reverse=True)
for b, c in pairs:
for _ in range(b):
x = heappop(q)
if x ... | p03038 |
from heapq import heappush, heappop
# input
N,M =list(map(int,input().split()))
A = [0]*N
B = [0]*M
C = [0]*M
A = list(map(int, input().split()))
A.sort()
for i in range(M):
B[i],C[i] = list(map(int,input().split()))
def solve():
pairs = list(zip(C, B))
sortedpairs = sorted(pairs, key=... | import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []
N, M = LI()
A = LI()
BC = [LI() for _ in range(M)]
A = list([x*(-1) for x in A])
heapq.heapify(A)
BC = sorted(BC, key=lambda x: x[1])[:... | p03038 |
import bisect
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 = sorted(BC, key=lambda x: x[1])
BC.reverse()
for i in range(M):
B, C = BC[i]
in_idx = bisect.bisect_right(A,C)
... | N, M = list(map(int,input().split()))
A = [-1]
A += list(map(int,input().split()))
A.sort()
BC = [[1,-1]]
for i in range(M):
BC.append(list(map(int,input().split())))
BC = sorted(BC, key=lambda x: x[1])
x = 0
for i in range(N):
if A[-1] > BC[-1][1]:
x += A.pop()
e... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
all_set = a
for _ in range(m):
# l.append(list(map(int, input().split())))
bi, ci = list(map(int, input().split()))
for _ in range(bi):
all_set.append(ci)
print((sum(sorted(all_set, reverse=True)[:n]))) | # coding: utf-8
# Your code here!
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())))
l = sorted(l, key=lambda x:x[1], reverse=True)
top_n = []
flag = False
for bi, ci in l:
for _ in range(bi):
... | p03038 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
bc = []
for i in range(M):
bc.append(list(map(int,input().split())))
A = sorted(A,reverse=True)
bc = sorted(bc,key=lambda x : x[1],reverse=True)
AA = []
for i in range(M):
l = [bc[i][1]]*bc[i][0]
AA += l
AA = sorted(AA)... | N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
bc.append(list(map(int,input().split())))
bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
for j in range(i,min(N,i+b)):
if A[j] < c:
A[j] = c
i += b
p... | p03038 |
N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True)
cur = 0
cnt = 0
for i in range(N):
if A[i]<B[cur][1] and cnt<B[cur][0]:
A[i]=B[cur][1]
cnt += 1
elif A[i]>=B[cur]... | N,M = list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True)
cur = 0
cnt = B[0][0]
for i in range(N):
a = A[i]
if cur<M and B[cur][1]>a:
if cnt>0:
A[i] = B[cur][1]
... | p03038 |
"""
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [list(map(int, input().split())) for _ in range(m)]
b.sort(key = lambda x : x[1], reverse = True)
a.sort()
i = 0
j = 0
c = 1
ans = sum(a)
while True:
if i >= m:
break
for _ in range(b[i][0]):
if j >= n:
... | 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([c, b])
a.sort()
bc.sort(reverse = True)
x = [0] * n
i, j = 0, 0
while i < n:
for _ in range(bc[j][1]):
x[i] = bc[j][0]
i += 1
... | p03038 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(m... | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, ... | p03038 |
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
d = []
for i in range(m):
b, c = list(map(int, input().split()))
d.extend([c]*b)
d.sort(reverse=True)
for i in range(min(n, len(d))):
if a[i] >= d[i]:
break
a[i] = d[i]
print((sum(a))) | n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
op = []
for i in range(m):
b, c = list(map(int, input().split()))
op.append((c, b))
op.sort(reverse=True)
j = 0
k = 0
for i in range(n):
if a[i] >= op[j][0]:
break
a[i] = op[j][0]
k += 1... | p03038 |
import heapq
def solve():
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)
BC2 = []
for bc in BC:
for i in range(bc[0]):
BC2... | def solve():
N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
operate = []
for _ in range(M):
b, c = list(map(int,input().split()))
operate.append([b,c])
operate.sort(reverse=True, key=lambda x:x[1])
rewrite = [0] * N
idx =... | p03038 |
def main():
from bisect import bisect_left
n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
for _ in range(m):
b,c=list(map(int,input().split()))
index = bisect_left(a,c)
b=index if b>=index else b
a=[c]*b+a[b:]
a.sort()
print((sum(a)))
if __name__=='_... | def main():
n,m=list(map(int,input().split()))
a=sorted(list(map(int,input().split())))
bc=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
bc.append([1,a[i]])
bc.sort(key=lambda x:x[1],reverse=True)
ans,cnt=0,0
for i in range(n):
ans+=bc[i][0]*bc[i][1]
cnt+=bc[i... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
A.append(0)
S = []
heapq.heapify(S)
c = A[0]
cnt = 1
for i in range(1, N + 1):
if A[i] == c:
cnt += 1
else:
heapq.heappush(S, (A[i - 1], cnt))
cnt = 1
c = A[i]
... | import heapq
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
A.append(0)
S = []
heapq.heapify(S)
c = A[0]
cnt = 1
for i in range(1, N + 1):
if A[i] == c:
cnt += 1
else:
heapq.heappush(S, (A[i - 1], cnt))
cnt = 1
c = A[i]
... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
A.append(0)
S = []
heapq.heapify(S)
c = A[0]
cnt = 1
for i in range(1, N + 1):
if A[i] == c:
cnt += 1
else:
heapq.heappush(S, (A[i - 1], cnt))
cnt = 1
c = A[i]
... | N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
D = []
for i in range(M):
b, c = list(map(int, input().split()))
D.append((c, b))
A.sort()
D.sort(reverse=True)
i = 0
for c, b in D:
for j in range(i, min(i + b, N)):
A[j] = max(c, A[j])
i += b
print((s... | p03038 |
def read_input():
n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
clist = []
for i in range(m):
b, c = list(map(int, input().split()))
clist.extend([c]*b)
return alist, clist
def submit():
alist, clist = read_input()
alis... |
def read_input():
n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
clist = []
for i in range(m):
b, c = list(map(int, input().split()))
clist.append([c, b])
return alist, clist
def submit():
alist, clist = read_input()
alist... | p03038 |
#!/usr/bin/env python3.4
# abc127_d
import collections
import itertools
import functools
def find_index(iterable, func, from_i):
i = from_i
l = len(iterable)
while i<l and not func(iterable[i]):
i += 1
return i
def insert(deq, i, x):
l = len(deq)
if i < l/2:
... | #!/usr/bin/env python3.4
# abc127_d
import collections
import itertools
import functools
def main():
# Input
_, m = [int(s) for s in input().split()]
cards = [int(s) for s in input().split()]
acts = [[int(s) for s in input().split()] for _ in range(m)]
# Get ans
cards = collecti... | p03038 |
#!/usr/bin/env python3.4
# abc127_d
import collections
import itertools
import functools
def main():
# Input
_, m = [int(s) for s in input().split()]
cards = [int(s) for s in input().split()]
acts = [[int(s) for s in input().split()] for _ in range(m)]
# Get ans
cards = collecti... | #!/usr/bin/env python3.4
# abc127_d
import collections
def main():
# Input
n, m = [int(s) for s in input().split()]
cards = [int(s) for s in input().split()]
acts = [[int(s) for s in input().split()] for _ in range(m)]
# Get ans
cards = collections.deque(sorted(cards), n)
act... | 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):
a = heapq.heappop(A)
if a < c:
heapq.heappush(A, c)
else:
heapq.heappush(A, a)
break
print(... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(M):
b, c = list(map(int, input().split()))
B.append([c, b])
B.sort(reverse=True)
i = 0
f = 0
for j in range(M):
while B[j][1]:
if A[i] < B[j][0]:
A[i] = B[j][0]
B[j][1] -= 1
... | p03038 |
import heapq
N, M = list(map(int, input().split()))
nums = list(map(int, input().split()))
n = len(nums)
heap = []
for i in range(M):
B, C = list(map(int, input().split()))
heap.append([-C, B])
for num in nums:
heap.append([-num, 1])
s = 0
heapq.heapify(heap)
while n > 0:
num, cnt = heapq.h... | def getInput():
return [int(x) for x in input().split()]
N, M = getInput()
nums = getInput()
nums = sorted(nums)
rep = []
for i in range(M):
b, c = getInput()
rep.append((b, c))
rep = sorted(rep, key=lambda x: x[1], reverse=True)
ans = 0
minIndex = 0
isFinished = False
for b, c in rep:
f... | p03038 |
import bisect
n,m = list(map(int,input().split()))
lst = list(map(int,input().split()))
lst.sort()
for i in range(m):
b,c = list(map(int,input().split()))
pos = bisect.bisect_left(lst,c)
for j in range(min(b,pos)):
lst[j] = c
lst.sort()
print((sum(lst))) | n,m = list(map(int,input().split()))
l_a = sorted(list(map(int,input().split())))
l_bc = [list(map(int,input().split())) for _ in range(m)]
l_bc.sort(key = lambda x:x[1],reverse = True)
for b,c in l_bc:
l_a.extend([c]*b)
if len(l_a) > 2*n:
break
l_a.sort(reverse = True)
print((sum(l_a[:n]))) | p03038 |
n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
ans = 0
cnt = 0
d = {}
for i in range(n):
d[a[i]] = d.get(a[i],0)+1
for k in d:
bc.append([d[k],k])
bc.sort(key= lambda x:x[1],reverse=True)
for i in range(len(b... | n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
d = []
cnt1 = 0
cnt2 = 0
x = 0
for lst in bc:
cnt2 = 0
while cnt1 < n and cnt2 < lst[0]:
d.append(lst[1])
... | p03038 |
n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
d = []
cnt1 = 0
cnt2 = 0
x = 0
for lst in bc:
cnt2 = 0
while cnt1 < n and cnt2 < lst[0]:
d.append(lst[1])
... | n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
d = []
cnt1 = 0
cnt2 = 0
x = 0
for lst in bc:
cnt2 = 0
while cnt1 < n and cnt2 < lst[0]:
d.append(lst[1])
... | p03038 |
from operator import itemgetter
n, m = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
#print(a)
bc = []
for _ in range(m):
bc.append([int(i) for i in input().split()])
bc = sorted(bc, key=itemgetter(1), reverse=True)
#print(bc)
ans = 0
for b,c in bc:
#print(a,b,c)
... | from operator import itemgetter
n, m = [int(i) for i in input().split()]
a = sorted([int(i) for i in input().split()])
#print(a)
bc = []
for _ in range(m):
bc.append([int(i) for i in input().split()])
bc = sorted(bc, key=itemgetter(1), reverse=True)
#print(bc)
change = []
for b,c in bc:
len_change ... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
if N == 1:
print((max(A[0], BC[0][1])))
quit()
heapq.heapify(A)
for b, c in BC:
a = A[0]
if a >= c:
continue
else:
curPo... |
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: x[1], reverse=True)
if N == 1:
print((max(A[0], BC[0][1])))
quit()
heapq.heapify(A)
for b, c in BC:
a = A[0]
if a >= c:... | p03038 |
from collections import deque
N, M = list(map(int, input().split()))
A = deque(list(map(int, input().split())))
for i in range(M):
B, C = list(map(int, input().split()))
A.extend([C]*B)
E = list(A)
E.sort(reverse = True)
print((sum(E[:N]))) | from collections import deque
N, M = list(map(int, input().split()))
A = deque(list(map(int, input().split())))
for i in range(M):
B, C = list(map(int, input().split()))
if C >= min(A):
A.extend([C]*B)
E = list(A)
E.sort(reverse = True)
print((sum(E[:N]))) | p03038 |
import heapq
n, m = list(map(int, input().split()))
queue = []
for a in map(int, input().split()):
heapq.heappush(queue, a)
for _ in range(m):
b, c = list(map(int, input().split()))
for _ in range(b):
if queue[0] < c:
heapq.heapreplace(queue, c)
else:
break
print((sum(queue))) | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cb = [list(map(int, input().split()[::-1])) for _ in range(m)]
a.sort()
cb.sort()
summation = 0
a_tmp = a.pop()
cb_tmp = cb.pop()
for i in range(n):
if a_tmp >= cb_tmp[0]:
summation += a_tmp
if a:
a_tmp = a.pop()
e... | p03038 |
from bisect import bisect_left
from heapq import heappop, heappush
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
BC = []
for i in range(M):
b, c = list(map(int, input().split()))
heappush(BC, (-c, b))
for i in range(M):
mc, b = heappop(BC)
c = -mc
inde... | from heapq import heappop, heappush, heapify
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapify(A)
BC = []
for i in range(M):
b, c = list(map(int, input().split()))
heappush(BC, (-c, b))
for i in range(M):
mc, b = heappop(BC)
c = -mc
end = False
for j in r... | p03038 |
import heapq
push, pop = heapq.heappush, heapq.heappop
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):
p = pop(a)
if p < c:
push(a, c)
else:
... | import heapq
push, pop = heapq.heappush, heapq.heappop
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
def modify():
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
for b,c in bc:
... | p03038 |
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
mat = []
for _ in range(m):
b, c = list(map(int, input().split()))
mat.extend([c] * b)
mat = sorted(mat, reverse=True)[:n]
for i, t in enumerate(a):
if i == len(mat):
break
if t < mat[i]:
a[i] =... | n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
bc = [[0] * 2 for _ in range(m)]
for i in range(m):
bc[i] = list(map(int, input().split()))
bc = sorted(bc, key=lambda x: x[1], reverse=True)
mat = []
for b, c in bc:
if len(mat) + b > n:
mat.extend([c] * (n - le... | p03038 |
N,M = list(map(int,input().split()))
A= list(map(int,input().split()))
for i in range(M):
B,C = list(map(int,input().split()))
A.extend([C]*B)
b=sorted(A)
print((sum(b[-N:]))) | import sys
input = sys.stdin.readline
N,M = list(map(int,input().split()))
A= list(map(int,input().split()))
for i in range(M):
B,C = list(map(int,input().split()))
A.extend([C]*B)
b=sorted(A)
print((sum(b[-N:]))) | p03038 |
import bisect
import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
A= list(map(int,input().split()))
A = sorted(A)
BC=[list(map(int,input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1],reverse=True)
for B,C in BC:
index =... | import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
A= list(map(int,input().split()))
A = sorted(A)
BC=[list(map(int,input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1],reverse=True)
index=0
max_index=len(A)
for B,C... | p03038 |
import heapq
n, m = list(map(int, input().split()))
al = list(map(int, input().split()))
h = []
ad = {}
for a in al:
if a not in ad:
ad[a] = 1
else:
ad[a] += 1
for i in range(m):
b, c = list(map(int, input().split()))
if c not in ad:
ad[c] = b
... | import heapq
n, m = list(map(int, input().split()))
al = list(map(int, input().split()))
h = []
ad = {}
for a in al:
if a not in ad:
ad[a] = 1
else:
ad[a] += 1
for i in range(m):
b, c = list(map(int, input().split()))
if c not in ad:
ad[c] = b
... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
origin = sum(A)
heapq.heapify(A)
for _ in range(M):
b, c = list(map(int, input().split()))
for _ in range(b):
smallest = heapq.heappop(A)
tmp = c - smallest
if tmp <= 0:
hea... | import sys
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
origin = sum(A)
heapq.heapify(A)
BC = [list(map(int, input().split())) for _ in range(M)]
BC = sorted(BC, reverse=True, key=lambda x: x[1])
count = 0
for i in range(M):
b = BC[i][0]
c = BC[i][1]... | p03038 |
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
for b, c in bc:
for _ in range(b):
x = heapq.heappop(a)
if c > x:
heapq.heappush(a, c)
else:
... | import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc = sorted(bc, key=lambda x: -x[1])
for b, c in bc:
for _ in range(b):
x = heapq.heappop(a)
if c > x:
heapq.heapp... | p03038 |
# sys.stdin.readline()
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
for _ in range(m):
b, c= list(map(int, input().split()))
if a[n-1] < c:
for i in range(min(b,n)):
a.append(c)
a.so... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, m = list(map(int, readline().split()))
a = sorted(list(map(int, readline().split())))
bc = [tuple(map(int, readline().split())) for i in range(m)]
bc.sort(key=l... | p03038 |
n,m=list(map(int,input().split()))
a=[int(i) for i in input().split()]
for i in range(m):
a.sort()
b,c=list(map(int, input().split()))
for i in range(b):
if a[i] < c:
a[i] = c
else:
break
print((sum(a))) | n,m=list(map(int,input().split()))
l=[[int(x),1] for x in input().split()]
for i in range(m):
b,c=list(map(int,input().split()))
l.append([c,b])
s = sorted(l, key=lambda x:x[0], reverse=True)
c=n
t=0
i=0
while c>0:
n = s[i][1] if c>=s[i][1] else c
t += s[i][0] * n
c -= n
i += 1
print(t)
| p03038 |
from collections import defaultdict
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
d=defaultdict(int)
a.sort()
for i in range(m):
b,c=list(map(int,input().split()))
d[c]+=b
d_sorted=sorted(list(d.items()),reverse=True, key=lambda x:x[0])
l=[]
for i,j in d_sorted:
for k ... | from collections import defaultdict
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
d=defaultdict(int)
a.sort()
for i in range(m):
b,c=list(map(int,input().split()))
d[c]+=b
d_sorted=sorted(list(d.items()),reverse=True, key=lambda x:x[0])
l=[]
for i,j in d_sorted:
for k ... | p03038 |
import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = []
C = []
BC = []
A.sort()
for i in range(M):
b, c = list(map(int, input().split()))
B.append(b)
C.append(c)
BC.append([b, c])
sorted(BC, key=lambda x: x[1])
BC = BC[::-1]
C = C.sort()
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = []
C = []
BC = []
A.sort()
for i in range(M):
b, c = list(map(int, input().split()))
B.append(b)
C.append(c)
BC.append([b, c])
BC = sorted(BC, key=lambda x: x[1])
BC = BC[::-1]
C = C.sort()
# print(A... | p03038 |
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
for i in range(m):
b, c = list(map(int, input().split()))
for j in range(b):
if c > a[0]:
heapq.heapreplace(a, c)
else:
break
print((sum(a))) | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = {}
for i in range(n):
if a[i] in cnt:
cnt[a[i]] += 1
else:
cnt[a[i]] = 1
for i in range(m):
b, c = list(map(int, input().split()))
if c in cnt:
cnt[c] += b
else:
cnt[... | p03038 |
import heapq
h = []
h2 = []
N, M = [int(i) for i in input().split()]
count = dict()
for i in input().split():
if not count.get(i):
count[i] = 0
count[i] += 1
for k, v in list(count.items()):
heapq.heappush(h, (int(k), v))
for _ in range(M):
B, C = [int(i) for i in input().split()... | import heapq
h = []
h2 = []
N, M = [int(i) for i in input().split()]
count = dict()
count2 = dict()
for i in input().split():
if not count.get(i):
count[i] = 0
count[i] += 1
for k, v in list(count.items()):
heapq.heappush(h, (int(k), v))
for _ in range(M):
B, C = [int(i) for i i... | p03038 |
import sys
input = sys.stdin.readline
n,m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort()
bc=[]
for i in range(m):
b,c = list(map(int, input().split(" ")))
bc = bc + [c]*b
bc.sort(reverse=True)
for i in range(n):
if len(bc) <= i or bc[i] <= a[i]:
brea... | import sys
input = sys.stdin.readline
n,m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
l.extend([c]*b)
if n < len(l):
... | p03038 |
import sys
input = sys.stdin.readline
n,m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
l.extend([c]*b)
if n < len(l):
... | import sys
from itertools import zip_longest
input = sys.stdin.readline
n,m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
l.... | 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 = []
for i in range(M):
B.append(BC[i][0])
C.append(BC[i][1])
for i in range(M):
A.sort()
card = 0
for j in range(N):
if A[j] < C[i]:... | from operator import itemgetter
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.sort(key = itemgetter(1),reverse=True)
change = []
for b,c in BC:
change += [c] * b
if len(change) ... | p03038 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.