Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, m = map(int,sys.stdin.readline().split())
a = list(map(int,sys.stdin.readline().split()))
for k in [0]*m:
  s, t = map(int,sys.stdin.readline().split())
  a.extend([t]*s)
ans = 0
a.sort()
for v in range(n):
  ans += a[-v-1]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

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 k in [0]*m:
  s, t = map(int,input().split())
  b = [t]*s
  a.extend(b)
ans = 0
a.sort()
for v in range(n):
  ans += a[-v-1]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

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 k in range(m):
  s, t = map(int,input().split())
  b = [t]*s
  a.extend(b)
ans = 0
a.sort(reverse=True)
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

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(reverse=True)
for k in range(m):
  s, t = map(int,input().split())
  if a[n-1] < t:
    for i in range(n):
      if a[n-i-1] >= t:
        a[n-i:n-i] = [t]*s
        break
      elif i + 1 == n:
        a[0:0] = [t]*s
ans = 0
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
for k in range(m):
  s, t = map(int,input().split())
  if a[n-1] < t:
    for i in range(n):
      if a[n-i-1] >= t:
        a[n-i:n-i] = [t]*s
        break
      elif i + 1 == n:
        a[0:0] = [t]*s
ans = 0
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
for k in range(m):
  s, t = map(int,input().split())
  for i in range(n):
    if a[i] <= t:
      a[i:i] = [t]*s
      break
ans = 0
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = list(map(int,input().split()))
for k in range(m):
  s, t = map(int,input().split())
  b = [t]*s
  a.extend(b)
ans = 0
a.sort(reverse=True)
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = list(map(int,input().split()))
for k in range(m):
  s, t = map(int,input().split())
  for i in range(s):
    a.append(t)
ans = 0
a.sort(reverse=True)
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
for k in range(m):
  s, t = map(int,input().split())
  for i in range(s):
    a.append(t)
ans = 0
a.sort(reverse=True)
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int,input().split())
a = list(map(int,input().split()))
for k in range(m):
  a.sort()
  s, t = map(int,input().split())
  for i in range(s):
    if a[i] < t:
      a[i] = t
    else:
      break
ans = 0
for v in range(n):
  ans += a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
n, m = int(input().split())
a = map(int,input().split())
for k in range(m):
  a.sort()
  s, t = int(input().split())
  for i in range(s)
  	if a[i] < t:
      a[i] = t
    else:
      break
ans = 0
for v in range(n):
  ans = a[v]
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))

Buggy python submission (verdict: Runtime Error):
n, m = input().split()
a = map(int,input().split())
for k in range(m):
  a.sort()
  s, t = input().split()
  for i in range(s)
  	if a[i] < t:
      a[i] = t
    else:
      break
ans = 0
for v in range(n):
  ans = a[v]
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))