Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
cards = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    cards += ([c] * b)
    cards = sorted(cards, reverse=True)[:n]

print(sum(cards))

Fixed submission:
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
cards = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    cards += ([c] * b)

cards.sort(reverse=True)

print(sum(cards[:n]))

Fixed submission:
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
cards = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        cards.append(c)

cards.sort(reverse=True)

print(sum(cards[:n]))

Fixed submission:
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n, m = map(int, input().split())

cards = list(map(int, input().split()))
cards.sort()

ans = 0
for i in range(m):
    b, c = map(int, input().split())
    cnt = bisect_left(cards,c)
    cards[:min(cnt,b)] = [c] * min(cnt,b)
    cards.sort()
    ans = max(ans, sum(cards))

print(ans)

Fixed submission:
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

cards = list(map(int, input().split()))
cards.sort()

ans = 0
for i in range(m):
    b, c = map(int, input().split())
    cnt = 0
    while cnt < b:
        if cards[cnt] >= c:
            break
        cards[cnt] = c
        cnt += 1
    cards.sort()
    total = sum(cards)
    ans = max(ans, total)

print(ans)

Fixed submission:
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))