Problem p03038 (python)

Fixed submission:
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
take =[[-1] for i in range(M)]
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

#
A.sort()
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if ind[i-1] >=N:
        break
    elif A[ind[i-1]] >=take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break
print(sum(A))

Buggy submission (verdict: Runtime Error):
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
take =[[-1] for i in range(M)]
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

#
A.sort()
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if ind[i-1] >N:
        break
    elif A[ind[i-1]] >take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break
print(sum(A))

Buggy submission (verdict: Runtime Error):
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
#A =np.array(A,dtype=np.int64)
take =[[-1] for i in range(M)]
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

#
A.sort()
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if A[ind[i-1]] >take[i][1]:
        break
    for j in range(ind[i-1],ind[i]):
        if A[j] <take[i][1]:
            A[j] =take[i][1]
        else:
            break
    #A[ind[i-1]:ind[i]] =np.where(A[ind[i-1]:ind[i]] < take[i][1] ,take[i][1],A[ind[i-1]:ind[i]])
print(sum(A))

Buggy submission (verdict: Runtime Error):
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
A =np.array(A,dtype=np.int64)
take =[[-1] for i in range(M)]
#num =[-1]*M
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C
    #num[i] =C

#
A.sort()
#take =[0] +take
#num =[0] +num
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if A[ind[i-1]] >take[i][1]:
        break
    A[ind[i-1]:ind[i]] =np.where(A[ind[i-1]:ind[i]] < take[i][1] ,take[i][1],A[ind[i-1]:ind[i]])
print(sum(A))

Buggy submission (verdict: Runtime Error):
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
A =np.array(A,dtype=int)
take =[[-1] for i in range(M)]
#num =[-1]*M
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C
    #num[i] =C

#
A.sort()
#take =[0] +take
#num =[0] +num
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
for i in range(1,M): #初項に「０」足したから「M]まで
    st =take[i-1][0]
    fi =take[i-1][0] +take[i][0]
    if A[st] >take[i][1]:
        break
    A[st:fi] =np.where(A[st :fi] < take[i][1] ,take[i][1],A[st:fi])
print(sum(A))