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())
parr = list(map(int,input().split()))
qarr = list(map(int,input().split()))
rarr = list(map(int,input().split()))
parr.sort(reverse=True)
qarr.sort(reverse=True)
rarr.sort(reverse=True)
parr = parr[:x]
qarr = qarr[:y]

tmparr = parr + rarr
tmparr.sort(reverse=True)
count = sum(tmparr[:x])

pidx = 0
for i in range(x):
    if parr[pidx] == tmparr[i]:
        pidx += 1
        
tmparr = qarr + rarr[(x-pidx):]
tmparr.sort(reverse=True)
count += sum(tmparr[:y])

print(count)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())
p,q,r = [sorted(map(int,input().split()),reverse=True) for i in range(3)]
rr = [0 for i in range(X+Y)]
for i in range(min(X+Y,C)):
    rr[i] += r[i]
temp = sum(rr)
ans = 0
count = X+Y-1

for i in range(X):
    temp += p[i]
    temp -= rr[count]
    count -= 1
    count_2 = count
    temp_2 = temp
    for j in range(Y):
        temp_2 += q[j]
        temp_2 -= rr[count_2]
        count_2 -= 1
        ans = max(ans,temp_2)

print(ans)

Submission status: Wrong Answer

Solution code:
def merge(A,B):
    C = []
    
    while len(A)!=0 and len(B) != 0:
        if A[0]>B[0]:
            C.append(A[0])
            del A[0]
        else:
            C.append(B[0])
            del B[0]

    if len(A)>len(B):
        C.extend(A)
    else:
        C.extend(B)

    return C

if __name__ == "__main__":
    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 = [1,23,4,1,2]
    # Q = [4,3,56]
    # R = [70,20,1]

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    S = merge(P[:X],Q[:Y])
    S = merge(S,R)

    print(S)
    
    score = 0
    for i in range(X+Y):
        score += S[i]
    print(score)

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))
ans = 0
for i in range(x):
    if len(p) == 0:
        ans += r.popleft()
    elif len(r) == 0:
        ans += p.popleft()
    else:
        if p[0] > r[0]:
            ans += p.popleft()
        else:
            ans += r.popleft()
for i in range(y):
    if len(q) == 0:
        ans += r.popleft()
    elif len(r) == 0:
        ans += q.popleft()
    else:
        if q[0] > r[0]:
            ans += q.popleft()
        else:
            ans += r.popleft()
print(ans)

Submission status: Wrong Answer

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

ans = sorted(qs)[-X:] + sorted(ps)[-Y:] + sorted(rs)

print(str(sum(sorted(ans)[-X-Y:])))

Submission status: Wrong Answer

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

ans = sorted(qs)[-X:] + sorted(ps)[-Y:] + sorted(rs)

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

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int, input().split(" "))
p = sorted([int(x) for x in input().split(" ")])
q = sorted([int(x) for x in input().split(" ")])
r = sorted([int(x) for x in input().split(" ")])

s = 0
# gen c
for a in range(C+1):
  for b in range(C+1):
    if a + b > C:
      break
    t = sum(p[A-X+a:A]) + sum(q[B-Y+b:B]) + sum(r[C-a-b:C])
    print(a,b,t)
    s = max([s, t])

print(s)

Submission status: Wrong Answer

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

p_a = list(map(int, input().split()))
p_b = list(map(int, input().split()))
p_c = list(map(int, input().split()))


p_a = sorted(p_a)[-x:]
p_b = sorted(p_b)[-y:]
p_c.sort(reverse=True)

a_s = b_s = 0

while p_c:
    view, start = (p_a, a_s) if p_a[a_s] < p_b[b_s] else (p_b, b_s)
    if view[start] < p_c[0]:
        view[start] = p_c.pop(0)
        start += 1
    else: break

print(sum(p_a) + sum(p_b))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
p+=[0]*y
q+=[0]*x
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x:
    ans+=r[k]
    i+=1
  elif r[k]>q[i] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
p+=[0]*y
q+=[0]*x
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i]:
    ans+=r[k]
    i+=1
  elif r[k]>q[i]:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor = list(map(int,input().split()))
nocolor = list(map(lambda w:w*(-1),nocolor))
heapq.heapify(red)
heapq.heapify(green)
heapq.heapify(nocolor)
for i in range(c):
    f = heapq.heappop(red)
    t = heapq.heappop(green)
    u = heapq.heappop(nocolor)
    if f < t:
        heapq.heappush(green,t)
        if f < -u:
            heapq.heappush(red,-u)
        else:
            heapq.heappush(red,f)
            break
    else:
        heapq.heappush(red,f)
        if t < -u:
            heapq.heappush(green,-u)
        else:
            heapq.heappush(green,t)
            break
red.sort(reverse=True)
green.sort(reverse=True)
print(sum(red[:x]) + sum(green[:y]))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor = list(map(int,input().split()))
nocolor = list(map(lambda w:w*(-1),nocolor))
heapq.heapify(red)
heapq.heapify(green)
heapq.heapify(nocolor)
for i in range(c):
    f = heapq.heappop(red)
    t = heapq.heappop(green)
    u = heapq.heappop(nocolor)
    if f < t:
        heapq.heappush(green,t)
        if f < -u:
            heapq.heappush(red,-u)
        else:
            heapq.heappush(red,f)
            break
    else:
        heapq.heappush(red,f)
        if t < -u:
            heapq.heappush(green,-u)
        else:
            heapq.heappush(green,t)
            break
print(sum(sorted(red[a-x:])) + sum(sorted(green[b-y:])))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor = list(map(int,input().split()))
nocolor = list(map(lambda w:w*(-1),nocolor))
heapq.heapify(red)
heapq.heapify(green)
heapq.heapify(nocolor)
for i in range(c):
    f = heapq.heappop(red)
    t = heapq.heappop(green)
    u = heapq.heappop(nocolor)
    if f < t:
        heapq.heappush(green,t)
        if f < -u:
            heapq.heappush(red,-u)
        else:
            heapq.heappush(red,f)
            break
    else:
        heapq.heappush(red,f)
        if t < -u:
            heapq.heappush(green,-u)
        else:
            heapq.heappush(green,t)
            break
print(sum(red[a-x:]) + sum(green[b-y:]))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))
green = list(map(int,input().split()))
nocolor = list(map(int,input().split()))
nocolor = list(map(lambda w:w*(-1),nocolor))
heapq.heapify(red)
heapq.heapify(green)
heapq.heapify(nocolor)
for i in range(len(nocolor)):
    f = heapq.heappop(red)
    t = heapq.heappop(green)
    u = heapq.heappop(nocolor)
    if f < t:
        heapq.heappush(green,t)
        if f < -u:
            heapq.heappush(red,-u)
        else:
            heapq.heappush(red,f)
            
            break
    else:
        heapq.heappush(red,f)
        if t < -u:
            heapq.heappush(green,-u)
        else:
            heapq.heappush(green,t)
            break
print(sum(red[a-x:]) + sum(green[b-y:]))

Submission status: Wrong Answer

Solution code:
import heapq

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.reverse(); q.reverse(); r.reverse();
ans = [sum(p[:X]) + sum(q[:Y])]
que = []
for pi in p:
    heapq.heappush(que, pi)
for qi in q:
    heapq.heappush(que, qi)

for i in range(min(C, X + Y + 1)):
    minimum = heapq.heappop(que)
    ans.append(ans[-1] - minimum + r[i])

print(max(ans))

Submission status: Wrong Answer

Solution code:
import heapq

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.reverse(); q.reverse(); r.reverse();
ans = [sum(p[:X]) + sum(q[:Y])]
que = []
for pi in p:
    heapq.heappush(que, pi)
for qi in q:
    heapq.heappush(que, qi)

for i in range(min(C, X + Y)):
    minimum = heapq.heappop(que)
    ans.append(ans[-1] - minimum + r[i])

print(max(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)
for i in range(a-x):
    del p[0]
for i in range(b-y):
    del q[0]
print(p,q,r)
date = [int() for a in range(len(p)+len(q))]
for a in range(len(p)):
    date[a] = p[a]
for a in range(len(q)):
    date[len(p)+a] = q[a]
date.sort()
print(date)

flag = False
while not flag:
    n = 0
    for j in range(len(r)):
        if date[n] < r[j]:
            date[n] = r[j]
            date.sort()
        if j == len(r)-1:
            flag =True
            break
print(sum(date))

Submission status: Wrong Answer

Solution code:
from collections import deque
X, Y, A, B, C = map(int, input().split())
P = deque(sorted(list(map(int, input().split())), reverse=True))
Q = deque(sorted(list(map(int, input().split())), reverse=True))
R = deque(sorted(list(map(int, input().split())), reverse=True))
ans = 0
p_cnt = 0
while p_cnt < X:
  if R and P[0] < R[0]:
    r = R.popleft()
  else:
    r = P.popleft()
  ans += r
  p_cnt += 1
q_cnt = 0
while q_cnt < Y:
  if R and Q[0] < R[0]:
    g = R.popleft()
  else:
    g = Q.popleft()
  ans += g
  q_cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = sorted(p_list, reverse=True)
q_list = sorted(q_list, reverse=True)
r_list = sorted(r_list, reverse=True)

total = 0
for _ in range(X):
    if r_list and p_list:
        r = r_list[0]
        p = p_list[0]

        if p >= r:
            total += p_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop()
    elif p_list:
        total += p_list.pop()
    else:
        break

for _ in range(Y):
    if r_list and q_list:
        r = r_list[0]
        q = q_list[0]

        if q >= r:
            total += q_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop(0)
    elif q_list:
        total += q_list.pop(0)
    else:
        break
ans = total
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
colored = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else 0
    q_min = q[len(q) - 1] if len(q) > 0 else 0
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored.append(i)
 
print(sum(p) + sum(q) + sum(colored))

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
 
p = sorted(list(map(int,input().split())), reverse=True)[:X]
q = sorted(list(map(int,input().split())), reverse=True)[:Y]
r = sorted(list(map(int,input().split())), reverse=True)
 
colored = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else -1
    q_min = q[len(q) - 1] if len(q) > 0 else -1
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored.append(i)
 
print(sum(p) + sum(q) + sum(colored))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=[int(x) for x in input().split()]
saare=[]
for item in P:
	saare.append([item,'R'])
for item in Q:
	saare.append([item,'G'])
for item in R:
	saare.append([item,'C'])
 
saare.sort(reverse=True)
# print(saare)
 
p=A-X
q=B-Y
 
i=0
 
ans=0
 
while X or Y:
 
	if saare[i][1]=='R' and X:
		X-=1
		p+=1
		ans+=saare[i][0]
		# print("EAT RED",saare[i][0])
	elif saare[i][1]=='G' and Y:
		Y-=1
		q+=1
		ans+=saare[i][0]
		# print("EAT GREEN",saare[i][0])
	elif saare[i][1]=='C':
		if not Y:
			X-=1
			p+=1
			ans+=saare[i][0]
			# print("EAT RED",saare[i][0])
		elif not X:
			Y-=1
			q+=1
			ans+=saare[i][0]
			# print("EAT GREEN",saare[i][0])
		else:
			if P[p] >= Q[q]:
				q+=1
				Y-=1
				ans+=saare[i][0]
				# print("EAT GREEN",saare[i][0])
			else:
				p+=1
				X-=1
				ans+=saare[i][0]
				# print("EAT RED",saare[i][0])
	i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d,e=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
t=0
l=l1+l3
l.sort(reverse=True)
t=t+sum(l[:a])
l4=l2+l3
l4.sort(reverse=True)
t=t+sum(l4[:a])
print(t)

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]
for r in R:
    if P[-1] < Q[-1]:
        if P[-1] < r:
            P[-1] = r
        else:
            break
    else:
        if Q[-1] < r:
            Q[-1] = r
        else:
            break
print(sum(P)+sum(Q))

Submission status: Wrong Answer

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

all = p + q + r
all.sort(reverse=True)
print((all[:X + Y]))

Submission status: Wrong Answer

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0] , A)
B = heapq.nlargest(n[1] , B)
len = len(C)
if len <(n[0]+n[1]):
    C = heapq.nlargest(len,C)
else:
    C = heapq.nlargest(n[0]+n[1] , C)
for i in range(n[0]+n[1]):
    if s == len:
        if a==n[0] and m<n[1]:
            saidai = B[m]
            m +=1
        else:
            saidai = A[a]
            a +=1

    else:
        if a==n[0] and m<n[1]:
            saidai = max([ B[m],C[s] ])

            if C[s] >= B[m]:
                s +=1
            else:
                m +=1
        elif a<n[0] and m == n[1]:
            saidai = max([ A[a],C[s] ])

            if C[s] >= A[a]:
                s +=1
            else:
                a +=1

        else:
            saidai=max([ A[a],B[m],C[s] ])

            if A[a] >= B[m] and A[a] > C[s]:
                a +=1
            elif A[a] < B[m] and B[m] > C[s]:
                m +=1
            elif C[s] >= B[m] and A[a] <= C[s]:
                s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

a=0
m=0
s=0
ans = 0
A = heapq.nlargest(n[0] , A)
B = heapq.nlargest(n[1] , B)
len = len(C)
if len <(n[0]+n[1]):
    C = heapq.nlargest(len,C)
else:
    C = heapq.nlargest(n[0]+n[1] , C)
for i in range(0,n[0]+n[1]):
    if s == len:
        if a==n[0] and m<n[1]:
            saidai = B[m]
            m +=1
        else:
            saidai = A[a]
            a +=1

    else:
        if a==n[0] and m<n[1]:
            saidai = max([ B[m],C[s] ])

            if C[s] >= B[m]:
                s +=1
            else:
                m +=1
        elif a<n[0] and m == n[1]:
            saidai = max([ A[a],C[s] ])

            if C[s] >= A[a]:
                s +=1
            else:
                a +=1

        else:
            saidai=max([ A[a],B[m],C[s] ])

            if A[a] >= B[m] and A[a] > C[s]:
                a +=1
            elif A[a] < B[m] and B[m] > C[s]:
                m +=1
            elif C[s] >= B[m] and A[a] <= C[s]:
                s +=1
    
    ans = ans + saidai

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
x, y, a, b, c = map(int, input().split())
P = [0]*x + [int(p) for p in input().split()]
Q = [0]*y + [int(q) for q in input().split()]
R = [int(r) for r in input().split()]

P.sort()
Q.sort()
R.sort(reverse=True)
Px = P[a:]
Qy = Q[b:]
R = R[:x+y]
pc, qc = 0, 0
pqpq = [Px, Qy]
pqc = [pc, qc]
for r in R:
    if Px[pc]<Qy[qc]:
        pq = 0
    else:
        pq = 1
    if pqpq[pq][pqc[pq]] < r:
        pqpq[pq][pqc[pq]] = r
        pqc[pq]+= 1
    else:
        break

print(sum(Px)+sum(Qy))

Submission status: Wrong Answer

Solution code:
xyabc = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

max_p = sorted(p, reverse=True)[:xyabc[0]]
max_q = sorted(q, reverse=True)[:xyabc[1]]
max_pp = sorted(p, reverse=True)
max_qq = sorted(q, reverse=True)
maxp = sorted(max_pp + r, reverse=True)[:xyabc[0]]
maxq = sorted(max_qq + r, reverse=True)[:xyabc[1]]
max_r = sorted(r, reverse=True)
sum_p = sum(max_p)
sump = sum(maxp)
sum_q = sum(max_q)
sumq = sum(maxq)
if sump + sum_q > sumq + sum_p and sump + sum_q > sum_p + sum_q:
    rr = sorted(list(set(maxp) - set(max_p)), reverse=True)[-1]
    rr = max_r[max_r.index(rr) + 1:]
    maxq = sorted(q + rr, reverse=True)[:xyabc[1]]
    sumq = sum(maxq)
    print(sump + sumq)
elif sum_p + sumq > sum_q + sump and sum_p + sumq > sum_p + sum_q:
    rr = sorted(list(set(maxq) - set(max_q)), reverse=True)[-1]
    rr = max_r[max_r.index(rr) + 1:]
    maxp = sorted(p + rr, reverse=True)[:xyabc[0]]
    sump = sum(maxp)
    print(sump + sumq)
else:
    print(sum_p + sum_q)

Submission status: Wrong Answer

Solution code:
xyabc = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

max_p = sorted(p, reverse=True)[:xyabc[0]]
max_q = sorted(q, reverse=True)[:xyabc[1]]
maxp = sorted(max_p + r, reverse=True)[:xyabc[0]]
maxq = sorted(max_q + r, reverse=True)[:xyabc[1]]
max_r = sorted(r, reverse=True)
sum_p = sum(max_p)
sump = sum(maxp)
sum_q = sum(max_q)
sumq = sum(maxq)
if sump + sum_q > sumq + sum_p and sump + sum_q > sum_p + sum_q:
    rr = sorted(list(set(maxp) - set(max_p)), reverse=True)[-1]
    rr = max_r[max_r.index(rr) + 1:]
    maxq = sorted(q + rr, reverse=True)[:xyabc[1]]
    sumq = sum(maxq)
    print(sump + sumq)
elif sum_p + sumq > sum_q + sump and sum_p + sumq > sum_p + sum_q:
    rr = sorted(list(set(maxq) - set(max_q)), reverse=True)[-1]
    rr = max_r[max_r.index(rr) + 1:]
    maxp = sorted(p + rr, reverse=True)[:xyabc[0]]
    sump = sum(maxp)
    print(sump + sumq)
else:
    print(sum_p + sum_q)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = 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)

p_count = 0
q_count = 0
r_count = 0
total = 0
for i in range(0, x + y):
  score_max = 0
  flag = 0
  if p_count < x:
    score = p_list[p_count]
    if score_max < score:
      score_max = score
      flag = 1
  if q_count < x:
    score = q_list[q_count]
    if score_max < score:
      score_max = score
      flag = 2
  if r_count < x:
    score = r_list[r_count]
    if score_max < score:
      score_max = score
      flag = 3
  if flag == 1:
    p_count += 1
  elif flag == 2:
    q_count += 1
  else:
    r_count += 1
  total += score_max
  
print(total)

Submission status: Wrong Answer

Solution code:
apple_data = [int(n) for n in input().split()]
X = apple_data[0]
Y = apple_data[1]
A = apple_data[2]
B = apple_data[3]
C = apple_data[4]

redlist = sorted([int(n) for n in input().split()])[-X:]
greenlist = sorted([int(n) for n in input().split()])[-Y:]
clearlist = sorted([int(n) for n in input().split()],reverse=True)

# print(redlist)
# print(greenlist)
# print(clearlist)

for clear in clearlist:
    if redlist[0] <= greenlist[0]:
        if clear > redlist[0]:
            redlist.pop(0)
            redlist.append(clear)
    if greenlist[0] < redlist[0]:
        if clear > greenlist[0]:
            greenlist.pop(0)
            greenlist.append(clear)

sum = 0
for n in redlist:
    sum += n
for n in greenlist:
    sum += n

print(sum)

Submission status: Wrong Answer

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

red = sorted(list(map(int, input().split())), reverse=True)[0:x-1]
gre = sorted(list(map(int, input().split())), reverse=True)[0:y-1]
non = sorted(list(map(int, input().split())), reverse=True)

eat = red + gre + non

eat.sort(reverse=True)

print(sum(eat[0:x+y-1]))

Submission status: Wrong Answer

Solution code:
def Main(X, Y, A, B, C, p, q, r):
    p.sort()
    q.sort()
    r.sort()
    ans = 0
    p = p[-X:]
    q = q[-Y:]
    wa = X+Y
    for i in range(wa):
        if(len(r) and len(p) and len(q)):
            if p[-1] < r[-1] and q[-1] < r[-1]:
                ans += r.pop()
            elif p[-1] < q[-1]:
                ans += q.pop()
            else:
                ans += p.pop()
        elif(len(r) == 0 and len(p) and len(q)):
            if p[-1] < q[-1]:
                ans += q.pop()
            else:
                ans += q.pop()
        elif(len(r) and len(p)==0 and len(q)):
            if q[-1] < r[-1]:
                ans += r.pop()
            else:
                ans += q.pop()
        elif(len(r) and len(p) and len(q)==0):
            if p[-1] < r[-1]:
                ans += r.pop()
            else:
                ans += p.pop()
        elif(len(r)==0 and len(p)==0 and len(q)):
            ans += q.pop()
        elif(len(r)==0 and len(p) and len(q)==0):
            ans += p.pop()
        elif(len(r) and len(p)==0 and len(q)==0):
            ans += r.pop()
    return ans
def main():
    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()))
    print(Main(X, Y, A, B, C, p, q, r))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
xyabc = list(map(int,input().rsplit()))
p = list(map(int,input().rsplit()))
q = list(map(int,input().rsplit()))
r = list(map(int,input().rsplit()))
x = xyabc[0]
y = xyabc[1]
p.sort()
q.sort()

z =p[:x]+q[:y]
z = z + r
z.sort()
print(sum(z[:x+y]))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort()
a_list.reverse()
b_list.sort()
b_list.reverse()
c_list.sort()
c_list.reverse()
a_fin=x-1
b_fin=y-1
a_min=a_list[a_fin]
b_min=b_list[b_fin]
change=0
while (a_min < c_list[change] or b_min < c_list[change]):
    if (a_fin== -1 or b_fin== -1):
        break
    elif (a_min <= b_min  and  a_min < c_list[change]):
        a_list[a_fin] = c_list[change]
        a_fin -= 1
        change += 1
        if (change > c-1):
            break
    elif (a_min >= b_min  and  b_min < c_list[change]):
        b_list[b_fin] = c_list[change]
        b_fin -= 1
        change += 1
        if (change > c-1):
            break
answer=0
for i in range(0,x):
    answer = answer + a_list[i]
for j in range(0,y):
    answer = answer + b_list[j]
print(answer)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted((int(v) for v in input().split()))
q_list = sorted((int(v) for v in input().split()))
r_list = sorted((int(v) for v in input().split()))

yummy = 0
# 赤リンゴを食べる
for _ in range(X):
    if p_list[-1] >= r_list[-1]:
        yummy += p_list.pop()
        if len(p_list) == 0:
            p_list = [0]
    else:
        yummy += r_list.pop()
        if len(r_list) == 0:
            r_list = [0]
# 緑リンゴを食べる
for _ in range(Y):
    if q_list[-1] >= r_list[-1]:
        yummy += q_list.pop()
        if len(q_list) == 0:
            q_list = [0]
    else:
        yummy += r_list.pop()
        if len(r_list) == 0:
            r_list = [0]

print(yummy)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted((int(v) for v in input().split()))
q_list = sorted((int(v) for v in input().split()))
r_list = sorted((int(v) for v in input().split()))

yummy = 0
# 赤リンゴを食べる
for _ in range(X):
    if p_list[-1] > r_list[-1]:
        yummy += p_list.pop()
        if len(p_list) == 0:
            p_list = [0]
    else:
        yummy += r_list.pop()
        if len(r_list) == 0:
            r_list = [0]
# 緑リンゴを食べる
for _ in range(Y):
    if q_list[-1] > r_list[-1]:
        yummy += q_list.pop()
        if len(q_list) == 0:
            q_list = [0]
    else:
        yummy += r_list.pop()
        if len(r_list) == 0:
            r_list = [0]


# for _ in range(X + Y):
#     p, q, r = p_list[0], q_list[0], r_list[0]
#     print(p_list, q_list, r_list)
#     want = max(p, q, r)
#     if   p == want:
#         yummy += p_list.pop(0)
#         if len(p_list) == 0:
#             p_list = [0]
#     elif q == want:
#         yummy += q_list.pop(0)
#         if len(q_list) == 0:
#             q_list = [0]
#     else:
#         yummy += r_list.pop(0)
#         if len(r_list) == 0:
#             r_list = [0]

print(yummy)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted((int(v) for v in input().split()), reverse=True)
q_list = sorted((int(v) for v in input().split()), reverse=True)
r_list = sorted((int(v) for v in input().split()), reverse=True)

yummy = 0
# 赤リンゴを食べる
for _ in range(X):
    p, r = p_list[0], r_list[0]
    want = max(p, r)
    if want == p:
        yummy += p_list.pop(0)
        if len(p_list) == 0:
            p_list = [0]
    else:
        yummy += r_list.pop(0)
        if len(r_list) == 0:
            r_list = [0]
# 緑リンゴを食べる
for _ in range(Y):
    q, r = q_list[0], r_list[0]
    want = max(q, r)
    if want == q:
        yummy += q_list.pop(0)
        if len(q_list) == 0:
            q_list = [0]
    else:
        yummy += r_list.pop(0)
        if len(r_list) == 0:
            r_list = [0]


# for _ in range(X + Y):
#     p, q, r = p_list[0], q_list[0], r_list[0]
#     print(p_list, q_list, r_list)
#     want = max(p, q, r)
#     if   p == want:
#         yummy += p_list.pop(0)
#         if len(p_list) == 0:
#             p_list = [0]
#     elif q == want:
#         yummy += q_list.pop(0)
#         if len(q_list) == 0:
#             q_list = [0]
#     else:
#         yummy += r_list.pop(0)
#         if len(r_list) == 0:
#             r_list = [0]

print(yummy)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted(list(int(v) for v in input().split()), reverse=True)
q_list = sorted(list(int(v) for v in input().split()), reverse=True)
r_list = sorted(list(int(v) for v in input().split()), reverse=True)

yummy = 0
# 赤リンゴを食べる
for _ in range(X):
    p, r = p_list[0], r_list[0]
    want = max(p, r)
    if want == p:
        yummy += p_list.pop(0)
        if len(p_list) == 0:
            p_list = [0]
    else:
        yummy += r_list.pop(0)
        if len(r_list) == 0:
            r_list = [0]
# 緑リンゴを食べる
for _ in range(Y):
    q, r = q_list[0], r_list[0]
    want = max(q, r)
    if q == want:
        yummy += q_list.pop(0)
        if len(q_list) == 0:
            q_list = [0]
    else:
        yummy += r_list.pop(0)
        if len(r_list) == 0:
            r_list = [0]


# for _ in range(X + Y):
#     p, q, r = p_list[0], q_list[0], r_list[0]
#     print(p_list, q_list, r_list)
#     want = max(p, q, r)
#     if   p == want:
#         yummy += p_list.pop(0)
#         if len(p_list) == 0:
#             p_list = [0]
#     elif q == want:
#         yummy += q_list.pop(0)
#         if len(q_list) == 0:
#             q_list = [0]
#     else:
#         yummy += r_list.pop(0)
#         if len(r_list) == 0:
#             r_list = [0]

print(yummy)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	X, Y, A, B, C = map(int, input().split())
	p = [int(a) for a in input().split()]
	q = [int(a) for a in input().split()]
	r = [int(a) for a in input().split()]

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


	P = p[0:X]
	Q = q[0:Y]
	Z = min(C,X+Y)
	R = r[0:Z]

	s = P+Q+R

	s.sort(reverse=True)

	S = s[0:X+Y]

	ans = sum(S)

	print(ans)