Problem:


Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74



Sample input:
1 2 2 2 1
2 4
5 1
3


Sample output:
12

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())
r_arr = sorted(list(map(int,input().split())))[::-1][:X+1]
g_arr = sorted(list(map(int,input().split())))[::-1][:Y+1]
r_arr = list(map(int,input().split()))

print(sum(sorted(r_arr + g_arr + r_arr)[::-1][:X+Y+1]))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, insort_left
import sys
def main():
	readlines = sys.stdin.readline
	x,y,a,b,c = map(int,input().split())

	p = list(map(int,input().split()))
	q = list(map(int,input().split()))
	r = list(map(int,input().split()))

	p.sort()
	q.sort()
	r.sort(reverse=True)

	p = p[a-x:]
	q = q[b-y:]
	a = len(p)
	b = len(q)
	ans = sum(p) + sum(q)
	p_count = 0
	q_count = 0

	for i in range(c):
		if p[p_count] < r[i] and q[q_count] < r[i]:
			if p[p_count] < q[q_count]:
				ans -= p[p_count]
				ans += r[i]
				#insort_left(p,r[i])
				if p_count < a-1:
					p_count += 1
			else:
				ans -= q[q_count]
				ans += r[i]
				#insort_left(q,r[i])
				if q_count < b-1:
					q_count += 1
		elif p[p_count] < r[i]:
			ans -= p[p_count]
			ans += r[i]
			#insort_left(p,r[i])
			if p_count < a-1:
				p_count += 1
		elif q[q_count] < r[i]:
			ans -= q[q_count]
			ans += r[i]
			#insort_left(q,r[i])
			if q_count < b-1:
				q_count += 1
		else:
			break

	print(ans)
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, insort_left
from collections import deque

x,y,a,b,c = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort()

p = deque(p[a-x:])
q = deque(q[b-y:])
ans = sum(p) + sum(q)

for i in range(c):
	if p[0] < r[i] and q[0] < r[i]:
		if p[0] < q[0]:
			ans -= p.popleft()
			ans += r[i]
			insort_left(list(p),r[i])
			p = deque(p)
		else:
			ans -= q.popleft()
			ans += r[i]
			insort_left(list(q),r[i])
			q = deque(q)
	elif p[0] < r[i] and q[0] >= r[i]:
		ans -= p.popleft()
		ans += r[i]
		insort_left(list(p),r[i])
		p = deque(p)
	elif p[0] >= r[i] and q[0] < r[i]:
		ans -= q.popleft()
		ans += r[i]
		insort_left(list(q),r[i])
		q = deque(q)

print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,raw_input().split(' '))

aas = map(int, raw_input().split(' '))
bbs = map(int, raw_input().split(' '))
ccs = map(int, raw_input().split(' '))
aas.sort(key = lambda x:-x)
bbs.sort(key = lambda x:-x)
ccs.sort(key = lambda x:-x)

for i in range(1,len(aas)): aas[i] += aas[i-1]
for i in range(1,len(bbs)): bbs[i] += bbs[i-1]
for i in range(1,len(ccs)): ccs[i] += ccs[i-1]


r = 0
for a in range(x+1):
	for b in range(y+1):
		m = (aas[a-1] if a-1 >= 0 else 0) + (bbs[b-1] if b-1 >=0 else 0)
		c = x + y - (a + b)
		if c > 0 and c-1 < len(ccs): 	 	
			m += ccs[c-1]
		else: 
			if c: m+= -float('inf')
		print a,b,c,m
		r = max(r, m)

print r

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,raw_input().split(' '))

aas = map(int, raw_input().split(' '))
bbs = map(int, raw_input().split(' '))
ccs = map(int, raw_input().split(' '))
aas.sort(key = lambda x:-x)
bbs.sort(key = lambda x:-x)
ccs.sort(key = lambda x:-x)

for i in range(1,len(aas)): aas[i] += aas[i-1]
for i in range(1,len(bbs)): bbs[i] += bbs[i-1]
for i in range(1,len(ccs)): ccs[i] += ccs[i-1]

r = 0
for a in range(x+1):
	for b in range(y+1):

		m = (aas[a-1] if a-1 >= 0 else 0) + (bbs[b-1] if b-1 >=0 else 0)
		c = x+y - (a + b)
		if c >0 and c-1 < len(ccs): 	 	
			m += ccs[c-1]
		else: 
			m+= -float('inf')
		r = max(r, m)

print r

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c=list(map(int,input().split()))
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la=sorted(la)
lb=sorted(lb)
lc=sorted(lc)
laq=deque()
lbq=deque()
lcq=deque()
for ii in range(a):
    laq.append(la[ii])
for ij in range(b):
    lbq.append(lb[ij])
for ik in range(c):
    lcq.append(lc[ik])
count=0
for i in range(x):
    if c>=1:
        aa=laq.pop()
        cc=lcq.pop()
        if aa>=cc:
            count+=aa
            lcq.append(cc)
        else:
            count+=cc
            laq.append(aa)
            c-=1
    else:
        count+=laq.pop()
for j in range(y):
    if c>=1:
        bb=lbq.pop()
        cc=lcq.pop()
        if bb>=cc:
            count+=bb
            lcq.append(cc)
        else:
            count+=cc
            lbq.append(bb)
            c-=1
    else:
        count+=lbq.pop()
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c=list(map(int,input().split()))
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la=sorted(la)
lb=sorted(lb)
lc=sorted(lc)
laq=deque()
lbq=deque()
lcq=deque()
for ii in range(a):
    laq.append(la[ii])
for ij in range(b):
    lbq.append(lb[ij])
for ik in range(c):
    lcq.append(lc[ik])
count=0
for i in range(x):
    if c>=1:
        aa=laq.pop()
        cc=lcq.pop()
        if aa>=cc:
            count+=aa
            lcq.append(cc)
        else:
            count+=cc
            laq.append(aa)
            c-=1
    else:
        count+=laq.pop()
for j in range(y):
    if c>=1:
        bb=lbq.pop()
        cc=lcq.pop()
        if bb>=cc:
            count+=bb
            lcq.append(cc)
        else:
            count+=cc
            lbq.append(bb)
            c-=1
    else:
        count+=lbq.pop()
print(count)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=list(map(int,input().split()))
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la=sorted(la)
lb=sorted(lb)
lc=sorted(lc)
count=0
for i in range(x):
    if c>=1:
        if la[a-i-1]>=lc[c-1]:
            count+=la[a-i-1]
            la.remove(la[a-i-1])
        else:
            count+=lc[c-1]
            lc.remove(lc[c-1])
            c-=1
    else:
        count+=la[a-i-1]
        la.remove(la[a-i-1])
for j in range(y):
    if c>=1:
        if lb[b-j-1]>=lc[c-1]:
            count+=lb[b-j-1]
            lb.remove(lb[b-j-1])
        else:
            count+=lc[c-1]
            lc.remove(lc[c-1])
            c-=1
    else:
        count+=lb[b-j-1]
        lb.remove(lb[b-j-1])
print(count)

Submission status: Wrong Answer

Solution code:
import copy
x, y, a, b, c = map(int, input().split())
#s= list(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
por = p[a-x:a]
qor = q[b-y:b]
qp = por.copy()
qp.extend(qor.copy())
qp.sort()
i=0
while(i < x+y and i < c and r[c-i-1] > qp[i]):
    qp[i] = r[c-i-1]
ans = sum(qp)
print(ans)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int, input().split())
plist=list(map(int, input().split())) 
qlist=list(map(int, input().split())) 
rlist=list(map(int, input().split())) 
plist.sort(reverse=True)
qlist.sort(reverse=True)
rlist.sort(reverse=True)
redlist = plist[:X]
greenlist = qlist[:Y]
RandG = redlist+greenlist
RandG.sort()
for i in range(min(X+Y,C)+2):
    if i > min(X,Y,C):
        break
    if sum(RandG[:i])>sum(rlist[:i]):
        break
maxdeli = sum(RandG[i-1:]) + sum(rlist[:i-1])
print(maxdeli)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int, input().split())
plist=list(map(int, input().split())) 
qlist=list(map(int, input().split())) 
rlist=list(map(int, input().split())) 
plist.sort(reverse=True)
qlist.sort(reverse=True)
rlist.sort(reverse=True)
redlist = plist[:X]
greenlist = qlist[:Y]
RandG = redlist+greenlist
RandG.sort()
for i in range(min(X,Y,C)+2):
    if i > min(X,Y,C):
        break
    if sum(RandG[:i])>sum(rlist[:i]):
        break
maxdeli = sum(RandG[i-1:]) + sum(rlist[:i-1])
print(maxdeli)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)
p2=p[:x]
q2=q[:y]
memop=x-1
memoq=y-1
sp=sum(p2)
sq=sum(q2)
k=0
flagp=0
flagq=0
while k<c:
    if memop<0:
        flagp=1
    if memoq<0:
        flagq=1
    if flagp*flagq==1:
        print(sp+sq)
        exit()
    elif flagq==1:
        if p2[memop]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sp-=p2[memop]
            sp+=r[k]
            k+=1
            memop-=1
    elif flagp==1:
        if q2[memoq]>=r[k]:
            print(sp+sq)
            exit()
        else:
            sq-=q2[memoq]
            sq+=r[k]
            k+=1
            memoq-=1
    elif p2[memop]>=r[k] and q2[memoq]>=r[k] and flagp+flagq==0:
        print(sp+sq)
        exit()
    elif p2[memop]>q2[memoq]:
        sq-=q2[memoq]
        sq+=r[k]
        k+=1
        memoq-=1
    elif p2[memop]<=q2[memoq]:
        sp-=p2[memop]
        sp+=r[k]
        k+=1
        memop-=1

Submission status: Wrong Answer

Solution code:
import sys
import heapq

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X,Y,A,B,C = map(int, readline().split())

P = list(map(int, readline().split()))
Q = list(map(int, readline().split()))
R = list(map(int, readline().split()))

print(len(P), len(Q), len(R))

P = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
R.sort(reverse=True)

heapq.heapify(P)
heapq.heapify(Q)

print(len(P), len(Q), len(R))

for r in R:
    p = heapq.heappop(P)
    q = heapq.heappop(Q)

    if p <= q and p < r:
        heapq.heappush(P, r)
        heapq.heappush(Q, q)
    elif q < r:
        heapq.heappush(Q, r)
        heapq.heappush(P, p)
    else:
        heapq.heappush(P, p)
        heapq.heappush(Q, q)

print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
import sys
import heapq

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X,Y,A,B,C = map(int, readline().split())

P = list(map(int, readline().split()))
Q = list(map(int, readline().split()))
R = list(map(int, readline().split()))

P = sorted(P)[len(P)-X:]
Q = sorted(Q)[len(Q)-Y:]


heapq.heapify(P)
heapq.heapify(Q)

R.sort(reverse=True)


for r in R:
    p = heapq.heappop(P)
    q = heapq.heappop(Q)

    if p < q and p < r:
        heapq.heappush(P, r)
        heapq.heappush(Q, q)
    elif q < p and q < r:
        heapq.heappush(Q, r)
        heapq.heappush(P, p)
    else:
        heapq.heappush(P, p)
        heapq.heappush(Q, q)

print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
import sys
import heapq

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X,Y,A,B,C = map(int, readline().split())

P = list(map(int, readline().split()))
Q = list(map(int, readline().split()))
R = list(map(int, readline().split()))

P = sorted(P)[len(P)-X:]
Q = sorted(Q)[len(Q)-Y:]


heapq.heapify(P)
heapq.heapify(Q)

R.sort(reverse=True)


for r in R:
    p = heapq.heappop(P)
    q = heapq.heappop(Q)

    if p < r:
        heapq.heappush(P, r)
        heapq.heappush(Q, q)
    elif q < r:
        heapq.heappush(Q, r)
        heapq.heappush(P, p)
    else:
        heapq.heappush(P,p)
        heapq.heappush(Q,q)
        
ans = 0
for p in P:
    ans += p
for q in Q:
    ans += q

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X,Y,A,B,C = map(int, readline().split())

P = list(map(int, readline().split()))
Q = list(map(int, readline().split()))
R = list(map(int, readline().split()))

P = sorted(P)[len(P)-X:]
Q = sorted(Q)[len(Q)-Y:]


heapq.heapify(P)
heapq.heapify(Q)

R.sort(reverse=True)


for r in R:
    p = heapq.heappop(P)
    q = heapq.heappop(Q)

    if p < r:
        heapq.heappush(P, r)
        heapq.heappush(Q, q)
    elif q < r:
        heapq.heappush(Q, r)
        heapq.heappush(P, p)
    else:
        heapq.heappush(P,p)
        heapq.heappush(Q,q)
        break
ans = 0
for p in P:
    ans += p
for q in Q:
    ans += q

print(ans)

Submission status: Wrong Answer

Solution code:

def main():
  x, y, _a, _b, _c = map(int, input().split())
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  print(sum(sorted(set(p + q + r))[- x - y:]))


main()

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

z = []

for i in range(x):
    z.append(p[a - i - 1])
    
for i in range(x):
    z.append(q[b - i - 1])

for i in list(r):
    z.append(i)

z.sort(reverse=True)

ans = 0

for i in range(x + y):
    ans += z[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
X ,Y ,A ,B ,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:X]
q = q[:Y]
p.extend(q)
p.extend(r)
p. sort(reverse = True)
p = p[:A+B]
print(sum(p))

Submission status: Wrong Answer

Solution code:
from collections import deque

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P = deque(sorted(P,reverse=True))
Q = deque(sorted(Q,reverse=True))
R = deque(sorted(R,reverse=True))

a = []
b = []

while len(a) >= A and len(b) >= B:
    r = R.popleft()
    for i in range(10**8):
        if len(a) == A and len(b) == B:
            break;
        p = P.popleft()
        q = Q.popleft()
        if r <= p and r <= q:
            if len(a) < A:
                a.append(p)
            if len(b) < B:
                b.append(q)
        elif r > p and r <= q:
            if len(b) < B:
                b.append(q)
        elif r <= p and r > q:
            if len(a) < A:
                a.append(p)
        elif r > p and r > q:
            P = list(P)
            Q = list(Q)
            if P[0] < r and Q[0] > r:
                if len(b) < B:
                    b.append(r)
                else :
                    a.append(p)    
            if P[0] > r and Q[0] < r:
                if len(a) < A:
                    a.append(p)
                else :
                    b.append(r)
            if P[0] == r and Q[0] == r:
                if len(a) < A and len(b) >= B:
                    a.append(p)
                elif len(a) >= A and  len(b) < B:
                    b.append(r)
                else:
                    a.append(p)
            P = deque(P)
            Q = deque(Q)
            break;


print(a)
print(b)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

R += sorted(R)[-X:]
R += sorted(Q)[-Y:]
ans = sum(sorted(R)[-(X+Y):])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
x, y, a, b, c = map(int,input().split())
p = np.array(input().split(),dtype=int)
q = np.array(input().split(),dtype=int)
r = np.array(input().split(),dtype=int)
p = np.sort(p)[::-1]
q = np.sort(q)[::-1]
r = np.sort(r)[::-1]

pn = x-1
qn = y-1
ans = 0


for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]

for i in range(c):
    if p[pn] <= q[qn] and p[pn] < r[i] and pn >= 0:
        ans -= p[pn]
        ans += r[i]
        pn -= 1
    elif q[qn] < r[i] and qn >= 0:
        ans -= q[qn]
        ans += r[i]
        qn -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
x, y, a, b, c = map(int,input().split())
p = np.array(input().split(),dtype=int)
q = np.array(input().split(),dtype=int)
r = np.array(input().split(),dtype=int)
p = np.sort(p)[::-1]
q = np.sort(q)[::-1]
r = np.sort(r)[::-1]

pn = x-1
qn = y-1
ans = 0


for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]

for i in range(min([x+y,c])):
    if p[pn] < q[qn] and p[pn] < r[i] and pn >= 0:
        ans -= p[pn]
        ans += r[i]
        pn -= 1
    elif q[qn] < r[i] and qn >= 0:
        ans -= q[qn]
        ans += r[i]
        qn -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
x, y, a, b, c = map(int,input().split())
p = np.array(input().split(),dtype=int)
q = np.array(input().split(),dtype=int)
r = np.array(input().split(),dtype=int)
p = np.sort(p)[::-1]
q = np.sort(q)[::-1]
r = np.sort(r)[::-1]

pn = x-1
qn = y-1
ans = 0


for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]

for i in range(min([x+y,c])):
    if p[pn] < q[qn] and p[pn] < r[i] and pn >= 0:
        ans -= p[pn]
        ans += r[i]
        pn -= 1
    elif q[qn] < r[i] and qn >= 0:
        ans -= q[qn]
        ans += r[i]
        pn -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
x, y, a, b, c = map(int,input().split())
p = np.array(input().split(),dtype=int)
q = np.array(input().split(),dtype=int)
r = np.array(input().split(),dtype=int)
p = np.sort(p)[::-1]
q = np.sort(q)[::-1]
r = np.sort(r)[::-1]

pn = x-1
qn = y-1
ans = 0


for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[i]

for i in range(min([x+y,c])):
    if p[pn] < q[qn] and p[pn] < r[i]:
        ans -= p[pn]
        ans += r[i]
        pn -= 1
    elif q[qn] < r[i]:
        ans -= q[qn]
        ans += r[i]
        pn -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())

P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
        
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

A=P[:X]+Q[:Y]+R

A.sort(reverse=True)

print(A[X+Y])

Submission status: Wrong Answer

Solution code:
###### Importing Libraries ######
import math
import operator as op
from functools import reduce
from fractions import Fraction as frac
#################################
##### User defined function #####

############ NCR ###############
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
    
############ READ ###############
def rd(p):
    if(p==0):
        return input()
    if(p==1):
        return int(input())
    if(p==2):
        return map(int,input().split())
    if(p==3):
        return list(map(int,input().split()))


############ DSU ###############
global par
par=[-1 for i in range(100001)]
# t=rd(1)
def find(u):
    if(par[u]<0):
        return u
    else:
        return find(par[u])
def uni(x,y):
    u=find(x)
    v=find(y)
    if u==v:
        return
    if(par[u]<par[v]):
        par[u]+=par[v]
        par[v]=u
    else:    
        par[v]+=par[u]
        par[u]=v
################################        
        

t=1
for term in range(1,t+1):
    x,y,a,b,c=rd(2)
    A=rd(3)
    B=rd(3)
    C=rd(3)
    A.sort()
    B.sort()
    C.sort()
    tot=0
    A=[0]+A
    B=[0]+B
    C=[0]+C
    for i in range(x):
        if(A[-1]>=C[-1]):
            tot+=A[-1]
            A.pop()
        else:
            tot+=C[-1]
            C.pop()
    for i in range(y):
        if(B[-1]>=C[-1]):
            tot+=B[-1]
            B.pop()
        else:
            tot+=C[-1]
            C.pop()
    print(tot)

Submission status: Wrong Answer

Solution code:
from collections import deque
X,Y,A,B,C = (int(x) for x in input().split())
p = [[int(x), 'r'] for x in input().split()]
q = [[int(x), 'g'] for x in input().split()]
r = [[int(x), 'c'] for x in input().split()]
pqr = p + q + r
pqr.sort(reverse=True)
d = deque(pqr)
rem = X + Y
picked = 0
ans = 0
if len(d) <= rem:
    print(sum([apple[0] for apple in pqr]))
else:
    while rem > picked:
        pop = d.popleft()
        if pop[1] == 'r':
            if X > 0:
                X -= 1
                ans += pop[0]
                picked += 1
        elif pop[1] == 'g':
            if Y > 0:
                Y -= 1
                ans += pop[0]
                picked += 1
        else:
            rem -= 1
            ans += pop[0]
            picked += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
X,Y,A,B,C = (int(x) for x in input().split())
p = [[int(x), 'r'] for x in input().split()]
q = [[int(x), 'g'] for x in input().split()]
r = [[int(x), 'c'] for x in input().split()]
pqr = p + q + r
pqr.sort(reverse=True)
d = deque(pqr)
rem = X + Y
picked = 0
ans = 0
while rem > picked:
    pop = d.popleft()
    if pop[1] == 'r':
        if X > 0:
            X -= 1
            ans += pop[0]
            picked += 1
    elif pop[1] == 'g':
        if Y > 0:
            Y -= 1
            ans += pop[0]
            picked += 1
    else:
        rem -= 1
        ans += pop[0]
        picked += 1
print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
p = p[a-x:]
q = q[b-y:]
pi = 0
qi = 0
ri = 0
while ri < c:
    if pi == x:
        if qi == y:
            break
        else:
            if q[qi] >= r[ri]:
                break
            else:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
    elif qi == y:
        if p[pi] >= r[ri]:
            break
        else:
            p[pi] = r[ri]
            pi += 1
            ri += 1
            continue
    else:
        if p[pi] >= r[ri] and q[qi] >= r[ri]:
            break
        else:
            if p[pi] <= q[qi]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
            else:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue

print(p)
print(q)
print(sum(p) + sum(q))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort(reverse=True)
p = p[A-X:]
q = q[B-Y:]
min_p = 0
min_q = 0
for i in range(C):
  if min_p > X-1 or min_q > Y-1:
    break
  if p[min_p] < q[min_q]:
    if p[min_p] < r[i]:
      p[min_p] = r[i]
    min_p += 1
  else:
    if q[min_q] < r[i]:
      q[min_q] = r[i]
    min_q += 1
    
print(sum(p)+sum(q))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort(reverse=True)
p = p[A-X:]
q = q[B-Y:]
min_p = 0
min_q = 0
for i in range(C):
  if min_p > X-1 or min_q > Y-1:
    break
  if p[min_p] < q[min_q]:
    if p[min_p] < r[i]:
      p[min_p] = r[i]
    min_p += 1
  elif q[min_q] < p[min_p]:
    if q[min_q] < r[i]:
      q[min_q] = r[i]
    min_q += 1
    
print(sum(p)+sum(q))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))

l=l[:]+l1[:]+l2[:]
sum=0
l.sort()

ct=0
while ct!=x+y:
  ct+=1
  sum+=l[-ct]
print(sum)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappush, heappop
def greenandredapples():
    X, Y, A, B, C = list(map(int, input().split()))
    RedD = sorted(list(map(int, input().split())))
    GreenD = sorted(list(map(int, input().split())))
    Colorl = sorted(list(map(int, input().split())))

    considered = RedD[-X:] + GreenD[-Y:]
    #print(considered)
    replacements = len(Colorl)
    #print(Colorl)
    while replacements >= 0 and len(Colorl) > 0:
        heapify(considered)
        smallest = heappop(considered)
        #print("ffff", smallest)
        r = Colorl.pop(0)
        #print("gggg", r, Colorl)
        if smallest >= r:
            heappush(considered, smallest)
            break
        heappush(considered, r)
        #print("ccc", considered)
        replacements -= 1
    #print(considered)
    return sum(considered)
print(greenandredapples())

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p,reverse = True)
q = sorted(q,reverse = True)
r = sorted(r,reverse = True)
p = p[0:x]
q = q[0:y]
for i in r:
    j = 0
    t = 0
    flag = True
    if p[-1] > q[-1]:
        j = y-1
        t = q[j]
        flag = False
    else:
        j = x-1
        t = p[j]
    if t < i:
        if flag == True:
            p[j] = i
        else:
            q[j] = i
    else:
        break
print(sum(p)+sum(q))

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:X]
Q = sorted(P, reverse=True)[:Y]
R = sorted(P, reverse=True)[:X+Y]

print(sum(sorted(P+Q+R, reverse=True)[:X+Y]))

Submission status: Wrong Answer

Solution code:
[X, Y, A, B, C] = list(map(int, input().split()))

p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

eatCandi = p[0:X] + q[0:Y] + r[0:X+Y]
print(sum(eatCandi[0:X+Y]))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = list(map(int, input().split(' ')))
p_list = sorted(list(map(int, input().split(' '))), reverse=True)
q_list = sorted(list(map(int, input().split(' '))), reverse=True)
r_list = sorted(list(map(int, input().split(' '))), reverse=True)

xy_list = sorted(p_list[:x] + q_list[:y])

i = 0
for r in range(c):
    if r_list[r] > xy_list[0]:
        i += 1
    else:
        break

if i == 0:
    print(sum(xy_list))
else:
    print(sum(xy_list[i:] + r_list[:i]))

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y, a, b, c = list(map(int, readline().split()))
    p = list(map(int, readline().split()))
    q = list(map(int, readline().split()))
    r = [-1 * i for i in list(map(int, readline().split()))]
    p.sort(reverse=True)
    q.sort(reverse=True)
    hq = p[:x] + q[:y]
    heapq.heapify(hq)
    heapq.heapify(r)
    while len(r):
        hqv = heapq.heappop(hq)
        rv = -heapq.heappop(r)
        print(rv)
        if rv > hqv:
            heapq.heappush(hq, rv)
        else:
            heapq.heappush(hq, hqv)
            break
    print(sum(hq))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y, a, b, c = list(map(int, readline().split()))
    p = list(map(int, readline().split()))
    q = list(map(int, readline().split()))
    r = list(map(int, readline().split()))
    p.sort(reverse=True)
    q.sort(reverse=True)
    hq = p[:x] + q[:y]
    heapq.heapify(hq)
    heapq.heapify(r)
    while len(r):
        hqv = heapq.heappop(hq)
        rv = heapq.heappop(r)
        if rv >= hqv:
            heapq.heappush(hq, rv)
        else:
            heapq.heappush(hq, hqv)
            break
    print(sum(hq))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
"""
x,y,a,b,c=[int(x) for x in input().split()]
p=[int(x) for x in input().split()]
q=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]
"""

x,y,a,b,c=[1,2,2,2,1]
p=[2,4]
q=[5,1]
r=[3]

p=list(np.sort(p)[::-1][0:x])
q=list(np.sort(q)[::-1][0:y])

select=np.sort(p+q+r)[::-1][0:x+y]
print(sum(select))

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c = map(int ,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p = p[:x]
q = q[:y]

pq = p+q
pq.sort(reverse=True)

pq_que = deque([])
r_que = deque([])

for i in range(x+y):
    pq_que.append(pq[i])
for i in range(c):
    r_que.append(r[i])


for i in range(c):
    if pq[-1] < r[i]:
        pq_que.pop()
        pq_que.append(r[i])

print(sum(pq_que))

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c = map(int ,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p = p[:x]
q = q[:y]

pq = p+q
pq.sort(reverse=True)

pq_que = deque([])
r_que = deque([])

for i in range(x+y):
    pq_que.append(pq[i])
for i in range(c):
    r_que.append(r[i])


for i in range(c):
    if pq[-1] < r[0]:
        pq_que.pop()
        pq_que.append(r[0])

print(sum(pq_que))