Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
x = np.zeros((2,m),dtype="int64")
for i in range(m):
    x[0,i],x[1,i]=intinput()
y = np.empty(n+np.sum(x[0]),dtype="int64")
y[0:n]=a
x = x.T
k = 0
for i in x:
    y[n+k:n+k+i[0]]=i[1]
    k+=i[0]
y=np.sort(y)[::-1]
print(np.sum(y[0:n]))

Fixed submission:
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
x = np.zeros((2,m),int)
for i in range(m):
    x[0,i],x[1,i]=intinput()
y = np.empty(n+np.sum(x[0]),dtype="int64")
y[0:n]=a
x = x.T
k = 0
for i in x:
    y[n+k:n+k+i[0]]=i[1]
    k+=i[0]
y=np.sort(y)[::-1]
print(np.sum(y[0:n]))

Fixed submission:
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
x = np.zeros((2,m),int)
for i in range(m):
    x[0,i],x[1,i]=intinput()
y = np.empty(n+np.sum(x[0]),int)
y[0:n]=a
x = x.T
k = 0
for i in x:
    y[n+k:n+k+i[0]]=i[1]
    k+=i[0]
y=np.sort(y)[::-1]
print(np.sum(y[0:n]))

Fixed submission:
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)

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

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a.sort()
l = []
for i in range(m):
    b,c=intinput()
    for j in range(b):
        l.append(c)
l.sort(reverse=1)
sum=0
for i in range(len(a)):
    try:
        sum += max(a[i],l[i])
    except:
        sum += a[i]
print(sum)

Fixed submission:
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)

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

def intinput():
    return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a.sort()
l = []
for i in range(m):
    b,c=intinput()
    for j in range(b):
        l.append(c)
l.sort(reverse=1)
if len(l)<len(a):
    for r in range(len(a)-len(l)):
        l.append(0)
sum=0
for i in range(len(a)):
    sum += max(a[i],l[i])
print(sum)

Fixed submission:
import sys

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
a = list(intinput())
a = [(a[x],1) for x in range(n)]
for i in range(m):
    b,c=intinput()
    a.append((c,b))
a.sort(reverse=1)
res,cnt=0,n
for (x,y) in a:
    k = min(cnt,y)
    res += k*x
    cnt -= k
print(res)