Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1    
                        else:
                                break
                        if a_count == n:
                                        break

        else:
                break
        if a_count == n:
                break        

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1
                        else:
                                break

        else:
                break

        if a_count == n:
                break        

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
bc_count = 0
bc_len = len(bc)
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1
                        else:
                                break
        else:
                break
        bc_count += 1
        if bc_count == bc_len:
                break
        

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1
                        else:
                                break
        else:
                break

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1
                        else:
                                break
        else:
                break

        if a_count > len(bc):
                break


print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1
                        else:
                                break
        else:
                break


print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

d = []
loop = 0

while True:
        for b, c in bc:
                d.extend([c] * b)
                loop += 1
        if len(d) > n:
                break
        elif loop == m:
                break

while True:
        if a[0] < d[0]:
                a.append(d[0])
                del a[0]
                del d[0]
        else:
                break

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

#n, m = 10, 3
#a = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
#bc = [[3, 10], [4, 30], [1, 4]]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

d = []
loop = 0

while True:
        for b, c in bc:
                d.extend([c] * b)
                loop += 1
        if len(d) > n:
                break
        elif loop == m:
                break

while True:
        if a[0] < d[0]:
                a = a[1:]
                a.append(d[0])
                d = d[1:]
        else:
                break

print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

d = []
d_count = 0
loop = 0

while True:
        for b, c in bc:
                d.extend([c] * b)
                d_count += b
                loop += 1
        if d_count > n:
                break
        elif loop == m:
                break

a.extend(d)
a.sort(reverse = True)

print(sum(a[0:n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)

d = []
d_count = 0

while d_count <= n:
        for b, c in bc:
                d.extend([b for i in range(c)])
                d_count += c

ans = []

sort(a.extend(d), reverse = True)

for i in range(n):
        ans.append(a[i])

print(sum(ans))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = map(int, input().split())
bc = [[int(i) for i in input().split()] for i in range(m)]

for i in range(m):
        a.sort()
        bc_temp = bc[i]
        for j in range(bc_temp[0]):
                if a[j] < bc_temp[1]:
                        a[j] = bc_temp[1]

print(sum(a))