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:
import sys
input = sys.stdin.readline
from heapq import heapify, heappop, heappush
from itertools import accumulate
x, y, a, b, c = map(int, input().split())
p_List = list(map(int, input().split()))
q_List = list(map(int, input().split()))
r_List = list(map(int, input().split()))
R_List = list(map(lambda x: x*(-1), r_List))
heapify(p_List)
heapify(q_List)
heapify(R_List)
diff_bet_p_R = 1
diff_bet_p_R = 1

for i in range(c):
    p_min = heappop(p_List)
    q_min = heappop(q_List)
    R_max = heappop(R_List)*(-1)
    diff_bet_p_R = R_max - p_min
    diff_bet_q_R = R_max - q_min 
    if diff_bet_p_R > diff_bet_q_R and diff_bet_p_R>0:
        heappush(p_List, R_max)
        heappush(q_List, q_min)
    elif diff_bet_q_R > diff_bet_p_R and diff_bet_q_R>0:
        heappush(q_List, R_max)
        heappush(p_List, p_min)
    else:
        heappush(p_List, p_min)
        heappush(q_List, q_min)
        break
p_List.sort()
q_List.sort()
p_Sum = [0]+list(accumulate(p_List))
q_Sum = [0]+list(accumulate(q_List))
print(p_Sum[a]-p_Sum[a-x] + q_Sum[b]-q_Sum[b-y])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
apples = []
for i in range(3):
    apples += list(map(int, input().split()))
apples.sort(reverse=True)
print(sum(apples[: x + y]))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
Lista = sorted(list(map(int, input().split())), reverse = True)
Listb = sorted(list(map(int, input().split())), reverse = True)
Listc = sorted(list(map(int, input().split())), reverse = True)
if x < a:
    del Lista[x:a]
if y < b:
    del Listb[y:b]
List = sorted(Lista + Listb, reverse = True)
while len(Listc) > 0:
    if List[-1] < Listc[0]:
        List[-1] = Listc[0]
        List = sorted(List, reverse = True)
        del Listc[0]
    else:
        break
print(sum(Lista) + sum(Listb))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
Lista = sorted(list(map(int, input().split())), reverse = True)
Listb = sorted(list(map(int, input().split())), reverse = True)
Listc = sorted(list(map(int, input().split())), reverse = True)
if x < a:
    del Lista[x:a]
if y < b:
    del Listb[y:b]
while len(Listc) > 0:
    if Lista[-1] < Listb[-1]:
        if Lista[-1] < Listc[0]:
            Lista[-1] = Listc[0]
            Lista = sorted(Lista, reverse = True)
            del Listc[0]
        else:
            break
    else:
        if Listb[-1] < Listc[0]:
            Listb[-1] = Listc[0]
            Listb = sorted(Listb, reverse = True)
            del Listc[0]
        else:
            break
print(Lista)
print(Listb)
print(sum(Lista) + sum(Listb))

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)[:max(x,y)]


print(sum(sorted(p + q + r, reverse=True)[:x+y]))

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)[:min(x,y)]


print(sum(sorted(p + q + r, reverse=True)[:x+y]))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
ans1 = 0
ans2 = 0
p1.sort(reverse = True)
p2.sort(reverse = True)
p3.sort(reverse = True)
for i in range(0, max(x,y)):
  p3.append(0)
for i in range(0,x):
  ans1= ans1 + max(p1[i],p3[0])
  if(p3[0]>p1[i]):
    del p3[0]
for i in range(0,y):
  ans2= ans2 + max(p2[i],p3[0])
  if(p3[0]>p2[i]):
    del p3[0]
print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int, input().split())
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
ans1 = 0
ans2 = 0
p1.sort(reverse = True)
p2.sort(reverse = True)
p3.sort(reverse = True)
for i in range(0,x):
  ans1= ans1 + max(p1[i],p3[0])
  if(p3[0]>p1[i]):
    p3[0] = 0
for i in range(0,y):
  ans2= ans2 + max(p2[i],p3[0])
  if(p3[0]>p2[i]):
    p3[0] = 0
print(ans1+ans2)

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()
tx = 0
ty = 0
sc= 0
while tx != x or ty != y:
    fp = True
    fq = True
    fr = True
    if p and r:
        if p[-1] >= r[-1] and tx < x:
            sc += p.pop(-1)
            tx += 1
            fp = False
    if q and r:
        if q[-1] >= r[-1] and ty < y:
            sc += q.pop(-1)
            ty += 1
            fq = False
    if p and r:
        if p[-1] <= r[-1] and tx < x:
            sc += r.pop(-1)
            tx += 1
            fr = False
    if q and r:
        if q[-1] <= r[-1] and ty < y:
            sc += r.pop(-1)
            ty += 1
            fr = False
    if fp:
        if p and tx < x:
            sc += p.pop(-1)
            tx += 1
    if fq:
        if q and ty < y:
            sc += q.pop(-1)
            ty += 1
    if fq:
        if r and tx < x:
            sc += r.pop(-1)
            tx += 1
        elif r and ty < y:
            sc += r.pop(-1)
            ty += 1
print(sc)

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()
tx = 0
ty = 0
sc= 0
while tx != x or ty != y:
    if p and r:
        if p[-1] >= r[-1] and tx < x:
            sc += p.pop(-1)
            tx += 1
    if q and r:
        if q[-1] >= r[-1] and ty < y:
            sc += q.pop(-1)
            ty += 1
    if p and r:
        if p[-1] <= r[-1] and tx < x:
            sc += r.pop(-1)
            tx += 1
    if q and r:
        if q[-1] <= r[-1] and ty < y:
            sc += r.pop(-1)
            ty += 1
    if p and tx < x:
        sc += p.pop(-1)
        tx += 1
    elif q and ty < y:
        sc += q.pop(-1)
        ty += 1
    elif r and tx < x:
        sc += r.pop(-1)
        tx += 1
    elif r and ty < y:
        sc += r.pop(-1)
        ty += 1
print(sc)

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()))
# print(p,q)
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
p = [int(1e10)]+p[:x]
q = [int(1e10)]+q[:y]
k = 0
i, j = x, y
# print(p, q)
while 1:
   if k >= c:
      break
   if min(p[i], q[j]) >= r[k] :
      break
   if p[i] < r[k] :
      p[i] = r[k]
      i -= 1
   else :
      q[j] = r[k]
      j -=1
   k += 1
print(sum(p[1:])+sum(q[1:]))

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()))
# print(p,q)
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
p = [int(1e10)]+p[:x]
q = [int(1e10)]+q[:y]
k = 0
i, j = x, y
# print(p, q)
while 1:
   if i <= 0 and j <= 0 or k >= c:
      break
   if min(p[i], q[j]) >= r[k] :
      break
   if p[i] < r[k] :
      p[i] = r[k]
      i -= 1
   else :
      q[j] = r[k]
      j -=1
   k += 1
print(sum(p[1:])+sum(q[1:]))

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()))
# print(p,q)
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)
p = [1e10]+p[:x]
q = [1e10]+q[:y]
k = 0
i, j = x, y
# print(p, q)
while 1:
   if i <= 1 and j <= 1 or k >= c:
      break
   if min(p[i], q[j]) >= r[k] :
      break
   if p[i] < r[k] :
      p[i] = r[k]
      i -= 1
   else :
      q[j] = r[k]
      j -=1
   k += 1
print(sum(p[1:])+sum(q[1:]))

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C= list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort(reverse=True)
P = P[:X]
heapq.heapify(P)
Q = list(map(int, input().split()))
Q.sort(reverse=True)
Q = Q[:Y]
heapq.heapify(Q)
R = list(map(lambda x: -int(x), input().split()))
heapq.heapify(R)
for r in R:
    r = -r
    p_min = P[0]
    q_min = Q[0]
    if p_min <= q_min and p_min < r:
        heapq.heapreplace(P, r)
    elif q_min <= p_min and q_min < r:
        heapq.heapreplace(Q, r)
    else:
        break
print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
er, eg, r, g, c = list(map(int, input().split()))
rd = sorted(list(map(int, input().split())))
gd = sorted(list(map(int, input().split())))
cd = sorted(list(map(int, input().split())))
rc = r-1
cc = c-1
gc = g-1
total = 0

while er != 0:
    if cc != 0 and rd[rc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += rd[rc]
        rc -= 1
    er -= 1
while eg != 0:
    if cc != 0 and gd[gc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += gd[gc]
        gc -= 1
    eg -= 1
print(total)

Submission status: Wrong Answer

Solution code:
er, eg, r, g, c = list(map(int, input().split()))
rd = sorted(list(map(int, input().split())))
gd = sorted(list(map(int, input().split())))
cd = sorted(list(map(int, input().split())))
rc = r-1
cc = c-1
gc = g-1
total = 0
while er != 0:
    if rd[rc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += rd[rc]
        rc -= 1
    er -= 1
while eg != 0:
    if gd[gc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += gd[gc]
        gc -= 1
    eg -= 1
print(total)

Submission status: Wrong Answer

Solution code:
er, eg, r, g, c = list(map(int, input().split()))
rd = sorted(list(map(int, input().split())))
gd = sorted(list(map(int, input().split())))
cd = sorted(list(map(int, input().split())))
rc = r-1
cc = c-1
gc = g-1
total = 0

while er != 0:
    if rd[rc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += rd[rc]
        rc -= 1
    er -= 1
while eg != 0:
    if gd[gc] < cd[cc]:
        total += cd[cc]
        cc -= 1
    else:
        total += gd[gc]
        gc -= 1
    eg -= 1
print(total)

Submission status: Wrong Answer

Solution code:
#コンマで区切る
A_list = input().split(' ')
X = A_list[0]
Y = A_list[1]

    
#コンマで区切る
p_list = input().split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
p_list = sorted(p_list, reverse=True)
#print(p_list)
#コンマで区切る
q_list = input().split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
q_list = sorted(q_list, reverse=True)

#コンマで区切る
r_list = input().split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
r_list = sorted(r_list, reverse=True)    

ans_list = []
#無色を考えない
del p_list[int(X):]
del q_list[int(Y):]

ans_list = p_list
ans_list.extend(q_list)
ans_list = sorted(ans_list, reverse=True)



for i in range(len(ans_list)):
  if(r_list!=[]):
    if(ans_list[i] < r_list[0]):
      ans_list[i] = r_list[0]
      r_list.remove(r_list[0])
    
print(sum(ans_list))

Submission status: Wrong Answer

Solution code:
#コンマで区切る
A_list = input().split(' ')
X = A_list[0]
Y = A_list[1]

    
#コンマで区切る
p_list = input().split(' ')
for i in range(len(p_list)):
    p_list[i] = int(p_list[i])
p_list = sorted(p_list, reverse=True)
print(p_list)
#コンマで区切る
q_list = input().split(' ')
for i in range(len(q_list)):
    q_list[i] = int(q_list[i])
q_list = sorted(q_list, reverse=True)

#コンマで区切る
r_list = input().split(' ')
for i in range(len(r_list)):
    r_list[i] = int(r_list[i])
r_list = sorted(r_list, reverse=True)    

ans_list = []
#無色を考えない
del p_list[int(X):]
del q_list[int(Y):]

ans_list = p_list
ans_list.extend(q_list)
ans_list = sorted(ans_list, reverse=True)



for i in range(len(ans_list)):
  if(r_list!=[]):
    if(ans_list[i] < r_list[0]):
      ans_list[i] = r_list[0]
      r_list.remove(r_list[0])
    
print(sum(ans_list))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = sorted(list(map(int, input().split())), reverse = True)

s = []

for i in range(x):
    p_e = p.pop()
    s.append(p_e)

for i in range(y):
    q_e = q.pop()
    s.append(q_e)

S = sum(s)
s.sort(reverse = True)

lim = c
if x + y < c:
    lim = x + y


k = x+y-1

for i in range(lim):
    while k > i:
        if r[i] > s[k]:
            S += r[i]
            S-= s[k]
            k -= 1
        if r[i] <= s[k]:
            break

print(S)

Submission status: Wrong Answer

Solution code:
#n,x,y=map(int,input())
# Queue
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()
p=deque(p[a-x:])
q=deque(q[b-y:])
r.sort()
for ri in r:
    if ri > p[0] and q[0] >= p[0]:
        p.popleft()
        p.append(ri)
        continue
    if ri > q[0] and p[0] >= q[0]:
        q.popleft()
        q.append(ri)
print(sum(p)+sum(q))

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""

Submission status: Wrong Answer

Solution code:
#n,x,y=map(int,input())
# Queue
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()
p=deque(p[a-x:])
q=deque(q[b-y:])
r.sort()
for ri in r:
    if ri > p[0] and q[0] >= p[0]:
        p.popleft()
        print(ri)
        p.append(ri)
        continue
    if ri > q[0] and p[0] >= q[0]:
        q.popleft()
        print(ri)
        q.append(ri)
print(sum(p)+sum(q))

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""

Submission status: Wrong Answer

Solution code:
#n,x,y=map(int,input())
# Queue
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()
p=deque(p[a-x:])
q=deque(q[b-y:])
r.sort()
for ri in r:
    if ri > p[0] and q[0] > p[0]:
        p.popleft()
        p.append(ri)
    if ri > q[0] and p[0] > q[0]:
        q.popleft()
        q.append(ri)

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

"""
1 2 2 2 1
2 4
5 1
3
->12
2 2 2 2 2
8 6
9 1
2 1
->25
"""

Submission status: Wrong Answer

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


p_counter = 0
q_counter = 0
r_counter = 0
total = 0
p2 = p[ p_counter]
q2 = q[ q_counter]
r2 = r[ r_counter]
l = [ r2, p2, q2]
while p_counter +q_counter+r_counter < X+Y:
    m = max(l)
    total+=m
    index = l.index(m)
    print(l)
    print(m)
    if index == 0:
        r_counter+=1
        if r_counter >= len(r):
            r2 = 0
        else:
            r2 = r[r_counter]
    elif index == 1:
        p_counter +=1
        if p_counter >= X:
            p2 = 0
        else:
            p2 = p[p_counter]
    else:
        q_counter+=1
        if q_counter >= Y:
            q2 = 0
        else:
            q2 = q[q_counter]
    l = [r2, p2, q2]
print(total)

Submission status: Wrong Answer

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

p_counter = 0
q_counter = 0
r_counter = 0
total = 0
p2 = p[ p_counter]
q2 = q[ q_counter]
r2 = r[ r_counter]
l = [ r2, p2, q2]
while p_counter +q_counter+r_counter < X+Y:
    m = max(l)
    total+=m
    index = l.index(m)
    if index == 0:
        r_counter+=1
        if r_counter >= len(r)-2:
            r2 = 0
        else:
            r2 = r[r_counter]
    elif index == 1:
        p_counter +=1
        if p_counter >= len(p)-2:
            p2 = 0
        else:
            p2 = p[p_counter]
    else:
        q_counter+=1
        if q_counter >= len(q)-2:
            q2 = 0
        else:
            q2 = q[q_counter]
    l = [r2, p2, q2]
print(total)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    X,Y,A,B,C=mis()
    p=lmis()
    q=lmis()
    r=lmis()
    p.sort(reverse=True)
    p = p[:A]
    q.sort(reverse=True)
    q = q[:B]
    print(sum(list(reversed(sorted(p+q+r)))[:X+Y]))


main()

Submission status: Wrong Answer

Solution code:
want_red, want_green, have_red, have_green, have_white = [int(n) for n in input().rstrip().split()]


red_deliciousness = sorted([[int(n),'red'] for n in input().rstrip().split()], reverse=True)[:want_red]
green_deliciousness = sorted([[int(n), 'green'] for n in input().rstrip().split()], reverse=True)[:want_green]
white_deliciousness = sorted([[int(n), 'white'] for n in input().rstrip().split()], reverse=True)[:want_red+want_green]


take_red=0
take_green=0
take_white=0

candidate_red = sorted(red_deliciousness+white_deliciousness[:want_red],reverse=True)[:want_red]
candidate_green = sorted(green_deliciousness+white_deliciousness[take_white:want_green+take_white],reverse=True)[:want_green]


for r in range(want_red):
    take_red+=candidate_red[r][0]#白かどうか印をつける必要はなかった
    if candidate_red[r][1]=='white':
        take_white+=1

for g in range(want_green):
    take_green += candidate_green[g][0]


happiness = take_red+take_green
print(happiness)

Submission status: Wrong Answer

Solution code:
want_red, want_green, have_red, have_green, have_white = [int(n) for n in input().rstrip().split()]

red_shortage = want_red-have_red
green_shortage = want_green-have_green

red_deliciousness = sorted([[int(n),'red'] for n in input().rstrip().split()], reverse=True)[:want_red]
green_deliciousness = sorted([[int(n),'green'] for n in input().rstrip().split()], reverse=True)[:want_green]
white_deliciousness = sorted([[int(n), 'white'] for n in input().rstrip().split()], reverse=True)[:want_red+want_green]

take_red=0
take_green=0
take_white=0

candidate_red = sorted(red_deliciousness+white_deliciousness[:want_red],reverse=True)[:want_red]
candidate_green = sorted(green_deliciousness+white_deliciousness[take_white:want_green],reverse=True)[:want_green]


for r in range(want_red):
    take_red+=candidate_red[r][0]
    if candidate_red[r][1]=='white':
        take_white+=1

for g in range(want_green):
    take_green += candidate_green[g][0]
happiness = take_red+take_green
print(happiness)

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]

total=sorted(p+q+r,reverse=True)[:(x+y)]
print(sum(total))

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)

k = 0
i = x-1
j = y-1

while k <= c-1 and   (p[i] < r[k] or q[j] < r[k]):
  if p[i] <= q[j] and p[i] < r[k]:
    p[i] = r[k]
    if i > 0:
      i -= 1
  
    k += 1
  elif p[i] > q[j] and q[j] < r[k]:
    q[j] = r[k]
    if i > 0:
      j -= 1
    k += 1
  

#print(p)
#print(q)
    
sum = 0
for ii in range(x):
  sum += p[ii]

for jj in range(y):
  sum += q[jj]
  
print(sum)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
p, pi = sorted(list(map(int, input().split())), reverse=True)[:X] + [-1], 0
q, qi = sorted(list(map(int, input().split())), reverse=True)[:Y] + [-1], 0
r, ri = sorted(list(map(int, input().split())), reverse=True) + [-1], 0
ans, nX, nY = 0, 0, 0
while nX < X or nY < Y:
    if r[ri] >= p[pi] and r[ri] >= q[qi]:
        if nX < X and nY < Y:
            if p[pi] >= q[qi]:
                nY += 1
            else:
                nX += 1
        elif nX < X:
            nX += 1
        elif nY < Y:
            nY += 1
        ans += r[ri]
        ri += 1
    elif nX < X:
        nX += 1
        ans += p[pi]
        pi += 1
    elif nY < Y:
        nY += 1
        ans += q[qi]
        qi += 1

print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
p, pi = sorted(list(map(int, input().split())), reverse=True)[:X] + [-1], 0
q, qi = sorted(list(map(int, input().split())), reverse=True)[:Y] + [-1], 0
r, ri = sorted(list(map(int, input().split())), reverse=True) + [-1], 0
ans, nX, nY = 0, 0, 0
while nX < X or nY < Y:
    if r[ri] >= p[pi] and r[ri] >= q[qi]:
        if nX < X and nY < Y:
            if p[pi] >= q[qi]:
                nX += 1
            else:
                nY += 1
        elif nX < X:
            nX += 1
        elif nY < Y:
            nY += 1
        ans += r[ri]
        ri += 1
    elif nX < X:
        nX += 1
        ans += p[pi]
        pi += 1
    elif nY < Y:
        nY += 1
        ans += q[qi]
        qi += 1

print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = (int(i) for i in input().split());

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);
color.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c and color[usedc] >= red[usedr] and color[usedc] >= green[usedg]:
        res += color[usedc];
        usedc += 1;
    elif (red[usedr] >= green[usedg] or usedg == y) and usedr < a:
        res += red[usedr];
        usedr += 1;
    elif usedg < y:
        res += green[usedg];
        usedg += 1;
    else:
        res += color[usedc];
        usedc += 1;

print(res);

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = (int(i) for i in input().split());

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);
color.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c and color[usedc] >= red[usedr] and color[usedc] >= green[usedg]:
        res += color[usedc];
        usedc += 1;
    elif (red[usedr] >= green[usedg] or usedg == y) and usedr < a:
        res += red[usedr];
        usedr += 1;
    else:
        res += green[usedg];
        usedg += 1;

print(res);

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = (int(i) for i in input().split());

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);
color.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c:
        if (color[usedc] >= red[usedr] and color[usedc] >= green[usedg]) or (usedg == y and usedr == x):
            res += color[usedc];
            usedc += 1;
        elif (red[usedr] >= green[usedg] and usedr < x) or (usedg == y):
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;
    else:
        if (red[usedr] >= green[usedg] and usedr < x) or (usedg == y):
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;

print(res);

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = (int(i) for i in input().split());

red = [int (i) for i in input().split()];
green = [int (i) for i in input().split()];
color = [int (i) for i in input().split()];

usedr = 0;
usedg = 0;
usedc = 0;
res = 0;

red.sort(reverse=True);
green.sort(reverse=True);
color.sort(reverse=True);

red.append(0);
green.append(0);
color.append(0);

while True:
    #print(usedr, usedg, usedc);
    if usedr + usedg + usedc == x + y:
        break;
    if usedc < c:
        if (color[usedc] >= red[usedr] and color[usedc] >= green[usedg]) or (usedg == y and usedr == x):
            res += color[usedc];
            usedc += 1;
        elif (red[usedr] >= green[usedg] and usedr < x) or (usedg == y):
            res += red[usedr];
            usedr += 1;
        else:
            res += green[usedg];
            usedg += 1;
    else:
        if usedr < x:
            res += red[usedr];
            usedr += 1;
        if usedg < y:
            res += green[usedg];
            usedg += 1;

print(res);

Submission status: Wrong Answer

Solution code:
x, y, a,b, c = map(int, input().split())
P = list(map(int, input().split())); P.reverse()
Q = list(map(int, input().split())); Q.reverse()
R = list(map(int, input().split())); R.reverse()

ans = P[:x] + Q[:y] + R
ans.sort(); ans.reverse()
ans = ans[:(x + y)]

print (sum(ans))

Submission status: Wrong Answer

Solution code:
x, y, a,b, c = map(int, input().split())
P = list(map(int, input().split())); P.reverse()
Q = list(map(int, input().split())); Q.reverse()
R = list(map(int, input().split())); R.reverse()

ans = 0
PQ = P[:x] + Q[:y]; PQ.sort(); PQ.reverse()

for i in range(len(PQ)):
    if max(PQ) >= max(R):
        ans += max(PQ)
    else:
        ans += max(R)
        del R[0]
    del PQ[0]

print (ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
auma=list(map(int,input().split()))
buma=list(map(int,input().split()))
cuma=list(map(int,input().split()))
auma.sort()
buma.sort()
cuma.sort(reverse=True)

for i in range(a-x):
  del auma[0]
for i in range(b-y):
  del buma[0]

d=[]
for i in range(c):
  if auma[0]<cuma[0] and auma[0]<buma[0]:
    d.append(cuma[0])
    del auma[0]
    del cuma[0]
    a-=1
  elif buma[0]<cuma[0] and auma[0]>buma[0]:
    d.append(cuma[0])
    del buma[0]
    del cuma[0]
    b-=1
  else:
    break

print(str(sum(auma)+sum(buma)+sum(d)))

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()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
ans=0
ccounter=0
for i in range(0,X):
    ans=p[i]+ans
for i in range(0,Y):
    ans=q[i]+ans
for i in range(0,X):
    if i>=C:
      break
    if p[X-1-i]<r[i]:
        ccounter=ccounter+1
        ans=ans-p[X-1-i]+r[i]
    else:
        break
for i in range(0,Y):
    if i+ccounter>=C:
        break
    if q[Y-1-i]<r[i+ccounter]:
        ans=ans-q[Y-1-i]+r[i+ccounter]
        ccounter=ccounter+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()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
ans=0
ccounter=0
for i in range(0,X):
    ans=p[i]+ans
for i in range(0,Y):
    ans=q[i]+ans
for i in range(0,X):
    if p[X-1-i]<r[i]:
        ccounter=ccounter+1
        ans=ans-p[X-1-i]+r[i]
    else:
        break
for i in range(0,Y):
    if i+ccounter>=C:
        break
    if q[Y-1-i]<r[i+ccounter]:
        ans=ans-q[Y-1-i]+r[i+ccounter]
        ccounter=ccounter+1
    else:
        break
print(ans)