Buggy python submission (verdict: Runtime Error):
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))


Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in inputs:
    if alist[0] > i[1]:
        break
    elif alist[i[0]-1] < i[1]:
        alist = [i[1]] * i[0] + alist[i[0]:]
    else:
        limit=bisect.bisect_left(alist, i[1])
        alist = [i[1]] * limit + alist[limit:]
    alist.sort()

print(sum(alist))




Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1])

for i in inputs:
    if alist[0] > i[1]:
        continue
    elif alist[i[0]-1] < i[1]:
        alist = [i[1]] * i[0] + alist[i[0]:]
    else:
        limit=bisect.bisect_left(alist, i[1])
        alist = [i[1]] * limit + alist[limit:]
    alist.sort()

print(sum(alist))




Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
inputs = [[int(i) for i in input().split()] for _ in range(M)]

alist.sort()
inputs.sort()

for i in inputs:
    if alist[i[0]-1] < i[1]:
        alist = [i[1]] * i[0] + alist[i[0]:]
    else:
        limit=bisect.bisect_left(alist, i[1])
        alist = [i[1]] * limit + alist[limit:]
    alist.sort()

print(sum(alist))




Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
inputs = [[int(i) for i in input().split()] for _ in range(M)]

alist.sort()
inputs.sort(key=lambda x: x[1],reverse=True)

for i in inputs:
    index=bisect.bisect_left(alist, i[1])
    limit = index if index < i[0] else i[0]
    alist = [i[1]] * limit + alist[limit:]
    alist.sort()

print(sum(alist))


Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
inputs = [[int(i) for i in input().split()] for _ in range(M)]

alist.sort()
inputs.sort(key=lambda x: x[1],reverse=True)

for i in inputs:
    index=bisect.bisect_left(alist, i[1])
    limit = index if index < i[0] else i[0]
    for r in range(limit):
        alist[r]=i[1]
    alist.sort()

print(sum(alist))




Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))

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

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
inputs = [[int(i) for i in input().split()] for _ in range(M)]

alist.sort()

for i in inputs:
    index=bisect.bisect_left(alist, i[1])
    limit = index if index < i[0] else i[0]
    for r in range(limit):
        alist[r]=i[1]
    alist.sort()

print(sum(alist))




Fixed submission:
import bisect

N, M = [int(i) for i in input().split()]
alist = [int(i) for i in input().split()]
alist.sort()
inputs = [[int(i) for i in input().split()] for j in range(M)]
inputs.sort(key=lambda x:x[1], reverse=True)

for i in range(N):
    if len(inputs) == 0:
        break
    if inputs[0][1] > alist[i]:
        alist[i] = inputs[0][1]
        inputs[0][0] -= 1
        if inputs[0][0] == 0:
            inputs.pop(0)
    else:
        break
print(sum(alist))