Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for _ in range(M):
    b, c = map(int, input().split())
    C.extend([c]*b)
C.sort()

ans = 0
for i in range(N):
    if C:
        if C[-1] >= A[-1]:
            ans += C.pop()
            continue
    ans += A.pop()
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for _ in range(M):
    b, c = map(int, input().split())
    C.extend([c]*b)
C.sort()

ans = 0
for i in range(N):
    if C:
        if C[-1] >= A[-1]:
            ans += C.pop()
            continue
    ans += A.pop()
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for _ in range(M):
    b, c = map(int, input().split())
    C.extend([c]*b)
C.sort(reverse=True)

ans = 0
for i in range(M):
    if i == N:
        print(ans)
        exit()
    if C[i] <= A[0]:
        num = i
        break
    ans += C[i]
ans += sum(A[num:])
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
C = []
for _ in range(M):
    b, c = map(int, input().split())
    C.extend([c]*b)
C.sort(reverse=True)

ans = 0
for i in range(M):
    if C[i] <= A[0] or i == N:
        num = i
        break
    ans += C[i]
ans += sum(A[num:])
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    b, c = map(int, input().split())
    A.extend([c] * b)
A.sort(reverse = True)
ans = 0
for i in range(N):
    ans += A[i]
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    b, c = map(int, input().split())
    A.extend([c] * b)
A.sort(reverse = True)
ans = 0
for i in range(N):
    ans += A[i]
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    b, c = map(int, input().split())
    A.extend([c] * b)
A.sort(reverse = True)
print(sum(A[:N]))


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    b, c = map(int, input().split())
    A.extend([c] * b)
A.sort(reverse = True)
print(sum(A[:N]))


Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
table = []
for i in range(N):
    table.append((A[i], 1))
for i in range(M):
    b, c = map(int, input().split())
    table.append((c, b))

table = sorted(table)
cnt = N
ans = 0
while cnt > 0:
    #print(ans,s)
    c, b = table.pop()
    if b >= cnt:
        ans += c*cnt
        break
    ans += c*b
    cnt -= b
print(ans)