Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = map(int, input().split())

A_list = list(map(int, input().split()))

R_list = []
B_list = []
C_list = []
for _ in range(M):
  B, C = map(int, input().split())
  B_list.append(B)
  C_list.append(C)

BC_list = [(B,C) for B, C in zip(B_list, C_list)]
BC_list.sort(key=lambda x: x[1])
BC_list = [[C]*B for B, C in BC_list]

R_list = sum(BC_list, [])

R_list = np.array(R_list)
R_list = R_list[::-1]
R_list = R_list[:N]

A_list = np.array(A_list)
A_list = np.sort(A_list)

short_len = N - len(R_list)

if short_len > 0:
  R_list = np.append(R_list, [0]*short_len)

print(np.sum(np.maximum(A_list,R_list)))


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))
 
BC.sort(key = itemgetter(1),reverse=True)
 
BC.append((N,-1))
 
change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
 
A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = map(int, input().split())

A_list = list(map(int, input().split()))

R_list = []

for _ in range(M):
  B, C = map(int, input().split())
  BC_list = [C]*B
  R_list.extend(BC_list)

R_list = np.array(R_list)
R_list = np.sort(R_list)
R_list = R_list[::-1]
R_list = R_list[:N]

A_list = np.array(A_list)
A_list = np.sort(A_list)

short_len = N - len(R_list)

if short_len > 0:
  R_list = np.append(R_list, [0]*short_len)

print(np.sum(np.maximum(A_list,R_list)))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))
 
BC.sort(key = itemgetter(1),reverse=True)
 
BC.append((N,-1))
 
change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
 
A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, M = map(int, input().split())

A_list = list(map(int, input().split()))

R_list = []

for _ in range(M):
  B, C = map(int, input().split())
  BC_list = [C]*B
  R_list.extend(BC_list)

R_list = np.array(R_list)
R_list = np.sort(R_list)
R_list = R_list[::-1]
R_list = R_list[:N]

A_list = np.array(A_list)
A_list = np.sort(A_list)

short_len = N - len(R_list)

if short_len > 0:
  R_list = np.append(R_list, [0]*short_len)

print(np.sum(np.maximum(A_list,R_list)))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))
 
BC.sort(key = itemgetter(1),reverse=True)
 
BC.append((N,-1))
 
change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
 
A += change
A.sort()
answer = sum(A[-N:])
print(answer)