Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    s, l = map(int, input().split())
    temp = [l]*s
    upd.extend(temp)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
ch = c
if f > c:
    for i in range(c):
        if upd[c-1-i] > a[c-1-i]:
            a[c-1-i] = upd[c-1-i]
        else:
            pass
else:
    for i in range(f):
        if upd[f-1-i] > a[f-1-i]:
            a[f-1-i] = upd[f-1-i]
        else:
            pass
print(sum(a))

Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    s, l = map(int, input().split())
    temp = [l]*s
    upd.extend(temp)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
ch = c
if f > c:
    for i in range(c):
        if upd[c-1-i] > a[c-1-i]:
            break
        else:
            ch = c-i-1
else:
    for i in range(f):
        if upd[f-1-i] > a[f-1-i]:
            break
        else:
            ch = f-i-1
print(sum(upd[:ch])+sum(a[ch:]))

Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    s, l = map(int, input().split())
    temp = [l]*s
    upd.extend(temp)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
if f > c:
    for i in range(c):
        o += max(upd[c-1-i], a[c-1-i])
#        print(o)
    print(o+sum(a[c:]))
else:
    for i in range(f):
        o += max(upd[i], a[i])
#        print(o)
    print(o)

Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
upd = []
for i in range(m):
    s, l = map(int, input().split())
    temp = [l]*s
    upd.extend(temp)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
if f > c:
    for i in range(c):
        o += max(upd[c-1-i], a[c-1-i])
#        print(o)
    print(o+sum(a[c:]))
else:
    for i in range(f):
        o += max(upd[i], a[i])
#        print(o)
    print(o)

Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
upd = []
for i in range(m):
    s, l = map(int, input().split())
    for j in range(s):
        upd.append(l)
upd.sort(reverse=True)

# output
f = len(a)
o = 0
c = len(upd)
if f > c:
    for i in range(c):
        o += max(upd[c-1-i], a[c-1-i])
#        print(o)
    print(o+sum(a[c:]))
else:
    for i in range(f):
        o += max(upd[i], a[i])
#        print(o)
    print(o)

Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
upd = []
for i in range(m):
    s, l = map(int, input().split())
    for j in range(s):
        upd.append(l)
upd = sorted(upd, reverse=True)
a = sorted(a)

# output
f = len(a)
o = 0
c = len(upd)
if f > c:
    for i in range(c):
        o += max(upd[c-1-i], a[c-1-i])
    print(o+sum(a[c:]))
else:
    for i in range(f):
        o += max(upd[i], a[i])
    print(o)


Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
for i in range(m):
    s, l = map(int, input().split())
    if l > a[0]:
        for j in range(s):
            if a[j] < l:
                a[j] = l
            else:
                break
    a = sorted(a)
# output
print(sum(a))


Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# abc 127 d
# input
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
for i in range(m):
    s, l = map(int, input().split())
    for j in range(s):
        if a[j] < l:
            a[j] = l
    a = sorted(a)
# output
print(sum(a))


Fixed submission:
# -*- coding: utf-8 -*-
# abc 127 d
from operator import itemgetter
# input
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
upd = []
for i in range(m):
    upd.append(list(map(int, input().split())))
upd.sort(key=itemgetter(1), reverse=True)
# print(upd)
# output
f = len(a)
p = 0
for t in upd:
    for i in range(p, p+t[0]):
        if p < f:
            if a[p] < t[1]:
                a[p] = t[1]
            else:
                break
        else:
            break
        p += 1
print(sum(a))