Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0

for i in command:
    for j in range(i[0]):
        if card[ind] >= i[1] | len(card) == ind + 1:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
for i in command:
    for j in range(i[0]):
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
#command = [list(map(int, input().split())) for i in range(m)]
#command.sort(key=lambda x: x[1], reverse=True)

command = []

for i in range(m):
    b, c = map(int, input().split())
    command.append([b,c])
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
for i in command:
    for j in range(i[0]):
        if card[ind] > i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
#command = [list(map(int, input().split())) for i in range(m)]
#command.sort(key=lambda x: x[1], reverse=True)

command = []

for i in range(m):
    b, c = map(int, input().split())
    command.append([c,b])

ind = 0
for i in command:
    for j in range(i[0]):
        if card[ind] > i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
for i in command:
    for j in range(i[0]):
        if card[ind] > i[1]:
            break
        card[ind] = i[1]
        ind += 1
#    else:
#        continue
#    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
ans = [list(map(int, input().split())) for i in range(m)]
ans.sort(key=lambda x: x[1], reverse=True)

ind = 0
for i in ans:
    for x in range(i[0]):
        if card[ind] > i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))

Fixed submission:
n, m = map(int, input().split()) 
card = list(map(int, input().split()))
card.sort()
command = [list(map(int, input().split())) for i in range(m)]
command.sort(key=lambda x: x[1], reverse=True)

ind = 0
maxNum = len(card)
for i in command:
    for j in range(i[0]):
        if maxNum < ind+1:
            break
        if card[ind] >= i[1]:
            break
        card[ind] = i[1]
        ind += 1
    else:
        continue
    break
print(sum(card))