input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
# そのままの k
ans = 0
for a, b in ab:
if k & a == a:
ans += b
for i in range(31):
# 上からi桁目までいっち、あとは1111
if k >> i & 1 == 0:
continue
nk = k
nk &= ~(1 << i)
for j in range... | n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = sum([b for a, b in ab if k & a == a])
for i in range(30):
if k >> i & 1:
nk = 1 << i ^ k
for j in range(i):
nk |= 1 << j
ans = max(ans, sum([b for a, b in ab if nk &... | p03584 |
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
int_list = []
for _ in range(N):
A, B = list(map(int, input().split()))
int_list.append([A, B])
K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_lis... | import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
int_list = []
for _ in range(N):
A, B = list(map(int, input().split()))
int_list.append([A, B])
K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_lis... | p03584 |
# Problem A
A, B, C = list(map(int, input().split()))
tmp = B
B = A
A = tmp
tmp = A
A = C
C = tmp
# output
print(("%d %d %d"%(A, B, C)))
| # Problem A - ABC Swap
# input
X, Y, Z = list(map(int, input().split()))
# swap
tmp = X
X = Y
Y = tmp
tmp = X
X = Z
Z = tmp
# output
print(("%d %d %d"%(X, Y, Z)))
| p02717 |
a,b,c = input().split()
print((c+' '+a+' '+b)) | a,b,c=map(int,input().split())
print(c,a,b,sep=' ')
| p02717 |
# [箱A, 箱B, 箱C]
list = input().split()
# 箱Aと箱B入れ替え
temp = list[0]
list[0] = list[1]
list[1] = temp
# 箱Aと箱C入れ替え
temp = list[0]
list[0] = list[2]
list[2] = temp
print((' '.join(list))) | # [箱A, 箱B, 箱C]
list = input().split()
# 箱Aと箱B入れ替え
list[0], list[1] = list[1], list[0]
# 箱Aと箱C入れ替え
list[0], list[2] = list[2], list[0]
print((' '.join(list))) | p02717 |
import sys
input = sys.stdin.readline
class BIT:
def __init__(self, size):
self.bit = [0] * (size + 1)
self.size = size
def sum(self, i):
i += 1
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i... | from itertools import accumulate
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list([int(x) - 1 for x in input().split()])
cnt0 = [0] * m
cnt1 = [0] * m
for i in range(n-1):
cnt0[a[i+1]] += (a[i+1] - a[i]) % m - 1
if (a[i] + 1) % m <= a[i+1]:
cnt1[(a[i]+1... | p03677 |
n,m,*A=list(map(int,open(0).read().split()));l=3*m;D=[0]*l;S=0
for a,b in zip(A,A[1:]):
b+=m*(b<a);k=b-a;S+=k
if k>1:D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
exec("for i in range(1,l):D[i]+=D[i-1]\n"*2);print((S-max(D[a]+D[a+m]for a in A))) | _,m,*A=list(map(int,open(0).read().split()));S=l=3*m;D=[0]*l
for a,b in zip(A,A[1:]):
b+=m*(b<a);k=b-a;S+=k
if k>1:D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
exec("for i in range(l):D[i]+=D[i-1]\n"*2);print((S-l-max(D[a]+D[a+m]for a in A))) | p03677 |
_,m,*A=list(map(int,open(0).read().split()));S=l=3*m;D=[0]*l
for a,b in zip(A,A[1:]):
b+=m*(b<a);k=b-a;S+=k
if k>1:D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
exec(("i=0;"+"D[i]+=D[i-1];i+=1;"*l)*2);print((S-l-max(D[a]+D[a+m]for a in A))) | _,m,*A=list(map(int,open(0).read().split()));S=l=3*m;D=[0]*l
for a,b in zip(A,A[1:]):b+=m*(b<a);k=b-a;S+=k;D[a+2]+=1;D[b+1]-=k;D[b+2]+=k-1
exec("for i in range(l):D[i]+=D[i-1]\n"*2);print((S-l-max(D[a]+D[a+m]for a in A))) | p03677 |
from collections import defaultdict
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <... | from collections import defaultdict
from itertools import accumulate
n, m = list(map(int, input().split()))
aa = list(map(int, input().split()))
counter = defaultdict(list)
cum = [0] * (m + 2)
ans_1 = 0
for a, b in zip(aa, aa[1:]):
counter[b].append(a)
cum[a + 1] += 1
cum[b] += -1
if a > ... | p03677 |
from collections import defaultdict
from itertools import accumulate
n, m = list(map(int, input().split()))
aa = list(map(int, input().split()))
counter = defaultdict(list)
cum = [0] * (m + 2)
ans_1 = 0
for a, b in zip(aa, aa[1:]):
counter[b].append(a)
cum[a + 1] += 1
cum[b] += -1
if a > ... | from collections import defaultdict
from itertools import accumulate
n, m = list(map(int, input().split()))
aa = list(map(int, input().split()))
counter = defaultdict(list)
cum = [0] * (m + 2)
ans_1 = 0
for a, b in zip(aa, aa[1:]):
counter[b].append(a)
cum[a + 1] += 1
cum[b] += -1
if a > ... | p03677 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
ex = [0] * m
left = [0] * (2*m)
right = [[0,0] for _ in range(2*m)]
ans = 0
for i in range(n-1):
a0 = a[i]-1
a1 = a[i+1]-1
ans += (a1-a0)%m
left[a0+1] += 1
right[a1 + (a0>a1)*m][0] += 1
right[a1 + (a0>a1)*m][... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
imos = [0] * (2*m+2)
ans = 0
for i in range(n-1):
a0 = a[i]-1
a1 = a[i+1]-1
dif = (a1-a0)%m
ans += dif
if(dif>=2):
imos[a0+2] += 1
imos[a0+dif+1] -= dif
imos[a0+dif+2] += dif-1
# print(im... | p03677 |
def main():
n, m = list(map(int, input().split()))
a = list([int(x)-1 for x in input().split()])
event = [[] for _ in [0]*m]
for j, i in enumerate(a):
if j < n-1:
A = m-a[j+1]
if A < m:
event[A].append((True, j))
B = m-i
if B < m:... | def main():
n, m = list(map(int, input().split()))
a = list([int(x)-1 for x in input().split()])
event = [[] for _ in [0]*m]
for j, i in enumerate(a):
if j < n-1:
A = m-a[j+1]
if A < m:
event[A].append((True, j))
B = m-i
if B < m:... | p03677 |
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline()... | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS... | p03677 |
def is_ok(A, index, key):
return A[index] >= key
def binary_search(A, key):
ng = -1
ok = len(A)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(A, mid, key):
ok = mid
else:
ng = mid
return ok
def main():
N, M = list(m... | def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
h = {}
for a in A:
if a in h:
h[a] += 1
else:
h[a] = 1
for m in range(M):
B, C = list(map(int, input().split()))
if C in h:
h[C] += B... | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = list(list(map(int,input().split())) for i in range(m))
a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
t = 0
for i in range(m):
for j in range(bc[i][0]):
if t != n:
if a[t] < bc[i][1]:
a[t] ... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = list(list(map(int,input().split())) for i in range(m))
a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
t = 0
for i in range(m):
for j in range(bc[i][0]):
if t != n:
if a[t] < bc[i][1]:
a[t] ... | p03038 |
n, m = list(map(int, input().split()))
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]
for i in range(m):
k = list_kard[i]
l = [k[1]]*k[0]
list_score.extend(l)
list_score.sort(reverse=True)
print((sum(list_score[:n]))) | n, m = list(map(int, input().split()))
list_score = list(map(int, input().split()))
list_kard = [ list(map(int,input().split(" "))) for i in range(m)]
list_score_colume = list(set(list_score))
for i in range(len(list_score_colume)):
k = [list_score.count(list_score_colume[i]), list_score_colume[i]]
li... | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(m):
b, c = list(map(int, input().split()))
a += [c] * b
a.sort(reverse=True)
print((sum(a[:n]))) | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a_min = min(a)
for i in range(m):
b, c = list(map(int, input().split()))
if c > a_min:
a += [c] * b
a.sort(reverse=True)
print((sum(a[:n]))) | p03038 |
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a_min = min(a)
for i in range(m):
b, c = list(map(int, input().split()))
if c > a_min:
a += [c] * b
if b > n//2:
a = sorted(a, reverse=True)[:n]
a.sort(reverse=True)
print((sum(a[:n]))) | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a_min = min(a)
for i in range(m):
b, c = list(map(int, input().split()))
if c > a_min:
a += [c] * b
a = sorted(a, reverse=True)[:n]
a_min = a[-1]
a.sort(reverse=True)
print((sum(a[:n]))) | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
BC=[list(map(int,input().split())) for _ in range(m)]
for i in range(m):
while BC[i][0]>0:
if BC[i][1] > a[0]:
minA = heapq.heappop(a)
heapq.heappush(a,BC[i][1])
... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
BC=[list(map(int,input().split())) for _ in range(m)]
BC.sort(reverse=True,key=lambda x:x[1])
for i in range(m):
while BC[i][0]>0:
if BC[i][1] > a[0]:
minA = heapq.heappop(a)
... | p03038 |
import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
break
heap... | import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
break
d = ... | p03038 |
import heapq
from collections import Counter
from itertools import starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(Counter(R()).items())
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
... | import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
break
d = ... | p03038 |
import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
break
d = ... | import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i:
x, y = a[0]
if x >= c:
break
if y... | p03038 |
import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i and a[0][0] < c:
x, y = a[0]
if y > i:
heap... | import heapq
from itertools import repeat, starmap
from operator import mul
R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
b, c = R()
i = b
while i and a[0][0] < c:
x, y = a[0]
if y > i:
heap... | p03038 |
n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
for _ in range(m):
b, c = list(map(int, input().split()))
k = [c]*b
a = a + k
a.sort()
a = a[-n::]
ans = sum(a)
print(ans) | n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
p = [(a[i], 1) for i in range(n)]
for i in range(m):
b, c = list(map(int, input().split()))
p.append((c, b))
p.sort()
p.reverse()
ans, count = 0, n
for (s, t) in p:
k = min(count, t)
ans += s * k
count -... | p03038 |
import bisect
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
for _ in range(M):
B, C = list(map(int, input().split()))
i = bisect.bisect_right(A, C)
if N <= i:
A = A[B:i] + [C] * B + A[i:]
elif i <= B:
A[:i] = [C] * i
else:
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
BC = []
for _ in range(M):
B, C = list(map(int, input().split()))
BC.append((B, C))
BC.sort(key=lambda bc: (bc[1], bc[0]), reverse=True)
ai = 0
bci = bcj = 0
while ai < N and bci < M:
if A[ai] < BC[bci][1]:
... | p03038 |
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[];C=[];Q=[]
A.sort()
for i in range(m):
b,c=list(map(int,input().split()))
Q.append([b,c])
import bisect as bi
#Qの統合
s=set([l[1] for l in Q])
dicts={}
for i in s:
dicts[i]=0
for l in Q:
dicts[l[1]]+=l[0]
Q=[[j,i] f... | n,m=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
Q=[]
for i in range(m):
b,c=list(map(int,input().split()))
Q.append([b,c])
Q=sorted(Q, key=lambda x:x[1], reverse=1)
kae=0
d=[-1]*(n)
now=0
for l in Q:
b,c=l
if n-now<b:
d[now:]=[c]*(n-now)
br... | p03038 |
from heapq import *
n, m = list(map(int, input().split()))
PAIRS = [[-a, -1] for a in map(int, input().split())]
heapify(PAIRS)
for _ in range(m):
b, c = list(map(int, input().split()))
heappush(PAIRS, [-c, -b])
answer = 0
for _ in range(n):
pair = heappop(PAIRS)
answer += -pair[0]
... | n, m = list(map(int, input().split()))
PAIRS = [(a, 1) for a in map(int, input().split())]
for _ in range(m):
b, c = list(map(int, input().split()))
PAIRS.append((c, b))
PAIRS.sort(reverse = True)
answer, count = 0, 0
for pair in PAIRS:
answer += pair[0] * pair[1]
count += pair[1]
if c... | p03038 |
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
b,c = list(map(int,input().split()))
d.extend([c]*b)
if n < len(d):
d=d[:n]
d.sort()
d=d[::-1]
for i in range(len(d)):
for j in range(n):
if a[j] < d[i]:
a[j]=d[i]
break
print((s... | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
b,c = list(map(int,input().split()))
d.extend([c]*b)
if n < len(d):
d=d[:n]
d.sort(reverse=True)
for i in range(len(d)):
for j in range(n):
if a[j] < d[i]:
a[j]=d[i]
break
print((... | p03038 |
import sys
from pprint import pprint
def solve(n, m, a, ops):
a.sort()
ops.sort(reverse=True)
# pprint(a)
# pprint(ops)
start = 0
for ope, count in ops:
for i, a_i in enumerate(a[start:start+count+1]):
if a_i < ope and count > 0:
count -= 1
... | import sys
from pprint import pprint
def solve(n, m, a, ops):
a.sort()
ops.sort(reverse=True)
# pprint(a)
# pprint(ops)
start = 0
for ope, count in ops:
i = 0
for a_i in range(start, start+count):
if a_i >= n:
break
if a[a_i]... | p03038 |
import heapq
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
heapq.heapify(a)
l = [[] for _ in range(m)]
for i in range(m):
b,c = list(map(int,input().split()))
l[i] = [c,b]
l.sort()
for i in range(m):
b,c = l[i][1],l[i][0]
for j in range(b):
x = hea... | import heapq
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
heapq.heapify(a)
l = [[] for _ in range(m)]
for i in range(m):
b,c = list(map(int,input().split()))
l[i] = [c,b]
l.sort(reverse=True)
for i in range(m):
b,c = l[i][1],l[i][0]
for j in range(b):
... | p03038 |
import heapq
n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for _ in range(m)]
heapq.heapify(a)
for i in range(m) :
B = b[i][0]
C = b[i][1]
for j in range(B) :
if a[0] < C :
heapq.heappop(a)
heapq... | n,m = list(map(int,input().split()))
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for _ in range(m)]
a.sort()
b = sorted(b,key = lambda x: x[1],reverse=True)
d = []
j = 0
while (n<=len(a) or j<m) :
C = b[j][1]
B = b[j][0]
for i in range(B) :
d.append(C)
... | p03038 |
from sys import stdin
import math
import itertools
def makeIntMatrix(lines):
intMatrix = []
for a in makeStringMatrix(lines):
intMatrix.append([int(b) for b in a])
return intMatrix
def makeStringMatrix(lines):
stringMatrix = [line.split() for line in lines]
return stringM... | # from sys import exit
N, M = [int(n) for n in input().split()]
# N = int(input())
a = [(int(n), 1) for n in input().split()]
B = [0 for _ in range(M)]
C = [0 for _ in range(M)]
for i in range(M):
B[i], C[i] = [int(n) for n in input().split()]
a.append((C[i], B[i]))
a = sorted(a, key=lambda x: -x[0])... | p03038 |
from heapq import heapify, heappop, heappush
from sys import stdin
N, M = list(map(int, input().split()))
A = list(map(int, stdin.readline().split()))
heapify(A)
BC = [None] * M
for i in range(M):
BC[i] = tuple(map(int, stdin.readline().split()))
BC = sorted(BC, key=lambda x: x[1])
for bc in BC:
f... | from heapq import heapify, heappop, heappush
from sys import stdin
N, M = list(map(int, input().split()))
A = list(map(int, stdin.readline().split()))
heapify(A)
BC = [None] * M
for i in range(M):
BC[i] = tuple(map(int, stdin.readline().split()))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
enough... | 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)#リバースと-1の違い
for b,c in BC:
A.extend([c]*b)
if len(A)>N**2:
break
A.sort(reverse=True)
print((sum(A[:N]))) | N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]#リストの表記が違う
BC.sort(key=lambda x: -x[1])#リバースと-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 |
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]))) | 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])#リバースと-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 |
import heapq
n, m = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []
for _ in range(m):
b, c = list(map(int, input().split()))
l.append((b, c))
for b, c in l:
for _ in range(b):
if a[0] < c:
heapq.heappushpop(a, c)
... | import heapq
n, m = list(map(int, input().split()))
a = sorted([int(i) for i in input().split()])
heapq.heapify(a)
l = []
for _ in range(m):
b, c = list(map(int, input().split()))
l.append((b, c))
l = sorted(l, key=lambda x: x[1], reverse=True)
for b, c in l:
if a[0] >= c:
break
... | p03038 |
N, M = list(map(int,input().split()))
a = list(map(int,input().split()))
check = []
for i in range(M):
check.append(list(map(int,input().split())))
check.sort(key=lambda x : x[1],reverse = True)
a.sort()
ans = []
for b, c in check:
ans += [c for i in range(b)]
if len(ans) <= N:
ans+=[0 for i in r... | N, M = list(map(int,input().split()))
a = list(map(int,input().split()))
check = []
for i in range(M):
check.append(list(map(int,input().split())))
check.sort(key=lambda x : x[1],reverse = True)
a.sort()
ans = []
for b, c in check:
ans += [c for i in range(b)]
if len(ans) > N:
break
else... | 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()))
for j in range(B):
A.append(C)
A.sort(reverse=True)
sum=0
for i in range(N):
sum+=A[i]
print(sum) | N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort(reverse=True)
D=[]
for i in range(M):
(B,C)=list(map(int,input().split()))
D.append((C,B))
D.append((0,0))
D.sort(reverse=True)
i=0
j=0
count=0
sum=0
while count<N:
if A[i]>=D[j][0]:
sum+=A[i]
i+=1
... | p03038 |
import heapq
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
heapq.heapify(A)
for _ in range(M):
b,c=list(map(int,input().split()))
for _ in range(b):
a=heapq.heappop(A)
if c>a:
heapq.heappush(A,c)
else:
heapq.heappush(A,a)
break
print((sum(A)))
| N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
L=[(1,a) for a in A]
for _ in range(M):
b,c=list(map(int,input().split()))
L.append((b,c))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
if n+k>=N:
ans+=a*(N-k)
break
else:
ans+=a*n
k+=n
prin... | p03038 |
N,M=list(map(int,input().split()))
L=list([(1,int(x)) for x in input().split()])
for _ in range(M):
L.append(tuple(map(int,input().split())))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
if n+k>=N:
ans+=a*(N-k)
break
else:
ans+=a*n
k+=n
print(ans) | N,M=list(map(int,input().split()))
L=sorted(list([(1,int(x)) for x in input().split()])
+[tuple(map(int,input().split())) for _ in range(M)]
,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
if n+k>=N:
ans+=a*(N-k)
break
else:
ans+=a*n
k+=n
print(ans) | p03038 |
N,M=list(map(int,input().split()))
L=sorted(list([(1,int(x)) for x in input().split()])
+[tuple(map(int,input().split())) for _ in range(M)]
,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
if n+k>=N:
ans+=a*(N-k)
break
else:
ans+=a*n
k+=n
print(ans) | import sys
N,M=list(map(int,sys.stdin.readline().split()))
L=sorted(list([(1,int(x)) for x in sys.stdin.readline().split()])
+[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
if n+k>=N:
ans+=a*(N-k)
break
... | p03038 |
import bisect
card_count, rewrite_count = list(map(int, input().split(" ")))
cards = list(map(int, input().split(" ")))
cards.sort()
for _ in range(rewrite_count):
stock_count, rewrite_number = list(map(int, input().split(" ")))
insert_point = bisect.bisect_left(cards, rewrite_number)
cards =... | import bisect
card_count, rewrite_count = list(map(int, input().split(" ")))
cards = {}
for card in list(map(int, input().split(" "))):
count = cards.get(card, 0)
cards[card] = count + 1
for _ in range(rewrite_count):
stock_count, rewrite_number = list(map(int, input().split(" ")))
count =... | p03038 |
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
X.sort(key=lambda x: x[1], reverse=True)
a.sort()
for b, c in X:
cnt = 0
for i in range(N):
if a[i] < c and cnt < b:
a[i] = c
cnt += 1
print((sum(a))) | N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
X = [list(map(int, input().split())) for _ in range(M)]
X.sort(key=lambda x: x[1], reverse=True)
num_cnt = [x[0] for x in X]
val_cnt = [x[1] for x in X]
idx = 0
cnt = 0
ans = 0
cum = 0
for i in range(min(N, sum(num_cnt)))... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
d = []
for _ in range(M):
b, c = list(map(int, input().split()))
d += [c] * b
ans = []
i_a = 0
i_d = 0
MAX_D = len(d)
A.sort(reverse=True)
d.sort(reverse=True)
while len(ans) < N:
if i_d < MAX_D and A[i_a] < d[i_d]... | 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()
idx = 0
for b, c in sorted(X, key=lambda x: -x[1]):
for j in range(idx, min(N, idx + b)):
if A[j] < c:
A[j] = c
idx += b
print((sum(A)))
... | p03038 |
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
N,M = list(map(int,input().split()))
A = [int(i) for i in input().split()]
change = [0 for i in range(... | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
N,M = list(map(int,input().split()))
A = [int(i) for i in input().split()]
change = [0 for i in range(... | p03038 |
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
N,M = list(map(int,input().split()))
A = [int(i) for i in input().split()]
change = [0 for i in range(... | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
N,M = list(map(int,input().split()))
A = [int(i) for i in input().split()]
change = [0 for i in range(... | 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)
import bisect
from collections import deque
D = sorted(D,reverse=True)
A = sorted(A)
A.extend(D[:N])
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)]
for i in range(M):
BC[i] = list(map(int, input().split()))
BC.sort(key=lambda x: x[1], reverse=True)
for i in BC:
A.extend([i[1]]*i[0])
if len(A) > 2*N:
break
A = sorted(A,reverse=True)
... | p03038 |
N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [tuple(map(int, input().split())) for _ in range(M)]
lst_A.sort()
lst_BC.sort(key=lambda x:x[1], reverse=True)
lst_D = []
add_num = N
for tpl in lst_BC:
b, c = tpl[0], tpl[1]
if add_num >= b:
lst_D ... | N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [list(map(int, input().split())) for _ in range(M)]
lst_A.sort()
lst_BC.sort(key=lambda x:-x[1])
lst_D = []
add_num = N
for b, c in lst_BC:
lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(ls... | p03038 |
N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [list(map(int, input().split())) for _ in range(M)]
lst_A.sort()
# lst_BC.sort(key=lambda x:-x[1])
lst_BC.sort(key=lambda x:x[1], reverse=True)
# print(lst_A)
# print(lst_BC)
lst_D = []
for b, c in lst_BC:
lst_... | N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [tuple(map(int, input().split())) for _ in range(M)]
lst_A.sort()
lst_BC.sort(key=lambda x:x[1], reverse=True)
lst_D = []
for b, c in lst_BC:
lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(l... | p03038 |
from heapq import heapify, heappush, heappop
N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
hq = []
heapify(hq)
for a in lst_A:
heappush(hq, [-a, 1])
for _ in range(M):
b, c = list(map(int, input().split()))
heappush(hq, [-c, b])
ans = 0
while N > 0:
... | from heapq import heapify, heappush, heappop
N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
hq = []
# heapify(hq)
for a in lst_A:
heappush(hq, [-a, 1])
for _ in range(M):
b, c = list(map(int, input().split()))
heappush(hq, [-c, b])
ans = 0
while N > 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 += [C]*B
E = sorted(A + D, reverse=True)
print((sum(E[0:N]))) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
D = []
E = []
for i in range(M):
B, C = list(map(int, input().split()))
D.append([C, B])
D = sorted(D, reverse = True)
for j in range(len(D)):
E += [D[j][0]]*D[j][1]
if len(E) >= N:
break
F = sorted(A + E,... | p03038 |
from collections import Counter
n,m=list(map(int,input().split()))
d=Counter(list(map(int,input().split())))
for i in range(m):
b,c=list(map(int,input().split()))
if c in d:
d[c]+=b
else:
d[c]=b
d=sorted(list(Counter(d).items()),reverse=True)
check=n
ans=0
for i in d:
if i[1... | from collections import Counter
n,m=list(map(int,input().split()))
d=Counter(list(map(int,input().split())))
for i in range(m):
b,c=list(map(int,input().split()))
if c in list(d.keys()):
d[c]+=b
else:
d[c]=b
d=sorted(list(d.items()),reverse=True)
check=n
ans=0
for i in d:
if... | p03038 |
from collections import Counter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
X = Counter(A)
for i in range(M):
B, C = list(map(int, input().split()))
X[C] += B
Z = []
for key, value in list(X.items()):
Z.append((key, value))
Z.sort(key=lambda x: x[0], reverse=Tr... | N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
query = []
for i in range(M):
b, c = list(map(int, input().split()))
query.append([b, c])
query.sort(key=lambda q: q[1], reverse=True)
i = 0
for b, c in query:
while i < N and b > 0:
if A[i] < c:
... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC0 = [list(map(int, input().split())) for _ in range(M)]
A.sort(reverse=True)
BC0.sort(key = lambda x:x[1], reverse=True)
BC = []
for m in range(M):
BC += [BC0[m][1]] * BC0[m][0]
summation = 0
for n in range(N):
if l... | N, M = list(map(int, input().split()))
A0 = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A = [[1,a] for a in A0]
ABC = A + BC
ABC.sort(key=lambda x:x[1], reverse=True)
summation = 0
p = 0
n = 0
while n<N:
summation += ABC[p][1] * (min(ABC[p][0], N-n))
... | p03038 |
import sys
input=sys.stdin.readline
import bisect
def main():
_,M= list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
B = []
for _ in range(M):
b,c = list(map(int,input().split()))
B.append((b,c))
B.sort(key=lambda x: x[1])
x = 0
... | import sys
input=sys.stdin.readline
import bisect
def main():
_,M= list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort()
B = []
for _ in range(M):
b,c = list(map(int,input().split()))
B.append((b,c))
B.sort(key=lambda x: x[1])
x = 0
... | p03038 |
# ABC127D - Integer Cards
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip().split()))
num = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
for i in lst:
num += [i[1]] * i[0]
print((sum(sorted(num, reverse=True)[:n]))) | # ABC127D - Integer Cards
import sys
input = sys.stdin.readline
n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
idx = 0
flg = False
for i,... | p03038 |
from bisect import bisect_left
n, m = list(map(int, input().split()))
alist = list(sorted(map(int, input().split())))
for _ in range(m):
b, c = list(map(int, input().split()))
i = bisect_left(alist, c)
if i + 1 > b:
alist = alist[b:] + [c]*b
else:
alist = alist[i:] + [c]*i
alist.sort()
... | n, m = list(map(int, input().split()))
alist = list(sorted(map(int, input().split())))
bc = []
total = 0
for _ in range(m):
bc.append(tuple(map(int, input().split())))
lim = n-1
total = 0
ans = 0
for b, c in sorted(bc, key=lambda x: -x[1]):
while lim >= 0 and alist[lim] >= c:
ans += alist[lim]
... | p03038 |
import heapq
def main():
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
heapq.heapify(A)
BC=[]
for i in range(M):
bc=list(map(int,input().split()))
BC.append(bc)
BC.sort(reverse=True,key=lambda x:x[1])
new_BC=[]
count=0
for i in rang... | def main():
N,M=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
BC=[]
for i in range(M):
bc=list(map(int,input().split()))
BC.append(bc)
BC.sort(reverse=True,key=lambda x:x[1])
new_BC=[]
count=0
for i in range(M):
for j i... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
rewritelist = []
for i in range(0, M):
rewritelist.append(list(map(int, input().split())))
A.sort()
rewritelist.sort(key = lambda val: val[1], reverse = True)
cardlist = []
for i in range(0, N):
if rewritelist == []: break
cardlist.... | def smaller(x, y):
if x < y: return x
return y
def larger(x, y):
if x > y: return x
return y
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
Asum = []
sum = 0
for i in range(0, N):
sum += A[i]
Asum.append(sum)
controllist = []
for i in range(0, M):
controllis... | 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)
def f():
s = sum(a)
i = 0
for v in bc:
b, c = list(map(int, v))
while b > 0:
if 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(key=lambda x: x[1], reverse=True)
d = []
for v in bc:
b, c = list(map(int, v))
d.extend([c] * b)
if len(d) >= len(a):
break
ans = sum(a)... | p03038 |
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush,heapify
from bisect import bisect_left
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
# print(A)
for i in range(M):
B, C = list(map(i... | #!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush,heapify
from bisect import bisect_left
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
q = []
for i in range(M):
B, C = list(map(int, ... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
#SA = sorted(A)
D = []
for _ in range(M):
B, C = list(map(int, input().split()))
D += B * [C]
A += D
SA = sorted(A, reverse=True)
#X = min(N, len(SD))
#SD = SD[:X]
print((sum(SA[:N])))
| N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
#SA = sorted(A)
D = []
for _ in range(M):
B, C = list(map(int, input().split()))
D.append([B, C])
SD = sorted(D, key=lambda x:x[1], reverse=True)
for b, c in SD:
A += b * [c]
if len(A) > N*2:
break
SA = sorted(A, ... | p03038 |
import bisect
n,m = list(map(int, input().split()))
A = sorted(map(int, input().split()))
for _ in range(m):
b,c = list(map(int, input().split()))
ind = bisect.bisect_left(A, c)
A = A[:ind]+[c]*b+A[ind:]
print((sum(A[-n:]))) | n,m = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1])
add = []
for b,c in BC:
add += [c]*b
if len(add)>n:
break
ans = sorted(A+add)
print((sum(ans[-n:]))) | p03038 |
from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=list(map(int,input().split()))
a=sorted(list(nii()))
l=[]
for i in range(m):
b,c=nii()
l+=[c]*b
l=sorted(l,reverse=True)
l_len=len(l)
if l_len<n:
l+=[0]*(n-l_len)
ans=0
for i in range(n):
ans+=max(a[i],l[i])
print(a... | from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))
n,m=list(map(int,input().split()))
a=sorted(list(nii()))
l=[list(nii()) for i in range(m)]
l=sorted(l,key=lambda x:x[1],reverse=True)
man=[]
num=0
for b,c in l:
man+=[c]*b
num+=b
if num>n:
break
ans=0
for i in range(n... | 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)]
b_sum=0
for b,c in l:
a+=[c]*b
b_sum+=b
a=sorted(a)[b_sum:]
print((sum(a))) | 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 |
from fractions import *
import sys
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
bc = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
bc = sorted(bc)
subar = a
for i in bc:
sc = [i[1]] * i[0]
suba = []
ra = subar[i[0]:]
... | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
pairs = [list(map(int, input().split())) for _ in range(m)]
pairs = sorted(pairs, key=lambda x: x[1])
cnt = 0
ans = 0
while cnt < n:
if pairs != [] and a[-1] < pairs[-1][1] and cnt+pairs[-1][0] <= n:
cnt += pair... | p03038 |
N,M = list(map(int,input().split()))
B = []
C = []
A = list(map(int,input().split()))
for j in range(1,M+1):
B_val,C_val = list(map(int,input().split()))
B.append(B_val)
C.append(C_val)
A.sort()
for k in range(0,M):
for l in range(0,B[k]):
if A[0] <= C[k]:
A[0] = C[k]
A.sort()
... | 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 = lambda x:-x[1])
flag = 0
flag_2 = 0
#print(a,bc)
for i in range(n):
if a[i] < bc[flag_2][1]:
a[i] = bc[flag_2][1]
else:
break
flag += 1
if flag... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
CB = [0]*(M)
for i in range(M):
b, c = list(map(int, input().split()))
CB[i] = (c, b)
A.sort()
CB = list(reversed(sorted(CB)))
ind = 0
for i in range(M):
(c, b) = CB[i]
for _ in range(b):
if ind >= N:
... | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
CB = [0]*(M)
for i in range(M):
b, c = list(map(int, input().split()))
CB[i] = (c, b)
A.sort()
CB = list(reversed(sorted(CB)))
ind = 0
for i in range(M):
(c, b) = CB[i]
for _ in range(b):
if ind >= N:
... | p03038 |
N, M = [int(s) for s in input().split(' ')]
As = [int(s) for s in input().split(' ')]
for m in range(M):
B, C = [int(s) for s in input().split(' ')]
As += [C] * B
As.sort()
print((sum(As[-N:])))
| N, M = [int(s) for s in input().split(' ')]
As = [int(s) for s in input().split(' ')]
CBs = []
for m in range(M):
B, C = [int(s) for s in input().split(' ')]
CBs.append((C, B))
As.sort(reverse=True)
CBs.sort(reverse=True)
CBs.append((0, 0))
ret = 0
a = 0
bc = 0
n = 0
while n < N:
C, B = CBs[bc... | p03038 |
#ABC127-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(eval(input()))
def S(): return list(eval(input()))
import bisect
n,m=IL()
A=IL()
A.sort()
for i in range(m):
b,c=IL()
s=bisect.bisect(A,c)
if s<=b:
A=[c]*s+A[s:]
e... | #ABC127-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(eval(input()))
def S(): return list(eval(input()))
n,m=IL()
A=IL()
A.sort()
Q=[IL() for i in range(m)]
Q.sort(key=lambda x:-x[1])
j=0
for i in range(n):
if Q[j][1]<A[i]:
break
els... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
numlist = []
for i in range(M):
B, C = list(map(int, input().split()))
numlist.append([C, B])
for i in range(N):
numlist.append([A[i], 1])
numlist.sort(reverse = True)
count = N
ans = 0
while count >= 0:
b, c = numlis... |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
num = dict()
for i in range(M):
B, C = list(map(int, input().split()))
if C in list(num.keys()):
num[C] += B
else:
num[C] = B
for i in range(N):
if A[i] in list(num.keys()):
num[A[i]] += 1
... | 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 for _ in range(b)])
A.sort(reverse = True)
print((sum(A[:n])))
| n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
C = []
for _ in range(m):
b,c = list(map(int,input().split()))
C.append((c,b))
C.sort(reverse = True)
count = 0
for c,b in C:
A.extend([c for _ in range(b)])
count += b
if count > n:
break
A.sort(reverse = True)
prin... | p03038 |
n,m = list(map(int,input().split()))
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
b,c = list(map(int,input().split()))
tmp_li.append((c,b))
tmp_li.sort(reverse=True)
#print(tmp_li)
count = 0
for t in tmp_li:
kazu = min(t[1],n-count+1)
li.extend([t[0]]*kazu)
if count... | n,m = list(map(int,input().split()))
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
b,c = list(map(int,input().split()))
tmp_li.append((c,b))
tmp_li.sort(reverse=True)
#print(tmp_li)
for c,b in tmp_li:
li.extend([c]*b)
if len(li)>= 2*n:
break
li.sort(reverse=True)... | p03038 |
n,m = list(map(int,input().split()))
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
b,c = list(map(int,input().split()))
tmp_li.append((c,b))
tmp_li.sort(reverse=True)
#print(tmp_li)
""" for c,b in tmp_li:
li.extend([c]*b)
if len(li)>= 2*n:
break
li.sort(reverse=T... | n,m = list(map(int,input().split()))
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
b,c = list(map(int,input().split()))
tmp_li.append([c,b])
tmp_li.sort(reverse=True)
#print(tmp_li)
count = 0
for t in tmp_li:
li += [t[0]]*t[1]
if len(li)>=2*n:
break
li.sort(reve... | p03038 |
# -*- coding: utf-8 -*-
# abc127/abc127_d
import sys
from operator import itemgetter
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda... | # -*- coding: utf-8 -*-
# abc127/abc127_d
import sys
from operator import itemgetter
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda... | p03038 |
if __name__ == '__main__':
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(m):
b, c = list(map(int, input().split()))
a += [c] * b
a.sort(reverse=True)
s = 0
for i in range(n):
s += a[i]
print(... |
if __name__ == '__main__':
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())))
bc.sort(key=lambda x: x[1], reverse=True)
a.sort()
bcn = 0
for i in range(n):
if(a[i]... | p03038 |
n,m= list(map(int,input().split()))
AA = list(map(int,input().split()))
A = [[AA[i],1] for i in range(n)]
for _ in range(m):
b,c = list(map(int,input().split()))
A += [[c,b]]
A.sort()
A.reverse()
rest = n
score = 0
while True:
C = A[0][0]
B = A[0][1]
score += B * C
rest -= B
del A[0]
if ... | n,m= list(map(int,input().split()))
AA = list(map(int,input().split()))
A = [(AA[i],1) for i in range(n)]
for _ in range(m):
b,c = list(map(int,input().split()))
A += [(c,b)]
A.sort()
A.reverse()
rest = n
score = 0
for (cc,bb) in A:
use = min(bb,rest)
rest -= use
score += use*cc
print(score) | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
p = [[aa,1] for aa in a]
for _ in range(m):
b = list(map(int,input().split()))
b.reverse()
p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for pp in p:
use = min(pp[1],rest)
rest -= use
score += pp[0] * use
if rest=... | n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
p = [[aa,1] for aa in a]
for _ in range(m):
b = list(map(int,input().split()))
b.reverse()
p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for ni in range(n):
use = min(p[ni][1],rest)
rest -= use
score += p[ni][0] * us... | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
p = [[aa,1] for aa in a]
for _ in range(m):
b = list(map(int,input().split()))
b.reverse()
p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for ni in range(n):
use = min(p[0][1],rest)
rest -= use
score += p[0][0] * use
... | #20:58
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(m):
now = list(map(int,input().split()))
now.reverse()
b.append(now)
b.sort()
b.reverse()
c = []
for i in range(m):
c += [b[i][0]] * b[i][1]
if len(c) > n:
c = c[:n]
break
if ... | p03038 |
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
d = []
for _ in range(m):
b,c = list(map(int,input().split()))
d.append([c,b])
d.sort(reverse = True)
e = []
f = 0
for j in range(m):
for k in range(d[j][1]):
e.append(d[j][0])
f += 1
if f == n:
break... | #15:40
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
bc = []
for _ in range(m):
bc.append(list(map(int,input().split())))
bc.sort(key=lambda x: -x[1])
d = []
dl = 0
for x in bc:
b,c = x
d += [c] * b
dl += b
if dl >= n:
break
if dl < n:
d += [0] * (n-dl... | p03038 |
from collections import Counter
n, m = list(map(int, input().split()))
a = Counter(list(map(int, input().split())))
for i in range(m):
b, c = list(map(int, input().split()))
for value in sorted(list(a.keys())):
if value >= c:
break
if a[value] > 0:
if a[value... | n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
cb = []
for i in range(m):
b, c = list(map(int, input().split()))
cb.append([c, b])
cb.sort(reverse=True)
now = 0
for i in range(n):
if a[i] < cb[now][0] and cb[now][1] > 0:
a[i] = cb[now][0]
cb[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.sort(key=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
newcard.extend([c]*b)
if(len(newcard)>=n):
break
size = min(... | import sys
input = sys.stdin.readline
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=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
newcard.extend([c]*b)
if(len(new... | p03038 |
import sys
input = sys.stdin.readline
from operator import itemgetter
def solve():
from operator import itemgetter
turns = tuple(map(int, input().split()))[1]
cardsList = list(map(int, input().split()))
turnsList = [tuple(map(int, input().split())) for _ in range(turns)]
for ch... | import sys
input = sys.stdin.readline
from operator import itemgetter
def solve():
cardsNum, turnsNum = tuple(map(int, input().split()))
cards = sorted([int(x) for x in input().split()])
turns = sorted([tuple(int(x) for x in input().split()) for _ in range(turnsNum)], key=itemgetter(1), reverse=True... | p03038 |
import heapq
def sol():
n,m=list(map(int,input().split()))
a=[int(i) for i in input().split()]
d={}
w=[]
q=[]
for i in a:
if i in d:
d[i]+=1
else:
d[i]=1
w.append(i)
for i in w: heapq.heappush(q, i)
for i in range(m):
... | import heapq
n,m=list(map(int,input().split()))
a=[int(i) for i in input().split()]
d={}
w=[]
q=[]
for i in a:
if i in d:
d[i]+=1
else:
d[i]=1
w.append(i)
for i in w: heapq.heappush(q, i)
for i in range(m):
b,c=list(map(int,input().split()))
while b:
if c>... | 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()))
index = bisect.bisect_left(A,C)
if index > B:
A[:B] = [C] * B
else:
A[0:index] = [C] * index
A.sort()
print((sum... | N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
A.sort()
B.sort(reverse = True, key = lambda x: x[1])
cot = 0
add = 0
for b,c in B:
cot += b
if cot > N:
add = N - cot + b
A.extend([c] * add)
... | p03038 |
import heapq
import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
for i in range(M):
B, C = list(map(int, input().split()))
for j in range(B):
s = min(A)
if s <... | import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
for _ in range(M):
BC.append(tuple(map(int, input().split())))
BC.sort(key=lambda x: x[1])
vs = []; jtmp = 0
for i in range(M):
... | p03038 |
def main():
from collections import Counter
n, m, *abc = list(map(int, open(0).read().split()))
a = Counter(abc[:n])
bc = abc[n:]
for i, j in zip(*[iter(bc)] * 2):
a[j] += i
cnt = n
ans = 0
keys = list(a.keys())
keys.sort(reverse=True)
for k in keys:
... | def main():
from collections import Counter
n, m, *abc = list(map(int, open(0).read().split()))
a = Counter(abc[:n])
bc = abc[n:]
for i, j in zip(*[iter(bc)] * 2):
a[j] += i
cnt = n
ans = 0
keys = sorted(list(a.keys()), reverse=True)
for k in keys:
... | p03038 |
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = [int(v) for v in input().split()]
LR = [list(map(int, input().split())) for _ in range(M)]
heap = []
for v in A:
heappush(heap, (v * -1, 1))
for c, p in LR:
heappush(heap, (p * -1... | import sys
from heapq import heappush, heappop
input = sys.stdin.readline
N, M = list(map(int, input().split()))
L = [int(v) for v in input().split()]
LL = [[int(v) for v in input().split()] for _ in range(M)]
heap = []
for a in L:
heappush(heap, (-a, 1))
for a in LL:
heappush(heap, (-a[1], a[0]... | p03038 |
import sys
f=lambda:list(map(int,sys.stdin.readline().split()))
n,m=f()
l=sorted(f())
s=[]
t=0
for i in range(m):
b,c=f()
s+=[c]*b
t+=b
s.sort(reverse=1)
a=0
for i in range(n):
if i<t: a+=max(l[i],s[i])
else: a+=l[i]
print(a) | import sys
f=lambda:list(map(int,sys.stdin.readline().split()))
n,m=f()
la=sorted(f())
ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1])
ls=[]
t=0
for b,c in ll:
if t+b>n:
ls+=[c]*(n-t)
t=n
break
ls+=[c]*b
t+=b
ls.sort(reverse=1)
a=0
for i in range(n):
if i<t: a+=max(la[i]... | p03038 |
import sys
f=lambda:list(map(int,sys.stdin.readline().split()))
n,m=f()
la=sorted(f())
ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1])
ls=[]
t=a=0
for b,c in ll:
if t+b>n: ls+=[c]*(n-t); t=n; break
ls+=[c]*b; t+=b
for i in range(n):
if i<t: a+=max(la[i],ls[i])
else: a+=la[i]
print(a) | import sys
f=lambda:list(map(int,sys.stdin.readline().split()))
n,m=f();l=f();t=n
for b,c in sorted([f() for _ in range(m)],key=lambda k:-k[1]):
l+=[c]*b;t+=b
if t>n*2:break
l.sort()
print((sum(l[-n:]))) | 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])))
| import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
for _ in range(m):
b, c = list(map(int, input().split()))
for _ in range(b):
tmp = heapq.heappop(a)
if tmp >= c:
heapq.heappush(a, tmp)
break
else... | p03038 |
import heapq
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
for _ in range(m):
b, c = list(map(int, input().split()))
for _ in range(b):
tmp = heapq.heappop(a)
if tmp >= c:
heapq.heappush(a, tmp)
break
else... | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
d = {}
for a in A:
d[a] = 1 if a not in d else d[a] + 1
for _ in range(m):
b, c = list(map(int, input().split()))
d[c] = b if c not in d else d[c] + b
ans = 0
cnt = 0
L = sorted(d, reverse=True)
for k in L:
if d[k] + ... | p03038 |
import bisect
n, m = list(map(int, input().split()))
a_array = sorted([int(x) for x in input().split()])
bc_array = sorted([[int(x) for x in input().split()] for x in range(m)], key=lambda x: x[1], reverse=True)
candidate_replace_cnt = n
replace_sum = 0
replace_cnt = 0
for b, c in bc_array:
if a_array[0... | import bisect
n, m = list(map(int, input().split()))
a_array = sorted([int(x) for x in input().split()])
bc_array = sorted([[int(x) for x in input().split()] for x in range(m)], key=lambda x: x[1], reverse=True)
# 何枚入れ替えられるか
candidate_replace_cnt = n
for b, c in bc_array:
if a_array[0] >= c or candidate_... | p03038 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
P = [(A[i], 1) for i in range(N)]
for j in range(M):
B, C = list(map(int, input().split()))
P.append((C, B))
P.sort(reverse=True)
ans, cnt = 0, N
for v, c in P:
use = min(c, cnt)
ans += use*v
cnt -= use
print(ans) | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
CB = [list(map(int, input().split()))[::-1] for _ in range(M)]
CB.sort()
C, B = list(map(list, list(zip(*CB))))
b = B.pop()
c = C.pop()
ans = []
for a in A:
if a < c:
ans.append(c)
b -= 1
else:
... | p03038 |
N, M = list(map(int, input().split()))
from bisect import bisect_right
inf = float("inf")
A = sorted(list(map(int, input().split())))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: -x[1])
cnt = 0
L, R = 0, N
I = []
for b, c in BC:
idx = bisect_right(A[L:R], c)
if id... | N, M = list(map(int, input().split()))
from bisect import bisect_right
inf = float("inf")
A = sorted(list(map(int, input().split())))
BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: -x[1])
cnt = 0
L, R = 0, N
I = []
for b, c in BC:
idx = bisect_right(A, c, lo=L, hi=R)
... | p03038 |
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
sum=0
for i in range(n):
sum+=a[i]
for i in range(m):
b=list(map(int,input().split()))
for i in range(b[0]):
if a[i]<=b[1]:
sum=sum-a[i]+b[1]
a[i]=b[1]
a.sort()
print(sum) | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
b=[]
sum=0
for i in range(m):
b.append(list(map(int,input().split())))
b.sort(key=lambda x: x[1])
B=len(b)
b1=b[B-1][0]
b2=b[B-1][1]
b3=0
for i in range(n):
if a[i]<b2 and b3==0:
sum+=b2
b1-=1
else:
... | p03038 |
import heapq
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
min_num = a[0]
tmp_array = []
for i in range(m):
b,c = list(map(int, input().split()))
tmp_array.append([b,c])
sort_array = sorted(tmp_array, key=lambda x: x[1])
for i in range(m):
b = so... | import heapq
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
heapq.heapify(a)
min_num = a[0]
tmp_array = []
for i in range(m):
b,c = list(map(int, input().split()))
tmp_array.append([b,c])
sort_array = sorted(tmp_array, key=lambda x: -x[1])
for i in range(m):
b = s... | p03038 |
N, M = list(map(int,input().split()))
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]
List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
for i in range(M):
for j in range(List_BC[i][0]):
if List_BC[i][1] > List_A[0]:
... | N, M = list(map(int,input().split()))
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]
List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0
for i in range(M):
for j in range(List_BC[i][0]):
if k >= N:
flag = ... | p03038 |
import heapq
n, m = list(map(int, input().split()))
A_list = list(map(int, input().split()))
B_list = [0]*m
C_list = [0]*m
for i in range(m):
b, c = list(map(int, input().split()))
B_list[i] = b
C_list[i] = c
heap = []
ans = 0
for a in A_list:
heapq.heappush(heap, a)
for i in range(m):
... | n, m = list(map(int, input().split()))
A_list = list(map(int, input().split()))
BC_list = []
for _ in range(m):
BC_list.append(list(map(int, input().split())))
A_list.sort()
BC_list.sort(key=lambda x: x[1], reverse=True)
C_list = []
for i in range(m):
for _ in range(BC_list[i][0]):
if len(C_li... | p03038 |
import heapq
n, m = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]
aa_lst = a_lst[:]
heapq.heapify(aa_lst)
for bc in bc_lst:
for i in range(bc[0]):
if aa_lst[0] < bc[1]:
heapq.heapreplace(aa_lst, b... | import heapq
n, m = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]
bc_lst = sorted(bc_lst, key = lambda x: -x[1])
aa_lst = a_lst[:]
heapq.heapify(aa_lst)
for bc in bc_lst:
for i in range(bc[0]):
if aa_lst[0] <... | p03038 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.