Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import heapq

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

B.sort(key=lambda B:B[1],reverse=True)
heapq.heapify(A)

for i in range(M):
    for j in range(B[i][0]):
        if A[0] < B[i][1]:
            heapq.heappop(A)
            heapq.heappush(A,B[i][1])
            print(A)
        else:
            break

print(sum(A))

Failing test case input:
10 2
0 8 0 7 100 4 10 33 24 5
3 15
4 47
1 2

Expected output:
390


Actual output:
[0, 5, 4, 7, 8, 100, 10, 33, 24, 47]
[4, 5, 10, 7, 8, 100, 47, 33, 24, 47]
[5, 7, 10, 24, 8, 100, 47, 33, 47, 47]
[7, 8, 10, 24, 47, 100, 47, 33, 47, 47]
[8, 15, 10, 33, 24, 100, 47, 47, 47, 47]
[10, 15, 47, 33, 15, 100, 47, 47, 47, 24]
[15, 15, 47, 33, 15, 100, 47, 47, 47, 24]
390


Fixed submission (verdict: Accepted):
import heapq

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

B.sort(key=lambda B:B[1],reverse=True)
heapq.heapify(A)

c = 0
for i in range(M):
    for j in range(B[i][0]):
        c += 1
        if c > N:
            break
        if A[0] < B[i][1]:
            heapq.heappop(A)
            heapq.heappush(A,B[i][1])
            
        else:
            break
    else:
        continue
    break
    
print(sum(A))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a = sorted(a)
bc = sorted(bc, key=lambda x: -x[1])
print(bc)
a_len = len(a)
i = 0
for one in bc:
    for j in range(one[0]):
        if i > a_len-1:
            break
        if a[i] > one[1]:
            break
        a[i] = one[1]
        i += 1
print(sum(a))

Failing test case input:
10 2
0 4 1 7 100 4 7 33 33 5
3 15
4 33
1 4

Expected output:
343


Actual output:
[[4, 33], [3, 15]]
343


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a = sorted(a)
bc = sorted(bc, key=lambda x: -x[1])
a_len = len(a)
i = 0
for one in bc:
    for j in range(one[0]):
        if i > a_len-1:
            break
        if a[i] > one[1]:
            break
        a[i] = one[1]
        i += 1
print(sum(a))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]))
for b,c in BC:
  A.sort()
  if A[0]>=c: break
  idx=bisect.bisect_left(A,c)
  for i in range(min(b,idx)):
    A[i]=c
print(sum(A))

Failing test case input:
3 2
5 1 1
2 3
1 0

Expected output:
11


Actual output:
7


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  for _ in range(b):
    if cnt>=n: break
    A.append(c)
    cnt+=1
A.sort(reverse=True)
print(sum(A[:n]))