Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
	break
    a[i] = l[i]
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[c])
l=[]
for [b,c] in bc:
    l = l+[c]*b
    if n < len(l):
        break
print(sorted(l))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[]
for i in range(m):
    b,c = map(int, input().split(" "))
    bc = bc + [c]*b
bc.sort(reverse=True)
for i in range(n):
    if len(bc) <= i or bc[i] <= a[i]:
        break
    a[i] = bc[i]
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[]
for i in range(m):
    b,c = map(int, input().split(" "))
    bc = bc + [c]*b
bc.sort(reverse=True)
for i in range(n):
    if bc[i] <= a[i]:
        break
    a[i] = bc[i]
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import zip_longest
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[]
for i in range(m):
    b,c = map(int, input().split(" "))
    bc = bc + [c]*b
bc.sort(reverse=True)
print(sum(list(map(lambda x: x[1] if x[0] < x[1] else x[0], zip_longest(a,bc[0:n], fillvalue=0)))))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(key=lambda x:x[1], reverse=True)
result = 0
for [b,c] in bc:
    if len(a) == 0 or c < a[0]:
        break
    result = result + sum(list(map(lambda x: x if c < x else c, a[0:b])))
    a = a[b:]
print(sum(a)+result)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(key=lambda x:x[1], reverse=True)
result = 0
for [b,c] in bc:
    if len(a) == 0 or c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    result = result + sum(a[0:b])
    a = a[b:]
print(sum(a)+result)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
result = 0
for [b,c] in bc:
    if len(a) == 0:
        break
    if c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    result = result + sum(a[0:b])
    a = a[b:]
print(sum(a)+result)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
result = 0
for [b,c] in bc:
    if c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    result = result + sum(a[0:b])
    a = a[b:]
print(sum(a)+result)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
for [b,c] in bc:
    if c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    a = a[b:] + [sum(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(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
for [b,c] in bc:
    if c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    a = a[b:] + 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(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
for [b,c] in bc:
    if c < a[0]:
        break
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc = sorted(bc, key=lambda x:x[1], reverse=True)
for [b,c] in bc:
    if c < a[0]:
        continue
    for i in range(b):
        if c < a[i]:
            break
        a[i] = c
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
b=[None]*m
c=[None]*m
for i in range(m):
    b[i],c[i] = map(int, input().split(" "))
for bb,cc in zip(b,c):
    if cc < a[0]:
        continue
    for i in range(bb):
        if cc < a[i]:
            break
        a[i] = cc
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
b=[None]*m
c=[None]*m
for i in range(m):
    b[i],c[i] = map(int, input().split(" "))
for bb,cc in zip(b,c):
    if cc < a[0]:
        continue
    a[0:bb] = list(map(lambda x: x if cc < x else cc, a[0:bb]))
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
b=[None]*m
c=[None]*m
for i in range(m):
    b[i],c[i] = map(int, input().split(" "))
for i in range(0, m):
    if c[i] < a[0]:
        continue
    a[0:b[i]] = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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()
b=[]
c=[]
for i in range(0, m):
    ib,ic = map(int, input().split(" "))
    b.append(ib)
    c.append(ic)
for i in range(0, m):
    if c[i] < a[0]:
        continue
    a[0:b[i]] = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
b=[]
c=[]
for i in range(0, m):
    ib,ic = map(int, input().split(" "))
    b.append(ib)
    c.append(ic)
for i in range(0, m):
    if c[i] < a[0]:
        continue
    a[0:b[i]] = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
b=[]
c=[]
for i in range(0, m):
    ib,ic = map(int, input().split(" "))
    b.append(ib)
    c.append(ic)
for i in range(0, m):
    ax = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a[0:b[i]] = ax
    a.sort()
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a = sorted(a)
b=[]
c=[]
for i in range(0, m):
    ib,ic = map(int, input().split(" "))
    b.append(ib)
    c.append(ic)
for i in range(0, m):
    ax = list(map(lambda x: x if c[i] < x else c[i], a[0:b[i]]))
    a[0:b[i]] = ax
    a = sorted(a)
print(sum(a))

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
print(sum(a))