Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
n = 0
i = 0
m = 0
while A[i]<BC[n][1]:
    A[i] = BC[n][1]
    m = m+1
    if m >=BC[n][0]:
        m = 0
        n = n+1
    i += 1
    if n==M:
      break
    if i == N:
      break
print(sum(A))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
b =[]
for i in range(M):
    B,C = map(int, input().split())
    b.extend([C for _ in range(B)])
bisec = bisect_left
ex = A.extend
b.sort()
b.reverse()
for i in range(N):
    if A[i]<b[-1]:
        l = bisec(b,A[i])
        print(b[l])
        A[i] = b[l]
        del b[l]
    else:
        break
print(sum(A))

Buggy submission (verdict: Runtime Error):

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
n = 0
i = 0
m = 0
while A[i]<BC[n][1]:
    A[i] = BC[n][1]
    m = m+1
    if m >=BC[n][0]:
        m = 0
        n = n+1
    i += 1
print(sum(A))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
bisec = bisect_left
ex = A.extend
su =0
for i in range(M):
    if BC[i][1]<=A[0]:
        break
    B= BC[i][0]
    C = BC[i][1]
    b = bisec(A,C)
    if B>=b:
        su += C*b
        A = [A[i] for i in range(b,len(A))]
    else:
        su += C*B
        A = [A[i] for i in range(B,len(A))]
print(sum(A)+su)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
bisec = bisect_left
ex = A.extend
su =0
for i in range(M):
    if BC[i][1]<=A[0]:
        break
    B= BC[i][0]
    C = BC[i][1]
    b = bisec(A,C)
    if B>=b:
        su = C*b
        A = [A[i] for i in range(b,N)]
    else:
        su = C*B
        A = [A[i] for i in range(B,N)]
print(sum(A)+su)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
bisec = bisect_left
ex = A.extend
su =0
for i in range(M):
    if BC[i][1]<=A[0]:
        break
    B= BC[i][0]
    C = BC[i][1]
    b = bisec(A,C)
    if B>=b:
        su += C*b
        del A[:b]
    else:
        su += C*B
        del A[:B]
print(sum(A)+su)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC = sorted(BC,key= lambda x: x[1],reverse=True)
A.sort()
su = sum(A)
for i in range(M):
    if BC[i][1]<A[0]:
        break
    B= BC[i][0]
    C = BC[i][1]
    b = bisect_left(A,C)
    if B>=b:
        su = su-sum(A[:b]) +C*b
        del A[:b]
    else:
        su = su-sum(A[:B]) +C*B
        del A[:B]
print(su)