Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
for b,c in B:A+=[c]*b
print(sum(sorted(A)[-n:]))

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
  b,c=map(int,input().split())
  d=bisect.bisect_right(A,c)
  b=min(b,d)
  A=A[b:d]+[c]*b+A[d:]
print(sum(A))

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
  b,c=map(int,input().split())
  d=bisect.bisect_right(A,c)
  b=min(b,d)
  A=A[b:d]+[c]*b+A[d:]
print(sum(A))

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))

Buggy python submission (verdict: Time Limit Exceeded):
#ABC127 D
from operator import itemgetter as ig
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
    B[i], C[i] = map(int, input().split()) 
BC = sorted([(B[i], C[i])for i in range(M)], key = ig(1), reverse=True)
s = 0
k = 0
while(s <= N and k < M):
    D = [BC[k][1] for i in range(BC[k][0])]
    A = A + D
    s += BC[k][0]
    k += 1
print(sum(sorted(A, reverse=True)[:N]))

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))

Buggy python submission (verdict: Time Limit Exceeded):
#ABC127 D
from operator import itemgetter as ig
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(M)]
C = [0 for i in range(M)]
for i in range(M):
    B[i], C[i] = map(int, input().split()) 
BC = sorted([(B[i], C[i])for i in range(M)], key = ig(1), reverse=True)
s = 0
k = 0
while(s <= N and k < M):
    D = [BC[k][1] for i in range(BC[k][0])]
    A = A + D
    s += BC[k][0]
    k += 1
print(sum(sorted(A, reverse=True)[:N]))

Fixed submission:
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[list(map(int,input().split())) for _ in range(m)]
B.sort(key=itemgetter(1),reverse=True)
C=[]
for b,c in B:
  C+=[c]*b
  if len(C)>=n:break
print(sum(sorted(A+C)[-n:]))