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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

mx = n*2
[heapq.heappushpop(A, bc[1]) for i, bc in enumerate(BC) for _ in range(bc[0]) if i < mx]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

mx = n*2
[heapq.heappushpop(A, bc[1]) for bc in BC if len(A) < mx for _ in range(bc[0])]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

mx = n*2+1
[heapq.heappushpop(A, bc[1]) for bc in BC for _ in range(bc[0]) if len(A) < mx]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC]
A.sort(reverse=True)

print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC]
A.sort(reverse=True)

print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend(list(ls[1] for _ in range(ls[0]))) for ls in BC]
A.sort(reverse=True)

print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([ls[1] for _ in range(ls[0])]) for ls in BC]
A.sort(reverse=True)

print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

[A.extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

[extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])
 
extend = A.extend
[extend([BC[i][1]] * BC[i][0]) for i in range(m)]
 
A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC = sorted(BC, key=lambda x: -x[1])

extend = A.extend
[extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A = sorted(A, reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A.sort(key=lambda x: -x)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]

extend = A.extend
[extend([BC[i][1]] * BC[i][0]) for i in range(m)]

A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))

C = []
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    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 = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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 for _ in range(b)])
C.sort(reverse=True)

for i in range(min(len(C), n)):
    if C[i] <= A[i]:
        break
    A[i] = C[i]

print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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 for _ in range(b)])
C.sort(reverse=True)

for i in range(min(len(C), n)):
    if C[i] <= A[i]:
        break
    A[i] = C[i]

print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
 
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
 
for _ in range(m):
    b, c = map(int, input().split())
    [heapq.heappushpop(A, c) for i in [0]*b]
 
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for _ in range(m):
    b, c = map(int, input().split())
    [heapq.heappushpop(A, c) for i in [0]*b]

print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
B = 0
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    extend([c]*b)
 
A.sort()
del A[0:B]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
 
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
 
for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        heapq.heappushpop(A, c)
 
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(m)]
for card_set in BC:
    for i in range(card_set[0]):
        heapq.heappushpop(A, card_set[1])

print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)

for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        heapq.heappushpop(A, c)

print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
B = 0
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    extend([c]*b)

A.sort()
del A[0:B]
print(np.sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
B = 0
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    extend([c]*b)
 
A.sort()
del A[0:B]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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

input = sys.stdin.readline
n, m = map(int, input().split())
*A, = map(int, input().split())
B = 0
extend = A.extend
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    extend([c]*b)

A.sort()
del A[0:B]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
B = 0
for _ in range(m):
    b, c = map(int, input().split())
    B += b
    C = [c]*b
    A.extend(C)

A.sort()
del A[0:B]
print(sum(A))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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())
    C = [c]*b
    A.extend(C)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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())
    C = [c for i in range(b)]
    A.extend(C)
 
A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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())
    C = [c for i in range(b)]
    A.extend(C)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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()))
BC = [list(map(int, input().split())) for _ in range(m)]
 
C = [card_set[1] for card_set in BC for j in range(card_set[0])]
A.extend(C)
 
A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

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())
    for i in range(b):
        A.append(c)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        A.append(c)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Runtime Error):
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
C = []
for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        C.append(c)
A.extend(C)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
C = []
for _ in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        C.append(c)
A.extend(C)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

C = [card_set[1] for card_set in BC for j in range(card_set[0])]
A.extend(C)

A = sorted(A, reverse=True)
result = [A[i] for i in range(n)]
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

C = [card_set[1] for card_set in BC for j in range(card_set[0])]
A.extend(C)

A = sorted(A, reverse=True)
result = []
for i in range(n):
    result.append(A[i])
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

for card_set in BC:
    for j in range(card_set[0]):
        A.append(card_set[1])

A = sorted(A, reverse=True)
result = []
for i in range(n):
    result.append(A[i])
print(sum(result))

Fixed submission:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))