Buggy python submission (verdict: Runtime Error):
n = 0
for b,c in bc:
    for i in range(b):
        if i == n or a[i] >= c:
            break

        a[i] = c
        n += 1

print(sum(a))

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int,input().split()))
MIN = min(a)
p = []
for _ in range(m):
    b,c = map(int, input().split())  
    if c > MIN:
        p.extend([c]*b)

ans = (a+p)
ans.sort(reverse=True)
print(sum(ans[:n]))

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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())
    if min(a) < c:
        for _ in range(b):
            if min(a) < c:
                a[a.index(min(a))] = c
            else:
                break

print(sum(a))

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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 _ in range(b):
        a.append(c)
        a.sort(reverse=True)
    a = a[:n]
    
print(sum(a))

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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 _ in range(b):
        a.append(c)
        a.sort(reverse=True)
                

print(sum(a[:n]))

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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

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


Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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 _ in range(b):
        a.append(c)

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

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))