Buggy python submission (verdict: Runtime Error):
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    if c <= a[a_idx] or a_idx == a_len:
        break
    for b_idx in range(b):
        if a_idx == a_len or c <= a[a_idx]:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(sum(a))


Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    if c <= a[a_idx] or a_idx == a_len:
        break
    for b_idx in range(b):
        if c <= a[a_idx] or a_idx == a_len:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(a)

Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    for b_idx in range(b):
        if c <= a[a_idx] or a_idx == a_len:
            print(sum(a))
            exit()
        else:
            a[a_idx] = c
            a_idx += 1


Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for b, c in cards:
    if c <= a[a_idx] or a_idx == a_len:
        break
    for b_idx in range(b):
        if c <= a[a_idx]:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(sum(a))


Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))

Buggy python submission (verdict: Runtime Error):
import sys
import operator

n, m = map(int, input().split())
a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()
cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0

for b, c in cards:
    if c <= a[a_idx]:
        break
    for b_idx in range(b):
        if c <= a[a_idx]:
            break
        else:
            a[a_idx] = c
            a_idx += 1

print(sum(a))


Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))

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

n, m = map(int, input().split())
a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()
cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)
for b, c in cards:
    if c <= a[0]:
        break
    for idx in range(b):
        if c <= a[idx]:
            break
        a[idx] = c
    a.sort()
print(sum(a))


Fixed submission:
import sys
import operator

n, m = map(int, input().split())

a = [int(x) for x in sys.stdin.readline().rstrip().split()]
a.sort()

cards = [[int(x) for x in sys.stdin.readline().rstrip().split()] for _ in range(m)]
cards.sort(key=operator.itemgetter(1), reverse=True)

a_idx = 0
a_len = len(a)

for i in range(len(cards)):
    for j in range(cards[i][0]):
        if a_idx == a_len or a[a_idx] >= cards[i][1]:
            break
        else:
            a[a_idx] = cards[i][1]
            a_idx += 1

print(sum(a))