Problem p03038 (python)

Fixed submission:

def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    
    flag = False
    ans = 0
    for b,c in targetList:
        for j in range(b):
            if N > tmpC and A[tmpC] < c:
                ans += c
                tmpC +=1
            else:
                flag = True
                break
        if flag:
            break
    
    if tmpC < N:

        ans += sum(A[tmpC:])


    print(ans)






if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    
    flag = False
    ans = 0
    for b,c in targetList:
        for j in range(b):
            if A[tmpC] < c and N > tmpC:
                ans += c
                tmpC +=1
            else:
                flag = True
                break
        if flag:
            break
    
    if tmpC < N:

        ans += sum(A[tmpC:])


    print(ans)






if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    
    flag = False
    ans = 0
    for b,c in targetList:
        for j in range(b):
            if A[tmpC] < c and N > tmpC:
                ans += c
                tmpC +=1
            else:
                flag = True
                break
        if flag:
            break
    
    if flag < N:

        ans += sum(A[tmpC:])


    print(ans)






if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpB = []
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    ans = 0
    for b,c in targetList:
        for j in range(b):
            if A[tmpC] < c and N > tmpC:
                A[tmpC] = c
                tmpC +=1


    print(sum(A))






if __name__== "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpB = []
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    for i in range(M):
        for j in range(targetList[i][0]):
            if A[tmpC] < targetList[i][1] and N > tmpC:
                A[tmpC] = targetList[i][1]
                tmpC +=1


    print(sum(A))






if __name__== "__main__":
    main()