Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    for j in range(info[i][0]):
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
            if index == n-1:
                break
        else:
            break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    for j in range(info[i][0]):
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
            if index == n:
                break
        else:
            break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    for j in range(info[i][0]):
        if A[index] <= info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    for j in range(info[i][0]):
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)

Fixed submission:
n, m = map(int, input().split())
A = sorted(map(int, input().split()))
info = []
for _ in range(m):
    b, c = map(int, input().split())
    info.append([b, c])
info.sort(key=lambda x: x[1], reverse=True)
# print(info, A)
index = 0
for i in range(m):
    if index == n:
        break
    for j in range(info[i][0]):
        if index == n:
            break
        if A[index] < info[i][1]:
            A[index] = info[i][1]
            index += 1
        else:
            break

ans = sum(A)
print(ans)