Problem p03038 (python)

Fixed submission:
import sys
import heapq

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = [list(map(int,input().split())) for _ in range(m)]

d.sort(key=lambda x:-x[1])
total = sum(A)
heapq.heapify(A)

for i in range(m):
    for j in range(d[i][0]):
        tmp = heapq.heappushpop(A, d[i][1])
        if tmp < d[i][1]:
                total += (d[i][1] - tmp)
        else:
            break

print(total)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = [list(map(int,input().split())) for _ in range(m)]

d.sort(key=lambda x:-x[1])
total = sum(A)
heapq.heapify(A)

for i in range(m):
    for j in range(d[i][0]):
        tmp = heapq.heappushpop(A, d[i][1])
        if tmp < d[i][1]:
                total += (d[i][1] - tmp)
        else:
            break

print(total)

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = [list(map(int,input().split())) for _ in range(m)]

d.sort(key=lambda x:-x[1])
total = sum(A)
heapq.heapify(A)

for i in range(m):
    for j in range(d[i][0]):
        tmp = heapq.heappushpop(A, d[i][1])
        if tmp < d[i][1]:
                total += (d[i][1] - tmp)
            else:
                break

print(total)

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

for c, b in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    if b > n:
        b = n
    if A[0] < c:
        if A[b] > c:
            f=0
            for i in range(b):
                if A[i] // c == 0:
                    f = i
                else:
                    break
            A[:f+1]=[c]*(f+1)
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

for c, b in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    if b > n:
        b = n

    if A[0] < c:
        if A[b] > c:
            for i in range(A):
                if i // c == 0:
                    f = i
                else:
                    break
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

for c, b in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    if b > n:
        b = n

    if A[0] < c:
        if A[b] > c:
            for i in range(A):
                if i // c == 0:
                    f = i
                break
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

for c, b in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    if b > n:
        b = n

    if A[0] < c:
        if A[b] > c:
            for i in range(b):
                if i // c == 0:
                    f = i
                break
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

print(d)

for c, b in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    print(A)
    if b > n:
        b = n

    if A[0] < c:
        if A[b-1] > c:
            for i in range(b):
                if i // c == 0:
                    f = i
                break
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

print(d)

for c, d in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    print(A)
    if b <= n and A[0] < c:
        if A[b-1] > c:
            for i in range(b):
                if i//c:
                    break
                f = i
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for j in range(m):
    A.sort()
    b,c = map(int, input().split())
    if b <= n:
        if A[b] > c:
            for i in range(c):
                if A[0] < c-i:
                    f = my_index(A, c-i)
                    if f != -1:
                        A[:f]=[c]*f
                        break
                else:
                    break
        else:
            A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for j in range(m):
    A.sort()
    b,c = map(int, input().split())
    if A[b] > c:
        for i in range(c):
            if A[0] < c-i:
                f = my_index(A, c-i)
                if f != -1:
                    A[:f]=[c]*f
                    break
            else:
                break
    else:
        A[:b]=[c]*b


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for j in range(m):
    A.sort()
    b,c = map(int, input().split())
    if A[0] < c:
        if A[b] > c:
            for i in range(c):
                f = my_index(A, c-i)
                if f != -1:
                    A[:f]=[c for k in range(f)]
                    break
        else:
            A[:b]=[c for k in range(b)]


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1


input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for i in range(m):
    A.sort()
    b,c = map(int, input().split())
    if A[0] < c:
        if A[b] > c:
            A = [c if i < c else i for i in A]
        else:
            A[:b] = [c for i in range(b)]


print(sum(A))

Buggy submission (verdict: Runtime Error):
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1


input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))

for i in range(m-1):
    A.sort()
    b,c = map(int, input().split())
    if A[b] > c:
        A = [c if i < c else i for i in A]
    else:
        A[:b] = [c for _ in range(b)]


print(sum(A))