Problem p03038 (python)

Fixed submission:
read = input 
rn = lambda :map(int, read().split())
n,m = rn()
A = list(rn())
l = len(A)
d = {}
for x in A:
    if x not in d:
        d[x]=0
    d[x] += 1
for i in range(m):
    b, c = rn()
    if c not in d:
        d[c]=0
    d[c] += b
A = list(d.items())
A.sort(reverse=True)
ans = 0
cnt = l
# print(A)
for v, c in A:
    tmp = min(cnt, c)
    ans += tmp * v
    cnt -= tmp
print(ans)

Buggy submission (verdict: Runtime Error):
rn = lambda :map(int, read().split())
n,m = rn()
A = list(rn())
l = len(A)
d = {}
for x in A:
    if x not in d:
        d[x]=0
    d[x] += 1
for i in range(m):
    b, c = rn()
    if c not in d:
        d[c]=0
    d[c] += b
A = list(d.items())
A.sort(reverse=True)
ans = 0
cnt = l
# print(A)
for v, c in A:
    tmp = min(cnt, c)
    ans += tmp * v
    cnt -= tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
dic = {}
A = [int(x) for x in input().split()]
for x in input().split():
  if int(x) not in dic:
    dic[int(x)] = 0
  dic[int(x)] += 1
length = len(A)
for i in range(M):
  b,c  = map(int,input().split())
  if b not in A:
    A[b] = 0
  A[b] += c
A = sorted(A.items(),key = lambda x:x[1],reverse = True)
sum = 0
for v,c in A:
  tmp = min(length,c)
  sum += tem*V
  length -= tmp
print(sum)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N,M=map(int,input().split())
dic = defaultdict(lambda:0)
A = [int(x) for x in input().split()]
length = len(A)
for i in A:
  dic[i] += 1
for i in range(M):
  b,c = map(int,input().split())
  dic[c] += b
A = list(d.items())
A.sort(reverse=True)
ans = 0
l = length
for v,c in A:
  tmp = min(l, c)
  ans += tmp * v
  l -= tmp
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A = [int(x) for x in input().split()]
B = []
length = len(A)
for i in range(M):
  b,c = map(int,input().split())
  B.extend(b*[c])
A.sort(reverse = True)
B.sort(reverse=True)
A = A[:length] 
B = B[:length]
if A[-1] >= B[0]:
  print(sum(A))
elif B[-1] > = A[0]:
  print(sum(B)
else:
  C = A + B
  C.sort(reverse=True)
  print(C[:length])

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A = [int(x) for x in input().split()]
B = []
length = len(A)
for i in range(M):
  b,c = map(int,input().split())
  B.extend(b*[c])
A.sort(reverse = True)
B.sort(reverse=True)
A = A[:length] + B[:length]
if A[-1] >= B[0]:
  print(sum(A))
elif B[-1] > = A[0]:
  print(sum(B)
else:
  C = A + B
  C.sort(reverse=True)
  print(C[:length])

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A = [int(x) for x in input().split()]
length = len(A)
for i in range(M):
    b,c = map(int,input().split())
    A.extend(b*[c])
	A.sort(reverse = True)
    A = A[:length]
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A = [int(x) for x in input().split()]
length = len(A)
for i in range(N-1):
    b,c = map(int,input().split())
    A.extend(b*[c])
A.sort(reverse = True)
print(sum(A[:length]))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A = [int(x) for x in input().split()]
length = A
for i in range(N):
  b,c = map(int,input().split())
  A.extend(b*[c])
print(sum(A[:length]))