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:
# E
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())))

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

for i in range(min(x, y, c)):
    if p[-1-i] > q[-1-i]:
        if q[-1-i] < r[-1-i]:
            q[-1-i] = r[-1-i]
            r.append(r[-1-i])
        else:
            continue
    elif p[-1-i] <= q[-1-i]:
        if p[-1-i] < r[-1-i]:
            p[-1-i] = r[-1-i]
            r.append(r[-1-i])
            
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(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ip=X-1
iq=Y-1
ir=0
#ans=0
P=p[0:X]
Q=q[0:Y]
#ans+=sum(P)+sum(Q)
while True:
    if ir>=C:
        break
    print(ir,ip,iq)
    if r[ir]<P[ip] and r[ir]<Q[iq]:
        break
    if P[ip]<Q[iq]:
        P[ip]=r[ir]
        #ans+=r[ir]-P[ip]
        if ip!=0:
            ip-=1
    else:
        Q[iq]=r[ir]
        #ans+=r[ir]-Q[iq]
        if iq!=0:
            iq-=1
    ir+=1
    print(P,Q)
print(sum(P)+sum(Q))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
ans=0
for i in range(x):
    if len(r)==0:
        _p=heapq.heappop(p)
        ans-=_p
        continue
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<=_r:
        ans-=_p
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(p,_p)
for i in range(y):
    if len(r)==0:
        _q=heapq.heappop(q)
        ans-=_q
        continue
    _q,_r=heapq.heappop(q),heapq.heappop(r)
    if _q<=_r:
        ans-=_q
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(q,_q)
print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
v = []
l = list(map(int, input().split()))
for i in range(a):
    v.append([l[i], 1])
l = list(map(int, input().split()))
for i in range(b):
    v.append([l[i], 2])
l = list(map(int, input().split()))
for i in range(c):
    v.append([l[i], 3])
v.sort(reverse=True)
r, g, res = 0, 0, 0
for i in range(len(v)):
    if v[i][1] == 1 and r < x:
        r += 1
        res += v[i][0]
    elif v[i][1] == 2 and g < y:
        g += 1
        res += v[i][0]
    elif v[i][1] == 3:
        if  r < x:
            r += 1
            res += v[i][0]
        elif g < y:
            g += 1
            res += v[i][0]
    if r == x and g == y:
        break
print(res)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = (int(x) for x in input().split())
p = sorted((int(x) for x in input().split()), reverse=True)
q = sorted((int(x) for x in input().split()), reverse=True)
r = sorted((int(x) for x in input().split()), reverse=True)
ans = sum(p[:x]) + sum(q[:y])
cnt = 0
cnt_a = 0
cnt_b = 0
for cnt in range(c):
    if (r[cnt] < p[x-cnt_a-1] and r[cnt] < q[y-cnt_b-1]) or (x-cnt_a-1 < 0 and y-cnt_b-1 < 0):
        break
    if p[x-cnt_a-1] < q[max(0,y-cnt_b-1)] and x-cnt_a-1 > -1:
        ans = (ans-p[x-cnt_a-1]) + r[cnt] 
        cnt_a += 1
        # cnt+=1
    elif p[max(0, x-cnt_a-1)] > q[y-cnt_b-1] and y-cnt_b-1 > -1:
        ans = (ans-q[y-cnt_b-1]) + r[cnt] 
        cnt_b += 1
        # cnt += 1
    else:
        # determine side
        j = 0
        try:
            while p[x-cnt_a-1-j] == q[y-cnt_b-1-j] and x-cnt_a-1-j > -1 and y-cnt_b-1-j > -1:
                j += 1
            if p[x-cnt_a-1-j] < q[y-cnt_b-1-j] and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 1
        except:
            if x > y and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
INPUT=input().split()
X=int(INPUT[0])
Y=int(INPUT[1])
A=int(INPUT[2])
#赤
B=int(INPUT[3])
#緑
C=int(INPUT[4])
#無色
RED=[0]*A
GREEN=[0]*B
NOCOL=[0]*C

INPUT=input().split()
for _ in range(A):
    RED[_]=int(INPUT[_])
INPUT=input().split()
for _ in range(B):
    GREEN[_]=int(INPUT[_])
INPUT=input().split()
for _ in range(C):
    NOCOL[_]=int(INPUT[_])
RED.sort()
GREEN.sort()
NOCOL.sort()
"""
取得した美味しさを昇順で並べた
"""
X_apple=[0]*X
Y_apple=[0]*Y
for _ in range(min(X,A)):
    X_apple[_]=RED[A-_-1]
    RED[A-_-1]=0
for _ in range(min(Y,B)):
    Y_apple[_]=GREEN[B-_-1]
    GREEN[B-_-1]=0
X_apple.sort()
Y_apple.sort()

i=0
if X_apple[i]==0:
    while(X_apple[i]==0):
        X_apple[i]=NOCOL[C-i-1]
        NOCOL[C-i-1]=0
        i+=1
else:
    while(X_apple[0]<NOCOL[C-1]):
        X_apple[0]=NOCOL[C-1]
        NOCOL[C-1]=0
        NOCOL.sort()

NOCOL.sort()
i=0
if Y_apple[i]==0:
    while(Y_apple[i]==0):
        Y_apple[i]=NOCOL[C-i-1]
        NOCOL[C-i-1]=0
        i+=1
else:
    while(Y_apple[0]<NOCOL[C-1]):
        Y_apple[0]=NOCOL[C-1]
        NOCOL[C-1]=0
        NOCOL.sort()

SUM=0
for _ in range(X):
    SUM+=X_apple[_]
for _ in range(Y):
    SUM+=Y_apple[_]
print(SUM)

Submission status: Wrong Answer

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

pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
import itertools
pl_ac = [0] + list(itertools.accumulate(pl))
ql_ac = [0] + list(itertools.accumulate(ql))
rl_ac = [0] + list(itertools.accumulate(rl))

dada = max(ql[-1], pl[-1], rl[-1])

import bisect
ans = 0
#　赤色をi個食べるとすると無職x-i
for i in range(x+1):
    tmp = 0
    if i > a or x - i > c or b + c - (x - i) < y:
        continue
    #あか
    tmp += pl_ac[-1] - pl_ac[-1-i]
    # #無職
    # tmp += rl_ac[-1] - ql_ac[-1-(x-i)]
    #残りの無職
    if x-i == 0:
        rl_c = rl[:]
    else:
        rl_c = rl[:-(x-i)]
    # ub以上のりんご何個ある？
    ub = dada + 1

    lb = -1
    while True:
        if ub == lb:
            target = ub
            break
        target = (ub + lb) // 2 + 1
        idx = bisect.bisect_left(ql, target)
        idx2 = bisect.bisect_left(rl_c, target)
        if (b - idx) + (c - (x - i) - idx2) >= y:
            lb = target
        else:
            ub = target - 1
    idx = bisect.bisect_left(ql, target)
    idx2 = bisect.bisect_left(rl_c, target)
    tmp += ql_ac[-1] - ql_ac[idx]
    tmp += rl_ac[-1] - rl_ac[idx2]
    gg = (b - idx) + (c - (x - i) - idx2) - y
    ans -= target * gg
    ans = max(tmp, ans)

print(ans)

Submission status: Wrong Answer

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

xx = sorted(xx, reverse=True)[:x]
yy = sorted(yy, reverse=True)[:y]
rr = sorted(rr, reverse=True)[:x+y]

ri = 0
xi = x
yi = y
happy = 0
for i in range(min(x+y, len(rr))):
    if (xx[xi-1] <= yy[yi-1]) and(xx[xi-1] < rr[ri]) and (xi > 0):
        xi -= 1
        ri +=1
        continue
    if (yy[yi-1] <= xx[xi-1]) and(yy[yi-1] < rr[ri]) and (yi > 0):
        yi -= 1
        ri +=1
        continue
print(sum(xx[:xi]) + sum(yy[:yi]) + sum(rr[:ri]))

Submission status: Wrong Answer

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

ans = 0
pi = min(X, len(p))
qi = min(Y, len(q))
ri = X-pi + Y-qi

ans += sum(p[0:pi])
ans += sum(q[0:qi])
ans += sum(r[0:ri])

while ri < len(r):
  if pi == 0 and qi == 0: break
  if pi == 0:
    if q[qi-1] > r[ri]: break
    ans += r[ri] - q[qi-1]
    ri += 1
    qi -= 1
  elif qi == 0:
    if p[pi-1] > r[ri]: break
    ans += r[ri] - p[pi-1]
    ri += 1
    pi -= 1
  else:
    v = min(p[pi-1], q[qi-1], r[ri])
    if v == p[pi-1]:
      ans += r[ri] - p[pi-1]
      ri += 1
      pi -= 1
    if v == q[qi-1]:
      ans += r[ri] - q[qi-1]
      ri += 1
      qi -= 1
    else: break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

X, Y, A, B, C = mi()
p = sorted(li())[-X:]
q = sorted(li())[-Y:]
r = sorted(li())

len_r = len(r)-1
a_p = p.pop(-1)
a_r = r.pop(-1)
cnt = 0

for i in range(X):
    if len_r <= 0:
        cnt += sum(p[-(X-i):]) + a_p
        break
    if a_p >= a_r:
        cnt += a_p
        if p!=[]:
            a_p = p.pop(-1)
        else:
            break
    else:
        cnt += a_r
        if len_r <= 0:
            #cnt += sum(p[-(X-i):]) + a_p
            a_r = 0
            #break
        else:
            a_r = r.pop(-1)
            len_r -= 1
        

a_q = q.pop(-1)

for i in range(Y):
    if a_q >= a_r:
        cnt += a_q
        #a_q = q.pop(-1)
        if q!=[]:
            a_q = q.pop(-1)
        else:
            break
    else:
        cnt += a_r
        if len_r <= 0:
        #if i!=(Y-1):
            #cnt += sum(q[-(Y-i):]) + a_q
            #break
            #break
            a_r = 0
        else:
            a_r = r.pop(-1)
            len_r -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
ans=0
for i in range(x):
    if len(r)==0:
        _p=heapq.heappop(p)
        ans-=_p
        continue
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<_r:
        ans-=_p
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(p,_p)
for i in range(y):
    if len(r)==0:
        _q=heapq.heappop(q)
        ans-=_q
        continue
    _q,_r=heapq.heappop(q),heapq.heappop(r)
    if _q<_r:
        ans-=_q
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(q,_q)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = (int(x) for x in input().split())
p = sorted((int(x) for x in input().split()), reverse=True)
q = sorted((int(x) for x in input().split()), reverse=True)
r = sorted((int(x) for x in input().split()), reverse=True)
ans = sum(p[:x]) + sum(q[:y])
cnt = 0
cnt_a = 0
cnt_b = 0
for cnt in range(c):
    if (r[cnt] < p[x-cnt_a-1] and r[cnt] < q[y-cnt_b-1]) or (x-cnt_a-1 < 0 and y-cnt_b-1 < 0):
        break
    if p[x-cnt_a-1] < q[min(0,y-cnt_b-1)] and x-cnt_a-1 > -1:
        ans = (ans-p[x-cnt_a-1]) + r[cnt] 
        cnt_a += 1
        # cnt+=1
    elif p[min(0, x-cnt_a-1)] > q[y-cnt_b-1] and y-cnt_b-1 > -1:
        ans = (ans-q[y-cnt_b-1]) + r[cnt] 
        cnt_b += 1
        # cnt += 1
    else:
        # determine side
        j = 0
        try:
            while p[x-cnt_a-1-j] == q[y-cnt_b-1-j] and x-cnt_a-1-j > -1 and y-cnt_b-1-j > -1:
                j += 1
            if p[x-cnt_a-1-j] < q[y-cnt_b-1-j] and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 1
        except:
            if x > y and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 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(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    ans+=p[i]
P.sort()
Q=[]
for i in range(Y):
    Q.append(q[i])
    ans+=q[i]
Q.sort()
rc=0
gc=0
tc=0
fr=False
fg=False
while(1):
    val1=ans
    val2=ans
    if tc>(C-1):
        break
    if rc>(X-1):
        fr=True
    if gc>(Y-1):
        fg=True
    if fr and fg:
        break
    if fr:
        b=r[tc]-Q[gc]
        if b<=0:
            break
        val2+=b
        ans=val2
        gc+=1
        tc+=1
        continue
    if gc:
        a=r[tc]-P[rc]
        if a<=0:
            break
        val1+=a
        ans=val1
        rc+=1
        tc+=1
        continue
    a=r[tc]-P[rc]
    b=r[tc]-Q[gc]
    if a<=0 and b<=0:
        break

    val1+=a
    val2+=b
    if val1>val2:
        rc+=1
        tc+=1
        ans=val1
    else:
        gc+=1
        tc+=1
        ans=val2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = 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()

ans = 0

while X > 0:
    if len(p) == 0:
        ans += r.pop()
        X -= 1
    elif len(r) == 0:
        ans += p.pop()
        X -= 1
    else:
        if p[-1] >= r[-1]:
            ans += p.pop()
            X -= 1
        else:
            ans += r.pop()
            X -= 1

while Y > 0:
    if len(q) == 0:
        ans += r.pop()
        Y -= 1
    elif len(r) == 0:
        ans += q.pop()
        Y -= 1
    else:
        if q[-1] >= r[-1]:
            ans += q.pop()
            Y -= 1
        else:
            ans += r.pop()
            Y -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, y, a, b, c = map(int, input().split(" "))
    ps = sorted(list(map(int, input().split(" "))), reverse=True)
    qs = sorted(list(map(int, input().split(" "))), reverse=True)
    rs = sorted(list(map(int, input().split(" "))), reverse=True)

    red_eat = ps[:x]
    blue_eat = qs[:y]

    #eats = sorted(red_eat + blue_eat + rs, reverse=True)
    eats = sorted(red_eat + blue_eat + rs, reverse=True)
    #print(eats)
    #eats_dict = collections.Counter(eats)
    #print(eats_dict)

    eats = sorted(ps + qs + rs, reverse=True)

    points = sum(eats[:(x+y)])
    print(points)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


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()))
    p=sorted(p,reverse=True)
    q=sorted(q,reverse=True)
    r=sorted(r,reverse=True)
    for i in range(max(a,b,c)):
        p.append(0)
        q.append(0)
        r.append(0)

    nowx=0
    nowy=0
    nowc=0
    tempp=0
    tempq=0
    tempr=0
    total=0
    for i in range(1,x+y+1):
        tempp = 0
        tempq = 0
        tempr = 0
        if nowx<x:
            tempp=p[nowx]
        if nowy<y:
            tempq=q[nowy]
        if nowc<c:
            tempc=r[nowc]
        tempmax=max(tempp,tempq,tempc)
        if tempmax==tempp:
            nowx+=1
            total+=tempp
        elif tempmax==tempq:
            nowy+=1
            total+=tempq
        elif tempmax==tempc:
            total += tempc
            nowc+=1
            if nowx>=x:
                nowy+=1
            elif nowy>=y:
                nowx+=1
            else:
                larger=p
                for i in range(max(a,b)):
                    if p[nowx+i]==q[nowy+i]:
                        continue
                    elif p[nowx+i]>q[nowy+i]:
                        larger=p
                        break
                    else:
                        larger=q
                        break


                if larger==p:
                    nowy += 1
                else:
                    nowx += 1

    print(total)


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
import collections
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()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] >= p[i] and r[k] >= q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            if q[j] > r[k]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


if __name__ == '__main__':
    # main()
    print(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()))

point = 0

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

for i in range(0, X + Y):
    point += all_taste[i]

print(point)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

red = p[:X]
green = q[:Y]
nocolor = r


heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)

for nc in nocolor:
    R = red[0]
    G = green[0]
    if R > nc and G > nc:
        break
    if nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green,nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red,nc)
    if nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red,nc)
    if nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green,nc)


print(sum(red)+sum(green))

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)

reds = deque(p)
greens = deque(q)
uncolor = deque(r)

# できるだけ値が大きいやつを使いたい
ans = 0
red_cnt = 0
green_cnt = 0

while True:
    # print(red_cnt, green_cnt, reds, greens, uncolor)
    if red_cnt == x and green_cnt == y:
        break

    # 赤の処理をするケース
    # 緑が終わってる、赤が緑より大きい
    if len(greens) == 0:
        if len(uncolor) > 0:
            if reds[0] >= uncolor[0]:
                eat = reds.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = reds.popleft()
        ans += eat
        red_cnt += 1
        continue

    if len(reds) == 0:
        if len(uncolor) > 0:
            if greens[0] >= uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = greens.popleft()
        ans += eat
        green_cnt += 1
        continue

    if len(uncolor) == 0:
        for i in range(x - red_cnt):
            eat = reds.popleft()
            ans += eat
        for i in range(y - green_cnt):
            eat = greens.popleft()
            ans += eat
        red_cnt = x
        green_cnt = y
        continue

    if red_cnt < x and green_cnt < y:
        if reds[0] > greens[0] and reds[0] >= uncolor[0]:
            eat = reds.popleft()
            ans += eat
            red_cnt += 1
        elif reds[0] < greens[0] and greens[0] >= uncolor[0]:
            eat = greens.popleft()
            ans += eat
            green_cnt += 1
        elif reds[0] == greens[0]:
            eat = greens.popleft()
            ans += eat
            green_cnt += 1
        elif reds[0] > greens[0]:
            if greens[0] >= uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            green_cnt += 1
        else:
            if reds[0] >= uncolor[0]:
                eat = reds.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            red_cnt += 1
    elif red_cnt < x:
        if reds[0] >= uncolor[0]:
            eat = reds.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        red_cnt += 1
    else:
        if greens[0] >= uncolor[0]:
            eat = greens.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        green_cnt += 1

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)
if len(r) > x + y:
  r = r[:x+y]

ans = sum(p) + sum(q)
cp = x - 1
cq = y - 1
for tmp in r:
  if p[cp] > q[cq]:
    if tmp > q[cq]:
      ans += tmp - q[cq]
      cq -= 1
    else:
      break
  else:
    if tmp > p[cp]:
      ans += tmp - p[cp]
      cp -= 1
    else:
      break
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)

pp=0
pq=0
pr=0
s=0
while x+y > 0:
    if x>0 and y>0 and pr < c:
        if p[pp]>=q[pq]:
            if p[pp]>=r[pr]:
                s+=p[pp]
                pp+=1
                x-=1
            else:
                s+=r[pr]
                pr+=1
                x-=1
        else:
            if q[pq]>=r[pr]:
                s+=q[pq]
                pq+=1
                y-=1
            else:
                s+=r[pr]
                pr+=1
                y-=1
    elif x>0 and y==0 and pr < c:
        if p[pp]>=r[pr]:
            s+=p[pp]
            pp+=1
            x-=1
        else:
            s+=r[pr]
            pr+=1
            x-=1
    elif x==0 and y>0 and pr < c:
        if q[pq]>=r[pr]:
            s+=q[pq]
            pq+=1
            y-=1
        else:
            s+=r[pr]
            pr+=1
            y-=1
    elif x>0 and y==0 and pr == c:
        s+=p[pp]
        pp+=1
        x-=1
    elif x==0 and y>0 and pr == c:
        s+=q[pq]
        pq+=1
        y-=1

print(s)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
lc=list(map(int,input().split()))
la.sort()
lb.sort()
lc.sort()
summ=0
while(x>0 or y>0):

	if(x>0 and y>0):
		if(c==0):
			summ+=la[a-1]+lb[b-1]
			a-=1
			b-=1
			x-=1
			y-=1
		else:

			if min(la[a-1],lb[b-1])<lc[c-1] :
			
				summ+=lc[c-1]+max(la[a-1],lb[b-1])
				
					#summ+=lc[c-1]
				if(max(la[a-1],lb[b-1])==la[a-1]):
					a-=1
					c-=1
					x-=1
					y-=1
				else:
					b-=1
					c-=1
					x-=1
					y-=1

			else:
				summ+=la[a-1]+lb[b-1]
				a-=1
				b-=1
				x-=1
				y-=1
	else:
		if(x!=0):
			if(c==0):
				summ+=la[a-1]
				a-=1
				x-=1
			else:
				if(la[a-1]<lc[c-1]):
					summ+=lc[c-1]
					c-=1
					x-=1
				else:
					summ+=la[a-1]
					a-=1
					x-=1
		if(y!=0):
			if c==0:
				summ+=lb[b-1]
				b-=1
				y-=1
			else:
				if(lb[b-1]<lc[c-1]):
					summ+=lc[c-1]
					c-=1
					y-=1
				else:
					summ+=lb[b-1]
					b-=1
					y-=1


print(summ)

Submission status: Wrong Answer

Solution code:
import collections
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()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] > p[i] and r[k] > q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            if q[j] > r[k]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


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

Submission status: Wrong Answer

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    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()))
    i,j,k = 0,0,0
    p.sort(reverse=1)
    q.sort(reverse=1)
    r.sort(reverse=1)
    res = 0
    while k<c and i<X and j<Y:
        s = p[i]
        t = q[j]
        u = r[k]
        if s<t and s<u:
            res += t+u
            j += 1
            k += 1
        elif t<s and t<u:
            res += s+u
            i += 1
            k += 1
        else:
            res += s+t
            i += 1
            j += 1
    if i==X:
        l = q[j:] + r[k:]
        l.sort(reverse=1)
        res += sum(l[:X+Y-i-j-k])
    elif j==Y:
        l = p[i:] + r[k:]
        l.sort(reverse=1)
        res += sum(l[:X+Y-i-j-k])
    else:
        l = p+q
        l.sort(reverse=1)
        res = sum(r) + sum(l[:X+Y-c])
    print(res)


if __name__ == '__main__':
    main()