Problem p03038 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if idx+1 <= len(A):
      if A[idx] < k:
      	A[idx] = k
      	idx += 1
      else:
        print(sum(A))
        exit()
    else:
      print(sum(A))
      exit()
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if idx-1 <= len(A):
      if A[idx] < k:
      	A[idx] = k
      	idx += 1
      else:
        print(sum(A))
        exit()
    else:
      print(sum(A))
      exit()
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      break
  else:
    continue
  break
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      break
  else:
    continue
  break
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      break
  else:
    continue
  break
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      break
else:
  continue
break
      
      
print(sum(A))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      print(sum(A))
      exit()

print(sum(A))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx <= len(A):
      A[idx] = k
      idx += 1
    else:
      print(sum(A))
      exit()

print(sum(A))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k:
      A[idx] = k
      idx += 1
    else:
      print(sum(A))
      exit()

print(sum(A))