Buggy python submission (verdict: Time Limit Exceeded):
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]


for index1 in range(num2):
    num4 = 0
    num3.sort()
    #numArray[index1].sort()
    for index2 in range(num1):

        if num3[index2] < numArray[index1][1]:
            num3[index2] = numArray[index1][1]
            num4 += 1
        if num4 >= numArray[index1][0] :
            break
print(sum(num3))

Fixed submission:
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]

numArray.sort(key=lambda x:(-x[1]))

fg1 = True

for index1 in range(num2):
    for index2 in range(numArray[index1][0]):
        num3.append(numArray[index1][1])
        if len(num3)>=(num1*2):
            fg1= False
            break
    if fg1 == False:
        break

num3.sort(reverse=True)

sum1 = 0
for index4 in range(num1):
    sum1 +=num3[index4]

print(str(sum1))

Buggy python submission (verdict: Runtime Error):

num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]


for index1 in range(num1):
     for index2 in range(numArray[index1][0]):
         num3.append(numArray[index1][1])
         if index2 >= num2:
             break

num3.sort(reverse=True)

sum1 = 0

for index2 in range(num1):
    sum1 += num3[index2]

print(sum(num3))

Fixed submission:
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]

numArray.sort(key=lambda x:(-x[1]))

fg1 = True

for index1 in range(num2):
    for index2 in range(numArray[index1][0]):
        num3.append(numArray[index1][1])
        if len(num3)>=(num1*2):
            fg1= False
            break
    if fg1 == False:
        break

num3.sort(reverse=True)

sum1 = 0
for index4 in range(num1):
    sum1 +=num3[index4]

print(str(sum1))

Buggy python submission (verdict: Time Limit Exceeded):
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]


for index1 in range(num2):
     for index2 in range(numArray[index1][0]):
         num3.append(numArray[index1][1])

num3.sort(reverse=True)

sum1 = 0

for index2 in range(num1):
    sum1 += num3[index2]

print(sum1)

Fixed submission:
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]

numArray.sort(key=lambda x:(-x[1]))

fg1 = True

for index1 in range(num2):
    for index2 in range(numArray[index1][0]):
        num3.append(numArray[index1][1])
        if len(num3)>=(num1*2):
            fg1= False
            break
    if fg1 == False:
        break

num3.sort(reverse=True)

sum1 = 0
for index4 in range(num1):
    sum1 +=num3[index4]

print(str(sum1))

Buggy python submission (verdict: Runtime Error):
for index1 in range(num2):
     for index2 in range(numArray[index1][0]):
         num3.append(numArray[index1][1])

num3.sort(reverse=True)

sum1 = 0

for index2 in range(num1):
    sum1 += num3[index2]

print(sum1)

Fixed submission:
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]

numArray.sort(key=lambda x:(-x[1]))

fg1 = True

for index1 in range(num2):
    for index2 in range(numArray[index1][0]):
        num3.append(numArray[index1][1])
        if len(num3)>=(num1*2):
            fg1= False
            break
    if fg1 == False:
        break

num3.sort(reverse=True)

sum1 = 0
for index4 in range(num1):
    sum1 +=num3[index4]

print(str(sum1))

Buggy python submission (verdict: Runtime Error):
for index1 in range(num2):
     for index2 in range(numArray[index1][0]):
         num3.append(numArray[index1][1])

num3.sort(reverse=True)

sum1 = 0

for index2 in range(num1):
    sum1 += num3[index2]

print(sum1)

Fixed submission:
num1, num2 = [int(i) for i in input().split()]
num3 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index3 in range(num2):
    numArray[index3] = [int(j) for j in input().split()]

numArray.sort(key=lambda x:(-x[1]))

fg1 = True

for index1 in range(num2):
    for index2 in range(numArray[index1][0]):
        num3.append(numArray[index1][1])
        if len(num3)>=(num1*2):
            fg1= False
            break
    if fg1 == False:
        break

num3.sort(reverse=True)

sum1 = 0
for index4 in range(num1):
    sum1 +=num3[index4]

print(str(sum1))