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

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m

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

ans = 0
for i in range(n):
  a[i] = -a[i]

for i in b:
  a += [-i[1]] * i[0]

hq.heapify(a)

for i in range(n):
  ans -= hq.heappop(a)
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m

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

ans = 0
for i in range(n):
  a[i] = -a[i]

for i in b:
  a += i[1] * i[0]

hq.heapify(a)

for i in range(n):
  ans -= hq.heappop(a)
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
import sys
import heapq as hq
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))

ans = 0
for i in range(n):
  a[i] = -a[i]
#b.sort(key=itemgetter(1),reverse=True)
for i in b:
  for j in range(i[0]):
    a.append(-i[1])

hq.heapify(a)

for i in range(n):
  ans -= hq.heappop(a)
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
import sys
import heapq as hq
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))

ans = 0
for i in range(n):
  a[i] = -a[i]
#b.sort(key=itemgetter(1),reverse=True)
for i in b:
  for j in range(i[0]):
    a.append(-i[1])

hq.heapify(a)

for i in range(n):
  ans -= hq.heappop(a)
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
import sys
from operator import itemgetter
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))

ans = 0
b.sort(key=itemgetter(1),reverse=True)
for i in b:
  for j in range(i[0]):
    a.append(i[1])
a.sort(reverse=True)
for i in range(n):
  ans += a[i]
print(ans)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
import sys
from operator import itemgetter
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()
#print(a)
b.sort(key=itemgetter(1),reverse=True)
for i in b:
    tmp = min(bi.bisect_left(a,i[1]),i[0])
    if tmp == 0:
        print(sum(a))
        sys.exit()
    for j in range(tmp):
        a[j] = i[1]
    a.sort()
#print(a)
print(sum(a))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
import sys
from operator import itemgetter
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()
#print(a)
b.sort(key=itemgetter(1),reverse=True)
for i in b:
    tmp = bi.bisect_left(a,i[1])
    for j in range(min(tmp,i[0])):
        a[j] = i[1]
    a.sort()
#print(a)
print(sum(a))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()

for i in b:
    tmp = bi.bisect_left(a,i[1])
    for j in range(min(tmp,i[0])):
        a[j] = i[1]
    a.sort()

print(sum(a))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

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

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()

for i in b:
    tmp = bi.bisect_left(a,i[1])
    for j in range(min(tmp,i[0])):
        a[j] = i[1]
    a.sort()

print(sum(a))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bi
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()
#print(a)
for i in b:
    tmp = bi.bisect_left(a,i[1])
    for j in range(min(tmp,i[0])):
        a[j] = i[1]
    a.sort()
#print(a)
print(sum(a))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)