Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    num_freq[c] += b


new_list = []
for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
    new_list += [num] * freq
    if len(new_list) >= n:
        break
tmp = sorted(nums + new_list)[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    num_freq[c] += b


new_list = []
for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
    new_list += [num] * freq
    if len(new_list) > n:
        break
tmp = sorted(nums + new_list)[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = sorted([int(i) for i in input().split()])[::-1]

d = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    d[c] += b


new_list = []
cnt = 0
for c, b in sorted(d.items(), key=lambda x: -x[0]):
    new_list += [c] * b
    cnt += b
    if cnt > n:
        break
tmp = sorted(nums + new_list)[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = sorted([int(i) for i in input().split()])[::-1]

d = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    d[c] += b


new_list = []
cnt = 0
for c, b in sorted(d.items(), key=lambda x: -x[0]):
    new_list += [c] * b
    cnt += b
    if cnt > 10000:
        break
tmp = sorted(nums + new_list)[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = sorted([int(i) for i in input().split()])[::-1]

d = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    d[c] += b


new_list = []
cnt = 0
for c, b in sorted(d.items(), key=lambda x: -x[1]):
    new_list += [c] * b
    cnt += b
    if cnt > 10000:
        break
tmp = sorted(nums + new_list)[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())
nums = sorted([int(i) for i in input().split()])[::-1]

d = defaultdict(int)

for _ in range(m):
    b, c = map(int, input().split())
    d[c] += b


new_list = []
cnt = 0
for c, b in sorted(d.items(), key=lambda x: -x[1]):
    new_list += [c] * b
    cnt += b
    if cnt > 10000:
        break
tmp = sorted(nums + sorted(new_list))[::-1]
print(sum(tmp[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

nums = sorted([int(i) for i in input().split()])[::-1]

ms = []
for _ in range(m):
    a, b = map(int, input().split())
    ms += [b] * a
ms = sorted(ms)[::-1][:n]

print(sum(nums + ms)[:n])


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
 
nums = sorted([int(i) for i in input().split()])[::-1]
 
ms = []
for _ in range(m):
    a, b = map(int, input().split())
    ms += [b] * a
ms = sorted(ms)[::-1]
 
ans = i = j = 0
for _ in range(n):
    if nums[i] >= ms[j]:
        ans += nums[i]
        i += 1
    else:
        ans += ms[j]
        j += 1
print(ans)

Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Runtime Error):
# TLEを承知で出す
n, m = map(int, input().split())

nums = sorted([int(i) for i in input().split()])[::-1]

ms = []
for _ in range(m):
    a, b = map(int, input().split())
    ms += [b] * a
ms = sorted(ms)[::-1]

ans = i = j = 0
for _ in range(n):
    if nums[i] >= ms[j]:
        ans += nums[i]
        i += 1
    else:
        ans += ms[j]
        j += 1
print(ans)


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
# TLEを承知で出す
n, m = map(int, input().split())

nums = sorted([int(i) for i in input().split()])[::-1]

for _ in range(m):
    a, b = map(int, input().split())
    nums += [b] * a

nums = sorted(nums)[::-1]
print(sum(nums[:n]))


Fixed submission:
# from collections import defaultdict
# n, m = map(int, input().split())
# nums = [int(i) for i in input().split()]
#
# num_freq = defaultdict(int)
#
# for _ in range(m):
#     b, c = map(int, input().split())
#     num_freq[c] += b
#
#
# new_list = []
# for num, freq in sorted(num_freq.items(), key=lambda x: -x[0]):
#     new_list += [num] * freq
#     if len(new_list) >= n:
#         break
# tmp = sorted(nums + new_list)[::-1]
# print(sum(tmp[:n]))

# ↑と同じ処理なのに↑のはREになる
n, m = map(int, input().split())
nums = list(map(int, input().split()))
exc = []

for i in range(m):
    exc.append(list(map(int, input().split())))
exc.sort(key=lambda x: x[1], reverse=True)
e = []
count = 0
for i in range(m):
    freq = exc[i][0]
    e += [exc[i][1]] * freq
    count += freq
    if count >= n:
        break
cards = sorted(nums + e, reverse=True)
print(sum(cards[:n]))