Buggy python submission (verdict: Time Limit Exceeded):
import collections

N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
A_dict = collections.Counter(A)

for i in range(M):
  B,C = map(int, input().split())
  if C in A_dict:
    A_dict[C] += B
  else:
    A_dict[C] = B

ans = 0
for i in range(N):
  max_A_dict = max(A_dict)
  ans += max_A_dict
  if A_dict[max_A_dict] == 1:
    A_dict.pop(max_A_dict)
  else:
    A_dict[max_A_dict] -=1

print(ans)

Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

A.sort()

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)
      A.pop(A.index(min(A)))

ans = sum(A)

print(ans)


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    for i in range(B):
      if min_A >= C:
        break
      else:
        count+=1
        A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)

for B,C in BC:
  if min(A) >= C and count > N:
    break
  else:
    for i in range(B):
      if min(A) >= C:
        break
      else:
        count+=1
        A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
A.sort()

for B,C in BC:
  if min(A) >= C:
    break
  else:
    for i in range(B):
      if min(A) >= C:
        break
      else:
        A.append(C)
        A.pop(0)

ans = sum(A)

print(ans)


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

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

N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
count = 0

for i in range(M):
  B, C = map(int, input().split())
  count = count + B
  for j in range(B):
    A.append(C)

A = np.array(A)
A = np.sort(A)
ans = A[count : len(A)+1]

print(np.sum(ans))


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]

count = 0

for i in range(M):
  B, C = map(int, input().split())
  count = count + B
  for j in range(B):
    A.append(C)

A.sort()
ans = A[count : len(A)+1]

print(sum(ans))

Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

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

N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]

B = [0] * M
C = [0] * M

for i in range(M):
    B[i], C[i] = map(int, input().split())
np_A = np.array(A)

for i in range(M):
  if np.min(np_A) <= C[i]:
    for j in range(B[i]):
      A_min_index_np = np.argmin(np_A)
      np_A[A_min_index_np] = C[i]

print(np.sum(np_A))


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]

B = [0] * M
C = [0] * M

for i in range(M):
    B_tmp, C_tmp = map(int, input().split())
    B[i] = B_tmp
    C[i] = C_tmp

for i in range(M):
  if min(A) <= C[i]:
    for j in range(B[i]):
      A_min_index = A.index(min(A))
      A[A_min_index] = C[i]

print(sum(A))


Fixed submission:
N, M= (int(i) for i in input().split())
A = [int(i) for i in input().split()]
BC = [list(map(int, input().split())) for _ in range(M)]
count = 0

BC = sorted(BC, key=lambda x: x[1],reverse=True)
min_A = min(A)

for B,C in BC:
  if min_A >= C and count > N:
    break
  else:
    l = min(B, N-count)
    for i in range(l):
      count+=1
      A.append(C)

A.sort()

ans = sum(A[count:len(A)])

print(ans)