ZhenlongDai/ACPR huggingface dataset:
Problem: p03038
Buggy submission (PyPy3 (7.3.0), 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)]

BC.sort(reverse=True)
cnt = 0
for b, c in BC:
    if cnt == n:
        break
    if cnt + b > n:
        b = n-cnt
    cnt += b
    for _ in range(b):
        A.append(c)

A.sort(reverse=True)

print(sum(A[:n]))

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
11100006000


Fixed submission (verdict: Accepted):
from operator import itemgetter

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


BC.sort(reverse=True, key=itemgetter(1))
cnt = 0
for b, c in BC:
    if cnt + b > n:
        b = n-cnt
    for _ in range(b):
        A.append(c)
    cnt += b
    if cnt == n:
        break

A.sort(reverse=True)

print(sum(A[:n]))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = []
for i in range(m):
    b, c = map(int, input().split())
    d.append([b, c])
print(d)
d = sorted(d, key=lambda x: x[1], reverse=True)
print(d)
k = 0
for i in range(n):
    if d[k][0] == 0:
        k += 1
        if k == len(d):  
            break
    if a[i] >= d[k][1]:  
        break
    a[i] = d[k][1]  
    d[k][0] -= 1  
print(sum(a))

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

Expected output:
367


Actual output:
[[3, 15], [4, 39]]
[[4, 39], [3, 15]]
367


Fixed submission (verdict: Accepted):

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = []
for i in range(m):
    b, c = map(int, input().split())
    d.append([b, c])

d = sorted(d, key=lambda x: x[1], reverse=True)

k = 0
for i in range(n):
    if d[k][0] == 0:
        k += 1
        if k == len(d):  
            break
    if a[i] >= d[k][1]:  
        break
    a[i] = d[k][1]  
    d[k][0] -= 1  
print(sum(a))

Problem: p03038
Buggy submission (PyPy3 (2.4.0), 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)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

D=D[:N]
for i in range(len(D)):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    break
  


Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 14
8 30
1 4

Expected output:
383


Actual output:

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)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

D=D[:N]
for i in range(len(D)):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    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()))
a.sort()
bc = [list(map(int,input().split())) for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)

ad = 0
idx = 0
for b, c in bc:
    for i in range(min(b, n-idx)):
        if a[idx+i] < c:
            continue
        else:
            ad += c*i
            idx += i
            print(ad + sum(a[idx:]))
            exit()
    ad += c*b
    idx += b
print(ad + sum(a[idx:]))

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
13300006000


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

ad = 0
idx = 0
for b, c in bc:
    for i in range(min(b, n-idx)):
        if a[idx+i] < c:
            continue
        else:
            ad += c*i
            idx += i
            print(ad + sum(a[idx:]))
            exit()
    ad += c*min(b, n-idx)
    idx += min(b, n-idx)
print(ad + sum(a[idx:]))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
  heappush(q, [-x, 1])
for i in range(m):
  b, c = map(int, input().split())
  heappush(q, [-c, b])
r = []
k = 0
while k < n:
  c, b = heappop(q)
  c = -c
  r += [c] * b
  k += b
print(sum(r[-n:]))


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

Expected output:
301


Actual output:
211


Fixed submission (verdict: Accepted):
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
  heappush(q, [-x, 1])
for i in range(m):
  b, c = map(int, input().split())
  heappush(q, [-c, b])
r = []
k = 0
while k < n:
  c, b = heappop(q)
  c = -c
  r += [c] * b
  k += b
print(sum(r[:n]))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
BC=[list(map(int,input().split())) for _ in range(m)]
flag=0
for i in range(m):
    if flag==1:
        break
    else:
        while BC[i][0]>0:
            if BC[i][1] > a[0]:
                minA = heapq.heappop(a)
                heapq.heappush(a,BC[i][1])
                BC[i][0] -=1
            else:
                flag=1
                break
print(sum(a))

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

Expected output:
14

Actual output:
12


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
BC=[list(map(int,input().split())) for _ in range(m)]
BC.sort(reverse=True,key=lambda x:x[1])
for i in range(m):
    while BC[i][0]>0:
        if BC[i][1] > a[0]:
            minA = heapq.heappop(a)
            heapq.heappush(a,BC[i][1])
            BC[i][0] -=1
        else:
            break
print(sum(a))
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
A = [[1,int(a)] for a in input().split()]
BC = A + [list(map(int,input().split())) for _ in range(M)]

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

i = 0
ans = 0
for B,C in BC:
    if i + B <= N:
        ans += B*C
    else:
        ans += (N - i) * C
        break

print(ans)

Failing test case input:
11 3
0 1 1 1 0 1 1 1 1 1 1
3 1000001010
4 1000010000
3 1100000000

Expected output:
10300043031


Actual output:
10300043039


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
A = [[1,int(a)] for a in input().split()]
BC = A + [list(map(int,input().split())) for _ in range(M)]

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

i = 0
ans = 0
for B,C in BC:
    if i + B <= N:
        ans += B*C
        i += B
    else:
        ans += (N - i) * C
        break

print(ans)

Problem: p03038
Buggy submission (PyPy3 (2.4.0), 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)]
X = []
A.sort(reverse=True)
BC.sort(reverse=True,key=lambda x: x[1])
for b,c in BC:
    if len(X) > N:
        break
    for _ in range(b):
        X.append(c)
ans = 0
for i in range(N):
    val = sum(X[:i] + A[:N-i])
    if ans < val:
        ans = val
print(ans)




Failing test case input:
11 3
1 1 1 1 1 1 1 0 2 1 1
5 1000000000
4 1000000000
3 1000000001

Expected output:
11000000003


Actual output:
10000000005


Fixed submission (verdict: Accepted):
from collections import defaultdict
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
X = []
D = defaultdict(int)

for a in A:
    D[a] += 1
for b,c in BC:
    D[c] += b
ans = 0
for e in sorted(D.keys(),reverse=True):
    if D[e] >= N:
        ans += e*N
        break
    else:
        ans += e*D[e]
        N -= D[e]
print(ans)

Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
a = list(map(int, input().split()))

bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))

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

cnt = 0

for b, c in bc:
    cnt += b
    if cnt > n:
        break
    a += [c] * b

print(sum(sorted(a,reverse=True)[:n]))

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
9300006003


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
a = list(map(int, input().split()))

bc = []

for _ in range(m):
    b, c = map(int, input().split())
    bc.append((b, c))

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

cnt = 0

for b, c in bc:
    cnt += b
    a += [c] * b
    if cnt >= n:
        break

print(sum(sorted(a,reverse=True)[:n]))
Problem: p03038
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import deque
N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(M)]
bc.sort(key=lambda x:x[1])
for b,c in bc:
    while len(A) < 2*N and b > 0:
        b -= 1
        A.append(c)
    if len(A) == 2*N:
        break
A.sort(reverse=True)
print(sum(A[:N]))


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

Expected output:
413


Actual output:
411


Fixed submission (verdict: Accepted):
from collections import deque
N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(M)]
for x in A:
    bc.append((1,x))
bc.sort(key=lambda x:x[1], reverse=True)
A = []
for b,c in bc:
    while len(A) < N and b > 0:
        b -= 1
        A.append(c)
    if len(A) == N:
        break
A.sort(reverse=True)
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)]  
bc.sort(key=lambda x: x[1], reverse=True )

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

print(sum(a))

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

Expected output:
325


Actual output:
323


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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

c = []
for i in bc:
    for j in range(i[0]):
        c.append(i[1])
        
c.sort(reverse = True)

for i in c:
    cards.sort()
    if cards[0] < i:
        cards[0] = i
    else:
        break

Failing test case input:
11 3
1 1 1 1 1 1 1 0 1 1 1
3 1000000000
1 1000000000
3 1000000001

Expected output:
7000000007


Actual output:

Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
cards = [[1, int(i)] for i in input().split()]
bc = [list(map(int, input().split())) for _ in range(m)]
cards += bc
cards.sort(key = lambda x: x[1], reverse = True)

l = []
flag = 0
for i in cards:
    for j in range(i[0]):
        l.append(i[1])
        if len(l) == n:
            flag = 1
            break
    if flag:
        break

print(sum(l))
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            exit()
    i+=b
print(sum(a))

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

Expected output:
17


Actual output:

Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b
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()))
a.sort()
changer=[]
cl=0
flag=0
for i in range(m):
  b=list(map(int,input().split()))
  changer.append(b)
changer.sort(key=lambda x:x[1],reverse=True)
for i in range(m):
  if flag==1:
    break
  for j in range(cl,min(cl+changer[i][0],n)):
    if a[j]<changer[i][1]:
      a[j]=changer[i][1]
    else:
      flag=1
      break
print(sum(a))

Failing test case input:
11 3
1 1 1 1 0 1 1 1 1 1 1
3 1000001000
4 1000000000
3 1100000000

Expected output:
10300003001


Actual output:
3300000008


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
changer=[]
cl=0
flag=0
for i in range(m):
  b=list(map(int,input().split()))
  changer.append(b)
changer.sort(key=lambda x:x[1],reverse=True)
for i in range(m):
  if flag==1:
    break
  for j in range(cl,min(cl+changer[i][0],n)):
    if a[j]<changer[i][1]:
      a[j]=changer[i][1]
    else:
      flag=1
      break
  cl+=changer[i][0]
print(sum(a))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
anlist=[]
for a in map(int, input().split()):
    anlist.append([1,a])
for _ in range(M):
    anlist.append(list(map(int, input().split())))
anlist=sorted(anlist, key=lambda x: x[1], reverse=True)
cnt = 0
ans = 0
for b, c in anlist:
    if cnt + c > N:
        ans += b+(N-cnt)
        break
    else:
        ans +=b*c
print(ans)


Failing test case input:
3 2
100 110 100
3 82
3 99

Expected output:
310


Actual output:
4


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
anlist=[]
for a in map(int, input().split()):
    anlist.append([1,a])
for _ in range(M):
    anlist.append(list(map(int, input().split())))
anlist=sorted(anlist, key=lambda x: x[1], reverse=True)
cnt = 0
ans = 0
for b, c in anlist:
    if cnt + b > N:
        ans += c*(N-cnt)
        break
    else:
        ans +=b*c
        cnt += b
print(ans)
Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
T = []
for i in range(M):
    a,b = map(int,input().split())
    T.append([b,a])
T.sort(reverse=True)

ans = 0
c = 0
k = 0
t = len(T)
for i in range(N):
    if c == t:
        break
    n = T[c][0]
    l = T[c][1]
    k += 1
    if A[i] < n:
        A[i] = n
    else:
        break
    if k == l:
        c += 1
        k = 0
print(A)
print(sum(A))

Failing test case input:
10 2
0 8 0 7 100 4 10 33 13 5
5 15
4 21
1 4

Expected output:
277


Actual output:
[21, 21, 21, 21, 15, 15, 15, 15, 33, 100]
277


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
T = []
for i in range(M):
    a,b = map(int,input().split())
    T.append([b,a])
T.sort(reverse=True)

ans = 0
c = 0
k = 0
t = len(T)
for i in range(N):
    if c == t:
        break
    n = T[c][0]
    l = T[c][1]
    k += 1
    if A[i] < n:
        A[i] = n
    else:
        break
    if k == l:
        c += 1
        k = 0
print(sum(A))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def int_cards(cards, operations):
    cards = sorted(cards)
    operations.sort(reverse=True)
    for i in range(len(operations)):
        for j in range(operations[i][1]):
            if cards[j] > operations[i][0]:
                break
            cards.pop(0)
            cards.append(operations[i][0])
            
    print(sum(cards))
    
N, M = map(int, input().split())
A = list(map(int,input().split()))
operations = []
for i in range(M):
    B, C = map(int, input().split())
    operations.append([C, B])
    
int_cards(A, operations)

Failing test case input:
11 3
0 1 1 1 0 2 1 1 1 1 1
3 1000101000
4 1000000000
3 1100000000

Expected output:
10300303002


Actual output:
9300303003


Fixed submission (verdict: Accepted):
import collections

def int_cards(N, cards, operations):
    col_cards = collections.deque(sorted(cards), N)
    operations.sort(reverse=True)
    for c, b in operations:
        for _ in range(b):
            if col_cards[0] >= c:
                break
            col_cards.popleft()
            col_cards.append(c)
            
    print(sum(col_cards))
    
N, M = map(int, input().split())
A = list(map(int,input().split()))
operations = []
for i in range(M):
    B, C = map(int, input().split())
    operations.append([C, B])
    
int_cards(N, A, operations)
Problem: p03038
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

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

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1] and n < N - 1:
            A[n] = bc[i][1]
            n += 1
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
10300006002


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

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

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

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()))
BC = [list(map(int,input().split())) for _ in range(M)]
X = []

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

for b,c in BC:
    if len(X) > N:
        break
    for _ in range(b):
        X.append(c)

A.sort(reverse=True)

ans = 0
for i in range(min(len(X)+1,N)):
    val = sum(X[:i] + A[:N-i])
    if ans < val:
        ans = val
print(ans)




Failing test case input:
11 3
1 1 1 1 1 1 1 0 2 1 1
5 1000000000
4 1000000000
3 1000000001

Expected output:
11000000003


Actual output:
10000000005


Fixed submission (verdict: Accepted):
from collections import defaultdict
N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
X = []
D = defaultdict(int)

for a in A:
    D[a] += 1
for b,c in BC:
    D[c] += b
ans = 0
for e in sorted(D.keys(),reverse=True):
    if D[e] >= N:
        ans += e*N
        break
    else:
        ans += e*D[e]
        N -= D[e]
print(ans)

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
a = sorted([int(x) for x in input().split()])
p = []
for _ in range(m):
    b, c = map(int, input().split())
    p += [c]*b
sorted(p, reverse=True)
t = min(n, len(p))
for i in range(t):
    if a[i] < p[i]:
        a[i] = p[i]
        if i == n-1:
            break
    else:
        break
ans = sum(a)
print(ans)

Failing test case input:
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4

Expected output:
338

Actual output:
335


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
p = [(a[i], 1) for i in range(n)]

for i in range(m):
    b, c = map(int, input().split())
    p.append((c, b))
    
p.sort()
p.reverse()
ans, count = 0, n
for (s, t) in p:
    k = min(count, t)
    ans += s * k
    count -= t
    if count <= 0:
        break
    
print(ans)
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]  
bc.sort(key=lambda x: x[1], reverse=True )

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

        a[i] = c
        n += 1

print(sum(a))

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

Expected output:
16


Actual output:
5


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

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

N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
B = sorted(B, key = lambda x: x[1])

for i in range(N):  A[i] *= -1
heapq.heapify(A)
cnt = 0
for i in range(M):
    for _ in range(B[i][0]):  heapq.heappush(A, -max(-heapq.heappop(A), B[i][1]))
    cnt += B[i][0]
    if cnt >= N:  break
print(-sum(A))

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

Expected output:
358


Actual output:
198


Fixed submission (verdict: Accepted):
import heapq

N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
B = sorted(B, key = lambda x: x[1])[::-1]

heapq.heapify(A)
cnt = 0
for i in range(M):
    for _ in range(B[i][0]):  heapq.heappush(A, max(heapq.heappop(A), B[i][1]))
    cnt += B[i][0]
    if cnt >= N:  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()))
A.sort()
print(A)
X = [0 for i in range(N)]
CB = []
for i in range(M):
    b,c = map(int,input().split())
    CB.append([c,b])
CB.sort(reverse=True)
print(CB)
index = 0
for i in range(M):
    for j in range(CB[i][1]):
        A[index] = max(A[index],CB[i][0])
        if index != N - 1:
            index += 1
            continue
        else:
            print(sum(A))
            exit()
print(sum(A))

Failing test case input:
3 2
100 100 100
0 99
3 99

Expected output:
300


Actual output:
[100, 100, 100]
[[99, 3], [99, 0]]
300


Fixed submission (verdict: Accepted):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

X = [0 for i in range(N)]
CB = []
for i in range(M):
    b,c = map(int,input().split())
    CB.append([c,b])
CB.sort(reverse=True)

index = 0
for i in range(M):
    for j in range(CB[i][1]):
        A[index] = max(A[index],CB[i][0])
        if index != N - 1:
            index += 1
            continue
        else:
            print(sum(A))
            exit()
print(sum(A))
Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l = l+[c]*b
    if n < len(l):
        break
print(sorted(l))

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

Expected output:
334


Actual output:
[19, 19, 19, 30, 30, 30, 30]


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
n,m = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort()
bc=[None]*m
for i in range(m):
    bc[i] = list(map(int, input().split(" ")))
bc.sort(reverse=True, key=lambda x:x[1])
l=[]
for [b,c] in bc:
    l.extend([c]*b)
    if n < len(l):
        break
for i in range(n):
    if len(l) <= i or l[i] <= a[i]:
        break
    a[i] = l[i]
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=[]
for m in range(M):
    b,c=map(int,input().split())
    BC.append([b,c])

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

D=[]
for [b,c] in BC:
    D+=[c]*b
    if len(D)>N:
        break

if len(D)<N:
    D+=[0]*(N-len(D))

for i in range(N):
    if A[i]>D[i]:
        break

print(sum(D[:i]+A[i:]))

Failing test case input:
11 3
1 1 1 1 1 1 1 0 2 1 1
5 1000000000
4 1000000000
3 1000000001

Expected output:
11000000003


Actual output:
10000000005


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
A=list(map(int,input().split()))

BC=[]
for m in range(M):
    b,c=map(int,input().split())
    BC.append([b,c])

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

D=[]
for [b,c] in BC:
    D+=[c]*b
    if len(D)>N:
        break

if len(D)<N:
    D+=[0]*(N-len(D))

AD=[max(A[i],D[i]) for i in range(N)]
 
print(sum(AD))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = map(int , input().split())
data = sorted(list(map(int , input().split())))
A=[list(map(int , input().split())) for _ in range(M)]
change_list = sorted(A, key=lambda x:x[1])
cnt_total = 0

for i,x in reversed(change_list):
	for j in range(i):
		if data[cnt_total] <=x:
			data[cnt_total] =x
		else:
			print(sum(data))
			exit()

		cnt_total += 1
		if cnt_total == N:
			print(sum(data))
			exit()

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

Expected output:
352


Actual output:

Fixed submission (verdict: Accepted):
N,M = map(int , input().split())
data = sorted(list(map(int , input().split())))
A=[list(map(int , input().split())) for _ in range(M)]
change_list = sorted(A, key=lambda x:x[1])
cnt_total = 0

for i,x in reversed(change_list):
	for j in range(i):
		if data[cnt_total] <=x:
			data[cnt_total] =x
		else:
			print(sum(data))
			exit()

		cnt_total += 1
		if cnt_total == N:
			print(sum(data))
			exit()
			
print(sum(data))
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())

A = list(map(int, input().split()))

count = 0
B = []
for i in range(M):
    b, c = map(int, input().split())
    if count >= N:
        break
    for j in range(b):
        B.append(c)
        count += 1
        if count >= N:
            break

A.sort()
B.sort(reverse=True)
for i in range(min(N, len(B))):
    if A[i] < B[i]:
        A[i] = B[i]

ans = sum(A)
print(ans)

Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 14
8 30
1 4

Expected output:
383


Actual output:
367


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())

A = list(map(int, input().split()))

count = 0
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))

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

count = 0
CArr = []
for b, c in BC:
    if count >= N:
        break
    for i in range(b):
        CArr.append(c)
        count += 1
        if count >= N:
            break

for i in range(len(CArr)):
    if A[i] < CArr[i]:
        A[i] = CArr[i]

ans = sum(A)
print(ans)

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())

A = list(map(int, input().split()))

BC = []

for j in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
sorted_BC = sorted(BC, reverse=True, key=lambda item: item[1])

candidate = []
count = N
for bc in sorted_BC:
    b = bc[0]
    c = bc[1]
    if count - b >= 0:
        candidate.extend([c] * b)
        count = count - b
    else:
        break
    
candidate.extend(A)

print(sum(sorted(candidate, reverse=True)[:N]))

Failing test case input:
11 3
1 1 1 1 1 1 1 0 2 1 1
5 1000000000
4 1000000000
3 1000000001

Expected output:
11000000003


Actual output:
8000000007


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())

A = list(map(int, input().split()))

BC = []

for j in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
sorted_BC = sorted(BC, reverse=True, key=lambda item: item[1])

candidate = []
count = N
for bc in sorted_BC:
    b = bc[0]
    c = bc[1]
    if count >= 0:
        candidate.extend([c] * b)
        count = count - b
    else:
        break
    
candidate.extend(A)

print(sum(sorted(candidate, reverse=True)[:N]))
Problem: p03038
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[bc[i][0] - 1] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

print(sum(a))

Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 22
5 30
1 4

Expected output:
359


Actual output:
324


Fixed submission (verdict: Accepted):
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

print(sum(a))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
CB=[]
for i in range(M):
  B,C = map(int,input().split())
  CB +=[[C,B]]

for j in range(N):
  CB +=[[A[j],1]]

CB=sorted(CB,reverse = True)
count = 0
result =0
print(CB)
i=0
while count<N:
  count +=CB[i][1]
  result +=CB[i][0]*CB[i][1]
  i +=1

result -= (count-N)*(CB[i-1][0])
print(result)

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

Expected output:
299


Actual output:
[[100, 1], [33, 1], [30, 4], [24, 1], [8, 1], [7, 1], [7, 1], [5, 1], [5, 1], [4, 3], [4, 1], [0, 1]]
299


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
CB=[]
for i in range(M):
  B,C = map(int,input().split())
  CB +=[[C,B]]

for j in range(N):
  CB +=[[A[j],1]]

CB=sorted(CB,reverse = True)
count = 0
result =0

i=0
while count<N:
  count +=CB[i][1]
  result +=CB[i][0]*CB[i][1]
  i +=1

result -= (count-N)*(CB[i-1][0])
print(result)

Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,t):
      a[j]=bc[i][1]
    s=t-1
  else:
    break
print(sum(a))

Failing test case input:
11 1
-1 1 2 2 1 1 1 0 1 1 1
1 1000000000
4 0010101010
3 1000000001

Expected output:
1000000011


Actual output:
11000000000


Fixed submission (verdict: Accepted):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
s=0
for i in range(m):
  if a[s]<bc[i][1]:
    t=bisect.bisect_left(a,bc[i][1],s,n)
    for j in range(s,min(t,s+bc[i][0])):
      a[j]=bc[i][1]
    s=min(t,s+bc[i][0])
    if s>=n:
      break
  else:
    break
print(sum(a))
Problem: p03038
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import Counter
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))
for i in range(M):
    b,c = map(int,input().split())
    if c in A.keys():
        A[c] += b
    else:
        A[c] = b
A = sorted(A.items(),reverse=True)
check = N
ans = 0
for i in A:
    if i[1]<check:
        check -= i[1]
        ans += (i[0] * i[1])
    else:
        ans += i[1] * check
print(ans)


Failing test case input:
10 3
1 8 5 7 000 4 52 39 13 5
1 10
4 30
0 4

Expected output:
249


Actual output:
248


Fixed submission (verdict: Accepted):
from collections import Counter
n,m=map(int,input().split())
d=Counter(list(map(int,input().split())))
for i in range(m):
    b,c=map(int,input().split())
    if c in d:
        d[c]+=b
    else:
        d[c]=b
d=sorted(Counter(d).items(),reverse=True)
check=n
ans=0
for i in d:
    if i[1]<check:
        check-=i[1]
        ans+=(i[0]*i[1])
    else:
        ans+=(i[0]*check)
        print(ans)
        break

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

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        tmp = heapq.heappop(A_LIST)
        if c < tmp:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))


Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 14
8 30
1 4

Expected output:
383


Actual output:
197


Fixed submission (verdict: Accepted):
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))

Problem: p03038
Buggy submission (PyPy3 (2.4.0), 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.sort()
BC.sort(key=lambda x:x[1],reverse=True)
for i in range(m):
    for j in range(BC[i][0]):
        A[j]=max(A[j],BC[i][1])

print(sum(A))


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

Expected output:
298


Actual output:
290


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.sort()
BC.sort(key=lambda x:-x[1])

B=[]
for bc in BC:
    B+=[bc[1]]*bc[0]
    if len(B)>=N:
        break
B+=[0]*(N-len(B))
print(sum([max(A[i],B[i]) for i in range(N)]))
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
BC = []
for m in range(M):
    BC.append([int(i) for i in input().split()])
    if BC[m][0] > N:
        BC[m][0] = N
BC = sorted(BC,reverse=True)
change_list = []
for m in range(M):
    change_list.extend([BC[m][1] for _ in range(BC[m][0])])
    if len(change_list) >= N:
        change_list = change_list[0:N]
        break
A.extend(change_list)
A = sorted(A,reverse=True)
print(sum(A[0:N]))

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
11100006000


Fixed submission (verdict: Accepted):
N,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
BC = []
for m in range(M):
    BC.append([int(i) for i in input().split()])
    if BC[m][0] > N:
        BC[m][0] = N
BC = sorted(BC,reverse=True,key=lambda x: x[1])
change_list = []
for m in range(M):
    change_list.extend([BC[m][1] for _ in range(BC[m][0])])
    if len(change_list) >= N:
        change_list = change_list[0:N]
        break
A.extend(change_list)
A = sorted(A,reverse=True)
print(sum(A[0:N]))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys 
input = sys.stdin.readline
from heapq import *
def main():
  n, m = map(int, input().split())
  A = list(map(int, input().split()))
  BC = []
  for i in range(m):
    BC.append(list(map(int, input().split())))
  heapify(A)
  BC.sort(key = lambda x:x[1], reverse = True)
  for j in range(m):
    for _ in range(BC[i][0]):
      if BC[i][1]>A[0]:
        heappushpop(A, BC[i][1])
      else:
        break
  print(sum(A))
if __name__ == '__main__':
  main()


Failing test case input:
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1100000000

Expected output:
10300000001


Actual output:
11000000000


Fixed submission (verdict: Accepted):
import sys 
input = sys.stdin.readline
from heapq import *
def main():
  n, m = map(int, input().split())
  a = list( map(int, input().split()) )
  card = []
  for _ in range(m):
    card.append(list(map(int, input().split())))

  heapify(a)
  card.sort(key=lambda x:x[1], reverse=True)

  for i in range(m):
    for _ in range(card[i][0]):
      if a[0]<card[i][1]:
        heappushpop(a, card[i][1])
      else:
        break
  print(sum(a))

if __name__ == '__main__':
  main()
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque

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

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)

print(A)

sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break
        print(sum)

print(sum)

Failing test case input:
10 1
0 0 1 7 101 4 7 33 33 5
3 15
4 35
1 4

Expected output:
235


Actual output:
[[1, 101], [1, 33], [1, 33], [3, 15], [1, 7], [1, 7], [1, 5], [1, 4], [1, 1], [1, 0], [1, 0]]
101
134
167
212
219
226
231
235
235


Fixed submission (verdict: Accepted):
from collections import deque

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

BC = [list(map(int, input().split())) for i in range(M)]
A.extend(BC)
A = list(A)
A.sort(key=lambda x: x[1], reverse=1)


sum = 0
k = 0
for b, c in A:
        if k + b <= N:
                sum += b * c
                k += b
        elif k <= N:
                sum += (N - k) * c
                break

print(sum)

Problem: p03038
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

data = [None] * m
for i in range(m):
    data[i] = list(map(int, input().split()))
data.sort(key = lambda x : x[1])
data.reverse()


ans = 0
count = 0

for i in range(m):
    insert_index = bisect.bisect_left(a, data[i][1])
    if insert_index == 0:
        break
    count = min(data[i][0], insert_index)
    ans += count * data[i][1]
print(ans + sum(a))


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

Expected output:
307


Actual output:
343


Fixed submission (verdict: Accepted):
import bisect
n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

data = [None] * m
for i in range(m):
    data[i] = list(map(int, input().split()))
data.sort(key = lambda x : x[1])
data.reverse()


ans = 0
count = 0
pre_index = 0



for i in range(m):
    insert_index = bisect.bisect_left(a, data[i][1])
    count = min(data[i][0], insert_index - pre_index)
    for j in range(pre_index, pre_index + count):
        if j >= n:
            break
        a[j] = 0
    ans += count * data[i][1]
    pre_index = pre_index + count
print(ans + 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=[]
for m in range(M):
    b,c=map(int,input().split())
    BC.append([b,c])

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

D=[]
for [b,c] in BC:
    D+=[c]*b
    if len(D)>N:
        break

for i in range(min(len(A),len(D))):
    if A[i]>D[i]:
        break

print(sum(D[:i]+A[i:]))

Failing test case input:
11 3
0 0 1 1 0 1 1 1 1 1 1
3 1000001010
4 1000010100
3 1100000000

Expected output:
10300043431


Actual output:
9300042422


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
A=list(map(int,input().split()))

BC=[]
for m in range(M):
    b,c=map(int,input().split())
    BC.append([b,c])

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

D=[]
for [b,c] in BC:
    D+=[c]*b
    if len(D)>N:
        break

if len(D)<N:
    D+=[0]*(N-len(D))

AD=[max(A[i],D[i]) for i in range(N)]
 
print(sum(AD))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []

for _ in range(m):
    bc.append(list(map(int,input().split())))

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

print(a)
print(bc)

for i in range(m):
    count = 0
    for j in range(n):
        if bc[i][1] > a[j] and count < bc[i][0]:
            a[j] = bc[i][1]
            count += 1

print(sum(a))

Failing test case input:
11 1
-1 1 3 2 1 1 1 0 1 1 1
1 1000000000
4 0010101010
3 1000000001

Expected output:
1000000012


Actual output:
[-1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 3]
[[1, 1000000000]]
1000000012


Fixed submission (verdict: Accepted):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []

for _ in range(m):
    bc.append(list(map(int,input().split())))

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

for b,c in bc:
    a.extend([c]*b)
    if len(a) > n*2:
        break
a.sort(reverse=True)
print(sum(a[:n]))
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
  b,c = map(int,input().split()) 
  d.extend([c]*b)
d=d[::-1]
for i in range(len(d)):
  for j in range(n):
    if a[j] < d[i]:
      a[j]=d[i]
      break
print(sum(a))

Failing test case input:
11 3
1 1 1 1 1 1 1 0 2 1 1
3 1000000000
4 1010001000
3 1000000001

Expected output:
10040004005


Actual output:
7040004005


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1])
for b,c in bc[::-1]:
  a.extend([c]*b)
  if len(a)>2*n:
    break
a.sort(reverse=True)
print(sum(a[:n]))

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from heapq import heappush,heappop

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

def tempchange(l,change):
  for B,C in change:
    for j in range(B):
      a = heappop(l)
      if C - a > 0:
        heappush(l,C)
      else:
        heappush(l,a)
        break
  return sum(l)


change.sort(key = lambda x:x[1],reverse =True)
print(tempchange(A,change))

Failing test case input:
3 2
15 1 1
0 3
2 6

Expected output:
27


Actual output:
17


Fixed submission (verdict: Accepted):
from heapq import heappush,heappop,heapify

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

def tempchange(l,change):
  heapify(l)  
  for B,C in change:
    for j in range(B):
      a = heappop(l)
      if C - a > 0:
        heappush(l,C)
      else:
        heappush(l,a)
        break
  return sum(l)


change.sort(key = lambda x:x[1],reverse =True)
print(tempchange(A,change))

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 i in range(M)]

T=[]
count=0
for m in range(M):
    count+=BC[m][0]
    if count>N:
        
        t=[BC[m][1]]*(N-count+BC[m][0])
        break
    else:
        t=[BC[m][1]]*BC[m][0]
        T=T+t


D=A+T
D=sorted(D,reverse=True)

ANS=sum(D[:N])

print(ANS)


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

Expected output:
17


Actual output:
11


Fixed submission (verdict: Accepted):
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for i in range(M)]
BC=sorted(BC,key=lambda x:x[1],reverse=True)

T=[0]*N
count=0
cntmp=0
for m in range(M):
    count+=BC[m][0]
    if count>N:
        T[cntmp:]=[BC[m][1]]*(N-count+BC[m][0])
        break
    else:
        T[cntmp:count]=[BC[m][1]]*BC[m][0]
    cntmp=count





D=A+T
D=sorted(D,reverse=True)

ANS=sum(D[:N])

print(ANS)
Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n,m=map(int,input().split())
a=sorted(list(nii()))

l=[]
for i in range(m):
  b,c=nii()
  l+=[c]*b
l=sorted(l[:n],reverse=True)
l_len=len(l)
if l_len<n:
 l+=[0]*(n-l_len)

ans=0
for i in range(n):
  ans+=max(a[i],l[i])
print(ans)

Failing test case input:
11 3
1 1 1 1 0 2 1 1 1 1 1
6 1000001000
4 1000000000
3 1100000000

Expected output:
11300006000


Actual output:
11100006000


Fixed submission (verdict: Accepted):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n,m=map(int,input().split())
a=sorted(list(nii()))
l=[list(nii()) for i in range(m)]
l=sorted(l,key=lambda x:x[1],reverse=True)

man=[]
num=0
for b,c in l:
  man+=[c]*b
  num+=b
  if num>n:
    break

ans=0
for i in range(n):
  if i<num:
    ans+=max(a[i],man[i])
  else:
    ans+=a[i]
print(ans)

Problem: p03038
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
A = [[1,int(a)] for a in input().split()]
BC = A + [list(map(int,input().split())) for _ in range(M)]

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

i = 0
ans = 0
for B,C in BC:
    if i + B <= N:
        ans += B*C
    else:
        ans += (N - i) * C

print(ans)

Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 14
5 30
1 4

Expected output:
335


Actual output:
389


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
A = [[1,int(a)] for a in input().split()]
BC = A + [list(map(int,input().split())) for _ in range(M)]

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

i = 0
ans = 0
for B,C in BC:
    if i + B <= N:
        ans += B*C
        i += B
    else:
        ans += (N - i) * C
        break

print(ans)

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(list(map(int,input().split())) for i in range(m))

a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
t = 0
for i in range(m):
    for j in range(bc[i][0]):
        if t != n:
            if a[t] < bc[i][1]:
                a[t] = bc[i][1]
                t+=1
    else:
        break

print(sum(a))


Failing test case input:
10 2
0 8 5 7 110 4 7 33 13 10
3 10
4 30
1 4

Expected output:
306


Actual output:
301


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

a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
t = 0
for i in range(m):
    for j in range(bc[i][0]):
        if t != n:
            if a[t] < bc[i][1]:
                a[t] = bc[i][1]
                t+=1
            else:
                break
        else:
            break
    else:
        continue
    break

print(sum(a))