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

n, m = map(int, input().split())

nums = list(map(int, input().split()))

nums.sort()

ops = []
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if c < nums[0]:
        break
    if total > n:
        break

    index = bisect.bisect_left(nums, c)
    if index > 0:
        temp = nums[0:index]
        temp.extend([c]*b)
        temp.extend(nums[index:])
        nums = temp[-n:]
    total = total + b
print(sum(nums))

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

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

n, m = map(int, input().split())

nums = list(map(int, input().split()))

nums.sort()
for i in range(m):
    b, c = map(int, input().split())
    
    index = bisect.bisect_left(nums, c)
    if index > 0:
        temp = nums[0:index]
        temp.extend([c]*b)
        temp.extend(nums[index:])
        nums = temp[-n:]
        
print(sum(nums))

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

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

n, m = map(int, input().split())

nums = list(map(int, input().split()))

nums.sort()
for i in range(m):
    b, c = map(int, input().split())
    
    index = bisect.bisect_left(nums, c)
    if index > 0:
        temp = nums[0:index]
        temp.extend([c]*b)
        temp.extend(nums[index:])
        nums = temp[-n:]
        
result = 0
for i in nums:
    result = result + i

print(result)

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

nums = list(map(int, input().split()))

nums.sort(reverse=True)
for i in range(m):
    b, c = map(int, input().split())
    for j in range(n):
        if nums[j] < c:
            temp = nums[0:j]
            temp.extend([c]*b)
            temp.extend(nums[j:])
            nums = temp[0:n]
            break
        
result = 0
for i in nums:
    result = result + i

print(result)

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

nums = list(map(int, input().split()))

nums.sort(reverse=True)
for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        nums.append(c)
        
    nums.sort(reverse=True)
    nums = nums[0:n]

result = 0
for i in nums:
    result = result + i

print(result)

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

nums = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        nums.append(c)

count = 0
result = 0
nums.sort(reverse=True)
for i in nums:
    if count >= n:
        break
    result = result + i
    count = count + 1

print(result)

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

nums = list(map(int, input().split()))

for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        nums.append(c)

count = 0
result = 0
for i in sorted(nums, reverse=True):
    if count >= n:
        break
    result = result + i
    count = count + 1

print(result)

Fixed submission:
n, m = map(int, input().split())

nums = list(map(int, input().split()))

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))