Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
D = []
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  D.extend([C]*B)
A.sort()
D.sort(reverse=True)
result = 0
for i in range(min(len(A),len(D))):
  if D[i]-A[i]<=0:
    break
  result+=1
print(sum(D[:result])+sum(A[result:]))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count=>len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count=>len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count=>len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = {}
result_m = 0
for m in range(M):
  B, C = map(int, input().split())
  if BC.get(C) != None:
    BC[C] += B
  else:
    BC[C] = B
A.sort()
BC = sorted(BC.items(), reverse=True)
count = 0
for m in range(len(BC)):
  if count>=len(A):
    break
  if A[count]>BC[m][0]:
    break
  for i in range(BC[m][1]):
    if count>=len(A):
      break
    if BC[m][0] > A[count]:
      A[count] = BC[m][0]
      count+=1
print(sum(A))