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 = list(map(int,input().split()));
p = list(map(int,input().split()));
q = list(map(int,input().split()));
r = list(map(int,input().split()));

umami = [[0]*2 for i in range(a+b+c)];

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];
for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
    j += 1;

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 (x-1-cnt_a) < 0 and  y-1-cnt_b < 0:
        break
    pa = max(0, x-1-cnt_a)
    pb = max(0, y-1-cnt_b)
    if r[cnt] < p[pa] and r[cnt] < q[pb]:
        break
    if p[pa] > q[pb]:
        ans  = ans - q[pb] + r[cnt]
        cnt_b += 1
        q[pb] = r[cnt]
    elif p[pa] < q[pb]:
        ans = ans - p[pa] + r[cnt]
        cnt_a += 1
        q[pa] = r[cnt]
    else:
        j = 0
        while p[pa] == q[pb] and pa - j > -1 and pb - j > -1:
            j += 1
        if p[pa-j] > q[pb-j]:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        elif p[pa-j] < q[pb-j]:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif x > y and x-1-cnt_a >= 0:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif y-1-cnt_b >= 0:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        else:
            break
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                idx ^= 1
                if si[idx] <= 0:
                    break
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

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()
p = p[:x]
q = q[:y]

p.append(10**9+1)
q.append(10**9+1)
r.append(10**9+1)
result = sum(p+q)-2*(10**4)
ii, jj = x+y, c
for i in range(c):
    if p[x-1]<r[c-1]:
        result += r[c-1]-p[x-1]
        c -= 1
        x -= 1
    elif q[y-1]<r[c-1]:
        result += r[c-1]-q[y-1]
        c -= 1
        y -= 1
    else:
        break
    if c<0:
        break
print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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 = sum(p[-x:])+sum(q[-y:])
x_pos = -x
y_pos = -y
#print(ans)
for i in range(c):
    #したから見ていく
    #print(i,r[i],p[x_pos],q[y_pos])
    if min(p[x_pos],q[y_pos]) >= r[i]:
        continue
    elif p[x_pos] > q[y_pos]:
        ans += r[i] - q[y_pos]
        y_pos += 1
    else:
        ans += r[i] - p[x_pos]
        x_pos += 1
    if x_pos == 0:
        p.append(10**5)
        x_pos = -1
    if y_pos == -b:
        q.append(10**5)
        y_pos = -1
print(ans)

Submission status: Wrong Answer

Solution code:
input_1st = input()
input_2nd = input()
input_3rd = input()
input_4th = input()

split_input_1st = input_1st.split()
split_input_2nd = list(map(int, input_2nd.split()))
split_input_3rd = list(map(int, input_3rd.split()))
split_input_4th = list(map(int, input_4th.split()))

x = int(split_input_1st[0])
y = int(split_input_1st[1])
a = int(split_input_1st[2])
b = int(split_input_1st[3])
c = int(split_input_1st[4])

result = 0

red_apple_list = split_input_2nd
green_apple_list = split_input_3rd
for i in range(len(split_input_4th)):
    if i % 2 != 0:
        red_apple_list.append(split_input_4th[i])
    else:
        green_apple_list.append(split_input_4th[i])
red_apple_list = sorted(red_apple_list, reverse=True)
green_apple_list = sorted(green_apple_list, reverse=True)
for i in range(x):
    result += red_apple_list[i]
for i in range(y):
    result += green_apple_list[i]
    
print(result)

Submission status: Wrong Answer

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

umami = [[0]*2 for i in range(a+b+c)];

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];
for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
    j += 1;
    print(numr,numg,ans);

print(ans);

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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 = sum(p[-x:])+sum(q[-y:])
x_pos = -x
y_pos = -y
print(ans)
for i in range(c):
    #したから見ていく
    #print(i,r[i],p[x_pos],q[y_pos])
    if min(p[x_pos],q[y_pos]) >= r[i]:
        continue
    elif p[x_pos] > q[y_pos]:
        ans += r[i] - q[y_pos]
        y_pos += 1
    else:
        ans += r[i] - p[x_pos]
        x_pos += 1
    if x_pos == 0:
        p.append(10**5)
        x_pos = -1
    if y_pos == -b:
        q.append(10**5)
        y_pos = -1
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=(int(x) for x in 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
tmp=x-1
tmp2=y-1
for i in range(x):
    ans+=p[i]
for i in range(y):
    ans+=q[i]
for i in range(c):
    if p[tmp] > q[tmp2] and r[i]>q[tmp2]:
        ans+=r[i]-q[tmp2]
        tmp2-=1
    elif r[i] > p[tmp]:
        ans+=r[i]-p[tmp]
        tmp-=1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq as hq

x,y,a,b,c=map(int,input().split())
R=list(map(int,input().split()))
R=list(map(lambda x: x*(-1), R))
G=list(map(int,input().split()))
G=list(map(lambda x: x*(-1), G))
N=list(map(int,input().split()))
N=list(map(lambda x: x*(-1), N))
hq.heapify(R)
hq.heapify(G)
hq.heapify(N)
r=-hq.heappop(R)
g=-hq.heappop(G)
n=-hq.heappop(N)

ans=0
now=x+y
while now:
    if r<=n and g<=n and c>0:
        ans+=n
        c-=1
        if N:
            n=-hq.heappop(N)
        else:
            n=0
    elif r<=g and y>0:
        ans+=g
        y-=1
        if G:
            g=-hq.heappop(G)
        else:
            g=0
    else:
        ans+=r
        x-=1
        if R:
            r=-hq.heappop(R)
        else:
            r=0
    now-=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 = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)

ans = 0
ans += sum(p[:x])+sum(q[:y])
lp = (p[:x])
lq = (q[:y])
#print(lp)
#print(lq)
flag = 0
for i in range(x):
    if lp[i] < r[0]:
        del lp[:i]
        flag = 1
        break
if flag == 0:
  lp = []
  
flag = 0
for i in range(y):
    if lq[i] < r[0]:
        del lq[:i]
        flag = 1
        break
if flag == 0:
  lq = []
        
temp1 = 0
temp2 = 0
#print(lp)
#print(lq)
for i in range(1,10**9):
    #if lp[i] >= r[i] and lq[i] >= r[i]:
    #    break
    if i == max(x,y) or i == c+1 or (len(lq) < i and len(lp) < i):
      break
    elif i == y or len(lq) < i:
        temp2 = ans - lp[-i] + r[i-1]
    elif i == x or len(lp) < i:
        temp1 = ans - lq[-i] + r[i-1]
    else:
        temp1 = ans - lp[-i] + r[i-1]
        temp2 = ans - lq[-i] + r[i-1]
    ans = max(temp1,temp2,ans)
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)
q = sorted(list(map(int, input().split())),reverse=True)
r = sorted(list(map(int, input().split())),reverse=True)

reds=sorted(p[:min(x,len(p))])
grns=sorted(q[:min(y,len(q))])
rc=0
gc=0

if len(reds)<x:
    reds+=r[:(x-len(reds))]
    reds=sorted(reds)

if len(grns)<y:
    grns+=r[:(y-len(grns))]
    grns=sorted(grns)

from collections import deque

reds=deque(reds)
grns=deque(grns)

for i in range(len(r)):
    #print(reds,grns,r)
    if r[i]>min(reds[0],grns[0]):
        if reds[0]>=grns[0]:
            grns.popleft()
            grns.appendleft(r[i])
        else:
            reds.popleft()
            reds.appendleft(r[i])
    else:
        break
print(sum(reds)+sum(grns))

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                si[idx] = 0
                idx ^= 1
                if si[idx] == 0:
                    break
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

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 (x-1-cnt_a) < 0 and  y-1-cnt_b < 0:
        break
    pa = max(0, x-1-cnt_a)
    pb = max(0, y-1-cnt_b)
    if r[cnt] < p[pa] and r[cnt] < q[pb]:
        break
    if p[pa] > q[pb]:
        ans  = ans - q[pb] + r[cnt]
        cnt_b += 1
        q[pb] = r[cnt]
    elif p[pa] < q[pb]:
        ans = ans - p[pa] + r[cnt]
        cnt_a += 1
        q[pa] = r[cnt]
    else:
        j = 0
        while p[pa] == q[pb] and pa - j > -1 and pb - j > -1:
            j += 1
        if p[pa-j] > q[pb-j]:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        elif p[pa-j] < q[pb-j]:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif x > y and pa >= 0:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif pb >= 0:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        else:
            break
    
print(ans)

Submission status: Wrong Answer

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

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()
p = p[:x]
q = q[:y]

p.append(10**4)
q.append(10**4)
r.append(10**4)
result = sum(p+q)-2*(10**4)
ii, jj = x+y, c
for i in range(c):
    if p[x-1]<r[c-1]:
        result += r[c-1]-p[x-1]
        c -= 1
        x -= 1
    elif q[y-1]<r[c-1]:
        result += r[c-1]-q[y-1]
        c -= 1
        y -= 1
    else:
        break
    if c<0:
        break
print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque
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()))
lis = p[len(p)-x:] + q[len(q)-y:] + r
lis = sorted(lis)
print(sum(lis[len(r):]))

Submission status: Wrong Answer

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

reds=sorted(p[:min(x,len(p))])
grns=sorted(q[:min(y,len(q))])
rc=0
gc=0

if len(reds)<x and len(grns)<y:
    ans=sum(reds)+sum(grns)+sum(r[:((x+y)-(len(reds)+len(grns)))])
    exit()

if len(reds)<x:
    reds+=r[:(x-len(reds))]
    reds=sorted(reds)

if len(grns)<y:
    grns+=r[:(y-len(grns))]
    grns=sorted(grns)

from collections import deque

reds=deque(reds)
grns=deque(grns)

for i in range(len(r)):
    #print(reds,grns,r)
    if r[i]>min(reds[0],grns[0]):
        if reds[0]>=grns[0]:
            grns.popleft()
            grns.appendleft(r[i])
        else:
            reds.popleft()
            reds.appendleft(r[i])
    else:
        break
print(sum(reds)+sum(grns))

Submission status: Wrong Answer

Solution code:
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

if __name__ == "__main__":
    X, Y, A, B, C = MI()
    p = LI()
    p.reverse()
    q = LI()
    q.reverse()
    pq = p[:X] + q[:Y]
    r = LI()
    r.sort()
    for num in r:
        tmp = min(pq)
        if tmp < num:
            pq.remove(tmp)
            pq.append(num)
    print(sum(pq))

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 (x-1-cnt_a) < 0 and  y-1-cnt_b < 0:
        break
    pa = max(0, x-1-cnt_a)
    pb = max(0, y-1-cnt_b)
    if r[cnt] <= p[pa] and r[cnt] <= q[pb]:
        break

    if p[pa] > q[pb]:
        ans  = ans - q[pb] + r[cnt]
        cnt_b += 1
        q[pb] = r[cnt]
    elif p[pa] < q[pb]:
        ans = ans - p[pa] + r[cnt]
        cnt_a += 1
        q[pa] = r[cnt]
    else:
        j = 0
        while p[pa] == q[pb] and pa - j > -1 and pb - j > -1:
            j += 1
        if p[pa-j] > q[pb-j]:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        elif p[pa-j] < q[pb-j]:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif x > y and pa >= 0:
            ans = ans - p[pa] + r[cnt]
            cnt_a += 1
            q[pa] = r[cnt]
        elif pb >= 0:
            ans  = ans - q[pb] + r[cnt]
            cnt_b += 1
            q[pb] = r[cnt]
        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()
q.sort()
r.sort()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y]
px = 0
qx = 0
for i in range(C):
    if px == len(p) or qx ==len(q):
        break
    if min(p[px],q[qx],r[i]) ==p[px]:
        p[px] = r[i]
        px +=1
    elif min(p[px],q[qx],r[i]) ==q[qx]:
        q[qx] = r[i]
        qx += 1
    else:
        px += 1
        qx += 1
print(sum(p)+sum(q))

Submission status: Wrong Answer

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

p.insert(0, 0)
p.append(0)
q.insert(0, 0)
q.append(0)
r.append(0)

result = sum(p[:x+1]) + sum(q[:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if 0 < p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

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:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        if p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        if q[j] == v:
            ans += q[j]
            countB += 1
            j += 1

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    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 ans



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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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()))

def sort(L):
  if len(L)==1:
    return L
  left = sort(L[:len(L)//2])
  right = sort(L[len(L)//2:])
  result = []
  left.append(-1)
  right.append(-1)
  left_index = 0
  right_index = 0
  while len(result)<len(L):
    if left[left_index]>=right[right_index]:
      result.append(left[left_index])
      left_index += 1
    else:
      result.append(right[right_index])
      right_index += 1
  return result

P = sort(P)[:X]
Q = sort(Q)[:Y]
R = sort(R)

P_index = X-1
Q_index = Y-1
R_index = 0

Submission status: Wrong Answer

Solution code:
import collections

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)
r = collections.deque(r)
ans = 0
num = 0
for i in range(x):
    if r:
        if r[0] > p[num]:
            ans += r.popleft()
        else:
            ans += p[num]
            num += 1
    else:
        ans += p[num]
        num += 1

num = 0

for j in range(y):
    if r:
        if r[0] > q[num]:
            ans += r.popleft()
        else:
            ans += q[num]
            num += 1
    else:
        ans += q[num]
        num += 1

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,red,green,cl = map(int,input().split())
r = sorted(list(map(int,input().split())))[::-1]
g = sorted(list(map(int,input().split())))[::-1]
c = sorted(list(map(int,input().split())))[::-1]
s = r+g+c
print(sum(sorted(s)[::-1][:a+b]))

Submission status: Wrong Answer

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]

x_a.reverse()
x_b.reverse()

s = 0
v = 0
t = 0
while s < x and v < y and t < c:
    if x_a[s] <= x_b[v]:
        #print('B')
        if x_a[s] < s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        elif x_a[s] == s_c[t]:
            s += 1
        else:
            break
    else:
        #print('A')
        if x_b[v] < s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        elif x_b[v] == s_c[t]:
            v += 1
        else:
            break

ans = sum(x_a) + sum(x_b)
print(ans)

Submission status: Wrong Answer

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif Q[j-1] < P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

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()
p = p[:x]
q = q[:y]

p.append(10**4)
q.append(10**4)
r.append(10**4)
result = sum(p+q)-2*(10**4)
ii, jj = x+y, c
for i in range(c):
    if p[x-1]<r[c-1]:
        result += r[c-1]-p[x-1]
        c -= 1
        x -= 1
    elif q[y-1]<r[c-1]:
        result += r[c-1]-q[y-1]
        c -= 1
        y -= 1
    else:
        break
print(result)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    X, Y, A, B, C = map(int, input().split())
    pA = sorted(map(int, input().split()), reverse=True)
    pB = sorted(map(int, input().split()), reverse=True)
    pC = sorted(map(int, input().split()), reverse=True)

    # dp[red_count][green_count] = (value, red-index, green-index, non-index)
    dp = defaultdict(lambda: defaultdict(lambda: (0, 0, 0, 0)))

    for i in range(1, max(X, Y) + 1):
        ri = i if i <= X else X
        gi = i - 1 if i <= Y else Y - 1
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        ri = i - 1 if i <= X else X - 1
        gi = i if i <= Y else Y
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        ri = i if i <= X else X
        gi = i if i <= Y else Y
        if 0 < ri:
            v, r, g, n = dp[ri - 1][gi]
            dp[ri][gi] = max(dp[ri][gi], (v + pA[r], r + 1, g, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))
        if 0 < gi:
            v, r, g, n = dp[ri][gi - 1]
            dp[ri][gi] = max(dp[ri][gi], (v + pB[g], r, g + 1, n),
                             (v + pC[n] if n < C else v, r, g, n + 1))

    print(dp[X][Y][0])


main()

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = [int(i) for i in input().split()]
p = sorted([int(i) for i in input().split()])[::-1]
q = sorted([int(i) for i in input().split()])[::-1]
r = sorted([int(i) for i in input().split()])[::-1]
 
# print(p, q, r)
pp = x - 1
qp = y - 1
rp = 0
while rp < c:
    if r[rp] > p[pp] or r[rp] > q[qp]:
        if p[pp] > q[qp]:
            q[qp] = r[rp]
            qp -= 1
        else:
            p[pp] = r[rp]
            pp -= 1
    rp += 1
 
# print(p,q)
print(sum(p[:x]) + sum(q[:y]))

Submission status: Wrong Answer

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]

x_a.reverse()
x_b.reverse()

s = 0
v = 0
t = 0
while s < x and v < y and t < c:
    if x_a[s] <= x_b[v]:
        #print('B')
        if x_a[s] < s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        elif x_a[s] == s_c[t]:
            s += 1
        else:
            break
    else:
        #print('A')
        if x_b[v] < s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        elif x_b[v] == s_c[t]:
            s += 1
        else:
            break

ans = sum(x_a) + sum(x_b)
print(ans)

Submission status: Wrong Answer

Solution code:
#abc.py
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()))
ans = 0
while X>0 or Y>0:
#    print(P,Q,R)
#    print(X,Y)
    P_max=0
    Q_max=0
    R_max=0
    if len(P)>0:
        P_max = max(P)
    if len(Q)>0:
        Q_max = max(Q)
    if len(R)>0:
        R_max = max(R)
    if P_max<R_max and Q_max<R_max:
        #小さいほうに突っ込む
        if P_max< Q_max and X>0:
            P.append(R_max)
            R.remove(R_max)
        else:
            Q.append(R_max)
            R.remove(R_max)
    else:
        if P_max< Q_max and Y>0:
            ans += Q_max
            Q.remove(Q_max)
            Y-=1
        else:
            ans += P_max
            P.remove(P_max)
            X-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif P[i-1] <= Q[j-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))