Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        heapq.heappush(A_LIST, max(tmp, c))
print(sum(A_LIST))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A_LIST = sorted(map(int, input().split()))
C_LIST = []
for i in range(M):
    b, c = map(int, input().split())
    for _ in range(b):
        C_LIST.append(c)
C_LIST.sort(reverse=True)
ans = 0
for i in range(N):
    ans += max(A_LIST[i], C_LIST[i]) if len(C_LIST) > i else A_LIST[i]
print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A_LIST = sorted(map(int, input().split()))
C_LIST = []
for i in range(M):
    b, c = map(int, input().split())
    for _ in range(b):
        C_LIST.append(c)
C_LIST.sort(reverse=True)
for i in range(min(N, len(C_LIST))):
    A_LIST[i] = max(A_LIST[i], C_LIST[i])
print(sum(A_LIST))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A_LIST = sorted(map(int, input().split()))
C_LIST = []
for i in range(M):
    b, c = map(int, input().split())
    for _ in range(b):
        C_LIST.append(c)
C_LIST.sort(reverse=True)
for i in range(N):
    A_LIST[i] = max(A_LIST[i], C_LIST[i])
print(sum(A_LIST))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        tmp = heapq.heappop(A_LIST)
        heapq.heappush(A_LIST, max(tmp, c))
print(sum(A_LIST))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        if c > a[j]:
            a[j] = c
        else:
            break

    a.sort()

print(sum(a))


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
max_sum = sum(a)
for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        if c > a[j]:
            a[j] = c
        else:
            break

    a.sort()
    if sum(a) > max_sum:
        max_sum = sum(a)

print(max_sum)


Fixed submission:
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))