Problem p03038 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    print("----")
    cnt = 0
    Flag = True
    while Flag:
        print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index > n - 1):
                Flag = False
        else:
            break
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#print(A)
minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
for b,c in Query:
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    #print(A)
print(ans + sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#print(A)
minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
for b,c in Query:
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        ans += c * index
        A = A[index:]
    #print(A)
print(ans + sum(A))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#Query = []
#for _ in range(m):
#    b,c = map(int,input().split())
#    Query.append([c,b])
#Query.sort(reverse=True)
Query = [list(map(int,input().split())) for _ in range(m)]
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)
ans = 0
for b,c in Query:
    #b,c = Query[i][1],Query[i][0]
    #b,c = Query[i][0],Query[i][1]
    if A[0] >= c:
        break
    else:
        #A.sort()
        index = bisect.bisect_left(A,c)
        ans += sum(A[index:])
        if b <= index:
            #for i in range(b):
            #    A[i] = c
            A = A[b:index].extend([c for i in range(b)])
        else:
            #for i in range(index):
            #    A[i] = c
            A = [ c for i in range(index)]
    #print(A)
print(ans + sum(A))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
cards = list(map(int,input().split()))
cards.sort()
actions = []
#print()
#print(cards)
ans  = sum(cards)
for i in range(m):
    l,r  = map(int,input().split())
    actions.append([r,l])
actions.sort(reverse=True)
start = 0
for i in range(m):
    minnum = min(cards)
    if actions[i][0] <= minnum:
        break
    else:
        for j in range(actions[i][1]):
            #print(cards[j])
            if cards[start+j] <= actions[i][0]:
                #cards[start+j] = actions[i][0] - cards[start+j]
                ans += actions[i][0] - cards[start+j]
            else:
                break
    start += actions[i][1]
    #print(cards)
#print(sum(cards))
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
cards = list(map(int,input().split()))
cards.sort()
actions = []
#print()
#print(cards)
ans  = sum(cards)
for i in range(m):
    l,r  = map(int,input().split())
    actions.append([r,l])
actions.sort(reverse=True)
start = 0
for i in range(m):
    minnum = min(cards)
    if actions[i][0] <= minnum:
        break
    else:
        for j in range(actions[i][1]):
            #print(cards[j])
            if cards[start+j] <= actions[i][0]:
                #cards[start+j] = actions[i][0] - cards[start+j]
                ans += actions[i][0] - cards[start+j]
            else:
                break
    start += actions[i][1]
    #print(cards)
#print(sum(cards))
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
cards = list(map(int,input().split()))
cards.sort()
actions = []
#print()
#print(cards)
for i in range(m):
    l,r  = map(int,input().split())
    actions.append([r,l])
actions.sort(reverse=True)
start = 0
for i in range(m):
    minnum = min(cards)
    if actions[i][0] <= minnum:
        break
    else:
        for j in range(actions[i][1]):
            #print(cards[j])
            if cards[start+j] <= actions[i][0]:
                cards[start+j] = actions[i][0]
            else:
                break
    start += actions[i][1]
    #print(cards)
print(sum(cards))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
cards = list(map(int,input().split()))
cards.sort()
actions = []
#print()
#print(cards)
for i in range(m):
    l,r  = map(int,input().split())
    actions.append([r,l])
actions.sort(reverse=True)
start = 0
for i in range(m):
    #minnum = min(cards)
    if actions[i][0] <= cards[start]:
        break
    else:
        for j in range(actions[i][1]):
            #print(cards[j])
            if cards[start+j] <= actions[i][0]:
                cards[start+j] = actions[i][0]
            else:
                break
    start += actions[i][1]
    print(cards)
print(sum(cards))