Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N,M=map(int, input().split() )
A=list(map(int, input().split() ))
B=[0]*M
C=[0]*M
pos=A
for i in range(M):
  B[i],C[i]=map(int, input().split() )
  pos += B[i]*[C[i]]
  
pos.sort(reverse=True)
print(sum(pos[:N]))

Fixed submission:
from collections import Counter

N,M = map(int, input().split() )
A   = list(map(int, input().split() ))
B   = [0]*M
C   = [0]*M
Cou = Counter(A)

for i in range(M):
  B[i],C[i]  = map(int, input().split() )
  Cou[C[i]] += B[i]
  
#print(Cou)  
ans=0
cnt=0
S=sorted(Cou,reverse=True)
#print(S)
for num in S:
  kosuu = min(Cou[num],N-cnt)
  cnt += kosuu
  ans += num*kosuu
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N,M=map(int, input().split() )
A=list(map(int, input().split() ))
B=[0]*M
C=[0]*M
for i in range(M):
  B[i],C[i]=map(int, input().split() )

pos=A
for i in range(M):
  pos += B[i]*[C[i]]
  
pos.sort(reverse=True)
print(sum(pos[:N]))

Fixed submission:
from collections import Counter

N,M = map(int, input().split() )
A   = list(map(int, input().split() ))
B   = [0]*M
C   = [0]*M
Cou = Counter(A)

for i in range(M):
  B[i],C[i]  = map(int, input().split() )
  Cou[C[i]] += B[i]
  
#print(Cou)  
ans=0
cnt=0
S=sorted(Cou,reverse=True)
#print(S)
for num in S:
  kosuu = min(Cou[num],N-cnt)
  cnt += kosuu
  ans += num*kosuu
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N,M=map(int, input().split() )
A=list(map(int, input().split() ))
B=[0]*M
C=[0]*M
for i in range(M):
  B[i],C[i]=map(int, input().split() )
A.sort()
summ=sum(A)

for i in range(M):
  p=bisect.bisect_left(A,C[i])
  q=min(p,B[i])
  A= [C[i]]*q+ A[q:]
  A.sort()
  
print(sum(A))

Fixed submission:
from collections import Counter

N,M = map(int, input().split() )
A   = list(map(int, input().split() ))
B   = [0]*M
C   = [0]*M
Cou = Counter(A)

for i in range(M):
  B[i],C[i]  = map(int, input().split() )
  Cou[C[i]] += B[i]
  
#print(Cou)  
ans=0
cnt=0
S=sorted(Cou,reverse=True)
#print(S)
for num in S:
  kosuu = min(Cou[num],N-cnt)
  cnt += kosuu
  ans += num*kosuu
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split() )
A=list(map(int, input().split() ))
B=[0]*M
C=[0]*M
for i in range(M):
  B[i],C[i]=map(int, input().split() )
A.sort()
summ=sum(A)

for i in range(M):
  cnt=0
  for j,num in enumerate(A):
    if num<=C[i]:
      A[j]=C[i]
      cnt += 1
      if cnt==B[i]:
        break
  A.sort()
  
print(sum(A))
  
  

Fixed submission:
from collections import Counter

N,M = map(int, input().split() )
A   = list(map(int, input().split() ))
B   = [0]*M
C   = [0]*M
Cou = Counter(A)

for i in range(M):
  B[i],C[i]  = map(int, input().split() )
  Cou[C[i]] += B[i]
  
#print(Cou)  
ans=0
cnt=0
S=sorted(Cou,reverse=True)
#print(S)
for num in S:
  kosuu = min(Cou[num],N-cnt)
  cnt += kosuu
  ans += num*kosuu
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split() )
A=list(map(int, input().split() ))

B=[]
C=[]
ans_list=[]
ans=0

for i in range(M):
  b,c=map(int, input().split() )
  B.append(b)
  C.append(c)

while B:
  max_index=C.index(max(C))
  max_value=B[max_index]

  for i in range(max_value):
    ans_list.append(max(C))

  B.pop(max_index)
  C.pop(max_index)

new_list=A+ans_list
new_list.sort(reverse=True)

for i in range(N):
  ans+=new_list[i]

print(ans)	

Fixed submission:
from collections import Counter

N,M = map(int, input().split() )
A   = list(map(int, input().split() ))
B   = [0]*M
C   = [0]*M
Cou = Counter(A)

for i in range(M):
  B[i],C[i]  = map(int, input().split() )
  Cou[C[i]] += B[i]
  
#print(Cou)  
ans=0
cnt=0
S=sorted(Cou,reverse=True)
#print(S)
for num in S:
  kosuu = min(Cou[num],N-cnt)
  cnt += kosuu
  ans += num*kosuu
  
print(ans)