Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
print(sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
for _ in range(M):
    B, C = map(int,input().split())
    if A[B - 1] <= C:
        A[:B] = [C] * B
        A.sort()
    else:
        A[:B] = np.maximum(A[:B], C)
print(np.sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
for _ in range(M):
    B, C = map(int,input().split())
    if A[B - 1] <= C:
        A[:B] = [C] * B
        A.sort()
    else:
        A = np.maximum(A, C)
print(np.sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
for _ in range(M):
    B, C = map(int,input().split())
    if A[B - 1] <= C:
        A[:B] = [C] * B
         A.sort()
    else:
        A = np.maximum(A, C)
print(np.sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = map(int,input().split())
A = list(map(int,input().split()))
A = np.array(A)
for _ in range(M):
    B, C = map(int,input().split())
    A.sort()
    if A[B - 1] <= C:
        A[:B] = [C] * B 
    else:
        A = np.maximum(A, C)
print(np.sum(A))

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(N):
    if A[i] >= BC[j][1]:
        break
    else:
        A[i] = BC[j][1]
        BC[j][0] -= 1
        if BC[j][0] == 0:
            j += 1
        if j >= M:
            break
print(sum(A))