Problem p03038 (python)

Fixed submission:
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ind =0
for b,c in l[::-1]:
    mx = min(N,ind+b)
    for i in range(ind,mx):
        if c>A[i]:
            A[i] = c
    if mx==N:
        break
    ind += b
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ind =0
for b,c in l[::-1]:
    mx = min(N,ind+b)
    for i in range(ind,mx):
        if c>A[i]:
            A = A[1:].append(c)
    if mx==N:
        break
    ind += b
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B =[]
C =[]

l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ttl = 0
m_score = 0
flag =False
for i in l[::-1]:
    p = i[0]
    k = i[1]
    ttl+=p
    t = ttl-1
    if t>=N:
        print("WA")
        for n,j in enumerate(i[t-p+1:]):
            if j<k:
                m_score+=p
                break
        m_score += sum(A[t-p+1+n:])
        flag = True
        break
    if A[t]<k:
        m_score += p*k
        continue
    else:
        for n,j in enumerate(A[t-p+1:t+1]):
            if j>k:
                flag = True
                break
        if flag:
            m_score += k*n+sum(A[t-p+1+n:])
            break
if not flag:
    if ttl<N:
        m_score += sum(A[ttl:])
print(m_score)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B =[]
C =[]

l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ttl = 0
m_score = 0
flag =False
for i in l[::-1]:
    p = i[0]
    k = i[1]
    ttl+=p
    t = ttl-1
    if t>=N:
        for n,j in enumerate(i[t-p+1:]):
            if j<k:
                m_score+=p
                break
        m_score += sum(A[t-p+1+n:])
        flag = True
        break
    if A[t]<k:
        m_score += p*k
        continue
    else:
        for n,j in enumerate(A[t-p+1:t+1]):
            if j>k:
                flag = True
                break
        if flag:
            m_score += k*n+sum(A[t-p+1+n:])
            break
if not flag:
    if ttl<N:
        m_score += sum(A[ttl:])
print(m_score)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B =[]
C =[]

l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ttl = 0
m_score = 0
flag =False
for i in l[::-1]:
    p = i[0]
    k = i[1]
    ttl+=p
    t = ttl-1
    if t>=N:
        for n,j in enumerate(i[t-p+1:]):
            if j<k:
                m_score+=p
                break
        m_score += sum(A[t-p+1+n:])
        break
    if A[t]<k:
        m_score += p*k
        continue
    else:
        for n,j in enumerate(A[t-p+1:t+1]):
            if j>k:
                flag = True
                break
        if flag:
            m_score += k*n+sum(A[t-p+1+n:])
            break
if not flag:
    if ttl<N:
        m_score += sum(A[ttl:])
print(m_score)

Buggy submission (verdict: Runtime Error):
 map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B =[]
C =[]

l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ttl = 0
m_score = 0
flag =False
for i in l[::-1]:
    p = i[0]
    k = i[1]
    ttl+=p
    t = ttl-1
    if t>=N:
        t = N-1
    if A[t]<k:
        m_score += p*k
        continue
    else:
        for n,j in enumerate(A[t-p+1:t+1]):
            if j>k:
                flag = True
                break
        if flag:
            m_score += k*n+sum(A[t-p+1+n:])
            break
if not flag:
    if ttl<N:
        m_score += sum(A[ttl:])
print(m_scor

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B =[]
C =[]

l = [list(map(int,input().split())) for i in range(M)]

A.sort()
l = sorted(l,key = lambda x:x[1])

ttl = 0
m_score = 0
flag =False
for i in l[::-1]:
    p = i[0]
    k = i[1]
    ttl+=p
    t = ttl-1
    if A[t]<k:
        m_score += p*k
        continue
    else:
        for n,j in enumerate(A[t-p+1:t+1]):
            if j>k:
                flag = True
                break
        if flag:
            m_score += k*n+sum(A[t-p+1+n:])
            break
if not flag:
    if ttl<N:
        m_score += sum(A[ttl:])
print(m_score)