Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if List_BC[i][1] >= List_A[k] and k < N:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Fixed submission:
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if k >= N:
            flag = 1
            break
        elif List_BC[i][1] > List_A[k]:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if List_BC[i][1] > List_A[k] and k < N:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Fixed submission:
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if k >= N:
            flag = 1
            break
        elif List_BC[i][1] > List_A[k]:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if List_BC[i][1] > List_A[k]:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Fixed submission:
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if k >= N:
            flag = 1
            break
        elif List_BC[i][1] > List_A[k]:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if List_BC[i][1] > List_A[0]:
            List_A[0] = List_BC[i][1]
            List_A.sort()
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))

Fixed submission:
N, M = map(int,input().split())
List_A = list(map(int,input().split()))
List_BC = [list(map(int,input().split())) for i in range(M)]

List_A.sort()
List_BC.sort(key=lambda x:x[1], reverse=True)
flag = 0
k = 0

for i in range(M):
    for j in range(List_BC[i][0]):
        if k >= N:
            flag = 1
            break
        elif List_BC[i][1] > List_A[k]:
            List_A[k] = List_BC[i][1]
            k += 1
        else:
            flag = 1
            break
    if flag == 1:
        break

tmp = 0
for i in range(N):
    tmp += List_A[i]
    
print("{}".format(tmp))