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:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    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)

    now = sum(p[:X]) + sum(q[:Y])
    ans = now
    i = X-1
    j = Y-1

    for k in range(min(C,X+Y)):
        if p[i] < q[j] or j < 0:
            now += r[k]-p[i]
            i -= 1
        else:
            now += r[k]-q[j]
            j -= 1
        ans = max(ans,now)
    print(ans)
            
    
     

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    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)

    ans = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(X):
        if k < C and p[i] < r[k]:
            ans += r[k]
            k += 1
        else:
            ans += p[i]
            i += 1
            
    for l in range(Y):
        if k < C and q[j] < r[k]:
            ans += r[k]
            k += 1
        else:
            ans += q[j]
            j += 1
    # print(ans)
    ans2 = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(Y):
        if k < C and q[j] < r[k]:
            ans2 += r[k]
            k += 1
        else:
            ans2 += q[j]
            j += 1
    for l in range(X):
        if k < C and p[i] < r[k]:
            ans2 += r[k]
            k += 1
        else:
            ans2 += p[i]
            i += 1
    print(max(ans,ans2))
            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    X, Y, A, B, C = LI()
    p = LI()
    q = LI()
    r = LI()
    heapify(p), heapify(q)

    for ri in r:
        if len(p) < X:
            heappush(p, ri)
        elif len(q) < Y:
            heappush(q, ri)
        else:
            ptop = p[0]
            qtop = q[0]
            if ptop <= qtop:
                heappush(p, ri)
            else:
                heappush(q, ri)
    print(sum(sorted(p, reverse=True)[:X]) +
          sum(sorted(q, reverse=True)[:Y]))


main()

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C = map(int, input().split())
p = [-int(x) for x in input().split()]
q = [-int(x) for x in input().split()]
r = [-int(x) for x in input().split()]

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
yummy = 0
for _ in range(X):
    if p:
        red = heapq.heappop(p)
        if r:
            no_color = heapq.heappop(r)
        else:
            no_color = 0
        if red <= no_color:
            heapq.heappush(r, no_color)
            yummy += red
        else:
            heapq.heappush(p, red)
            yummy += no_color
    else:
        yummy += heapq.heappop(r)

for _ in range(Y):
    if q:
        green = heapq.heappop(q)
        if r:
            no_color = heapq.heappop(r)
        else:
            no_color = 0
        if green <= no_color:
            heapq.heappush(r, no_color)
            yummy += green
        else:
            heapq.heappush(q, green)
            yummy += no_color
    else:
        yummy += heapq.heappop(r)

print(str(-yummy))

Submission status: Wrong Answer

Solution code:
#

import sys
input=sys.stdin.readline

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()))
    lis=[]
    for i in range(A):
        lis.append((P[i],0))
    for i in range(B):
        lis.append((Q[i],1))
    for i in range(C):
        lis.append((R[i],2))
        
    lis.sort(reverse=True)
    white=[]
    sumc=0
    xy=[X,Y]
    for i in range(len(lis)):
        if lis[i][1]==2:
            white.append(lis[i])
        elif xy[lis[i][1]]:
            xy[lis[i][1]]-=1
            sumc+=lis[i][0]
        if (sum(xy)<=len(white)):
            break
    for i in range(len(white)):
        print(len(white))
        sumc+=white[i][0]
    print(sumc)
            
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int, input().split())
*p,=map(int, input().split())
*q,=map(int, input().split())
*r,=map(int, input().split())
from heapq import *
p=[-i for i in p]
q=[-i for i in q]
r=[-i for i in r]
heapify(p)
heapify(q)
heapify(r)
ans=0
cnt=0
pt=heappop(p)
qt=heappop(q)
rt=heappop(r)
n=x+y
while (x>=0 or y>=0) and cnt<n:
  if pt<=rt:
    ans-=pt
    x-=1
    cnt+=1
    if p and x>0: pt=heappop(p)
    else: pt=0
  elif qt<=rt:
    ans-=qt
    y-=1
    cnt+=1
    if q and y>0: qt=heappop(q)
    else: qt=0
  else:
    ans-=rt
    cnt+=1
    if r: rt=heappop(r)
    else: rt=0
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()))
D = P + R
E = Q + R
D.sort()
D = D[::-1]
E.sort()
E = E[::-1]
F = D[:X] + E[:Y]
ans = sum(F)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    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()))
    P = sorted(P, reverse = True)[:x]
    Q = sorted(Q, reverse = True)[:y]
    ans = P + Q + R
    print(sum(ans[:x + y]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
def main():
    x, y, a, b, c = list(map(int, input().split()))
    P = list(map(lambda x: -int(x), input().split()))
    Q = list(map(lambda x: -int(x), input().split()))
    R = list(map(lambda x: -int(x), input().split()))
    heapify(P)
    heapify(Q)
    heapify(R)
    ans = []
    for _ in range(x):
        p = heappop(P)
        heappush(ans, -p)
    for _ in range(y):
        q = heappop(Q)
        heappush(ans, -q)
    r = -heappop(R)
    for i in range(x + y):
        if r > ans[i]:
            ans[i] = r
            if len(R) == 0:
                break
            else:
                r = -heappop(R)
        else:
            break
    print(sum(ans))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
inp = input
#fin = open("case_21.txt")
#inp = fin.readline

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

#red = np.array(list(map(int, inp().split())), np.int32)
#green = np.array(list(map(int, inp().split())), np.int32)
#white = np.array(list(map(int, inp().split())), np.int32)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
#fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0

while X > countr and Y > countg:
    if red[idr] >= green[idg] and red[idr] >= white[idw]:
        #eat red
        total += red[idr]
        idr += 1
        countr += 1
    elif green[idg] > red[idr] and green[idg] >= white[idw]:
        # eat green
        total += green[idg]
        idg += 1
        countg += 1
    else:
        if red[idr] >= green[idg]:
            #compare green 1st
            if idw < C and green[idg] < white[idw]:
                #eat white
                total += white[idw]
                idw += 1
            else:
                #eat green
                total += green[idg]
                idg += 1
            countg += 1

        else:
            #compare red 1st
            if idw < C and red[idr] < white[idw]:
                #eat white
                total += white[idw]
                idw += 1
            else:
                #eat red
                total += red[idr]
                idr += 1

            countr += 1

#eat remain
while X > countr:
    # compare red 1st
    if idw < C and red[idr] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat red
        total += red[idr]
        idr += 1
    countr += 1

while Y > countg:
    # compare green 1st
    if idw < C and green[idg] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat green
        total += green[idg]
        idg += 1
    countg += 1

print(int(total))

Submission status: Wrong Answer

Solution code:
import numpy as np
inp = input
#fin = open("case_21.txt")
#inp = fin.readline

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

red = np.array(list(map(int, inp().split())), np.int32)
green = np.array(list(map(int, inp().split())), np.int32)
white = np.array(list(map(int, inp().split())), np.int32)
#fin.close()

red[::-1].sort()
green[::-1].sort()
white[::-1].sort()
idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0
while X > countr and Y > countg:
    if red[idr] > green[idg]:
        #compare green 1st
        if idw < C and green[idg] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat green
            total += green[idg]
            idg += 1
        countg += 1

    else:
        #compare red 1st
        if idw < C and red[idr] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat red
            total += red[idr]
            idr += 1

        countr += 1

#eat remain
while X > countr:
    # compare red 1st
    if idw < C and red[idr] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat red
        total += red[idr]
        idr += 1
    countr += 1

while Y > countg:
    # compare green 1st
    if idw < C and green[idg] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat green
        total += green[idg]
        idg += 1
    countg += 1

print(int(total))

Submission status: Wrong Answer

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

red = np.array(list(map(int, input().split())), np.int32)
green = np.array(list(map(int, input().split())), np.int32)
white = np.array(list(map(int, input().split())), np.int32)

red[::-1].sort()
green[::-1].sort()
white[::-1].sort()
idr = 0
idg = 0
idw = 0

total = 0
countr = 0
countg = 0
while X > countr and Y > countg:
    if red[idr] > green[idg]:
        #compare green 1st
        if idw < C and green[idg] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat green
            total += green[idg]
            idg += 1
        countg += 1

    else:
        #compare red 1st
        if idw < C and red[idr] < white[idw]:
            #eat white
            total += white[idw]
            idw += 1
        else:
            #eat red
            total += red[idr]
            idr += 1

        countr += 1

#eat remain
while X > countr:
    # compare red 1st
    if idw < C and red[idr] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat red
        total += red[idr]
        idr += 1
    countr += 1

while Y > countg:
    # compare green 1st
    if idw < C and green[idg] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat green
        total += green[idg]
        idg += 1
    countg += 1

print(total)

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()))
r = sorted(r,reverse=True)

s = []
for i in range(a):
    s.append([p[i],1])
for i in range(b):
    s.append([q[i],2])
s.sort(key= lambda val : val[0],reverse=True)
A = 0
B = 0
ans = 0
i = 0
j = 0
k = 0
while k < x+y+c:
    if A >= x and B >= y:
        break
    k += 1
    if s[i][1] == 1:
        if A < x:
            A += 1
            if j < c:
                if s[i][0] >= r[j]:
                    ans += s[i][0]
                    i += 1
                else:
                    ans += r[j]
                    j += 1
            else:
                ans += s[i][0]
                i += 1
        else:
            i += 1
            pass
    else:
        if B < y:
            B += 1
            if j < c:
                if s[i][0] >= r[j]:
                    ans += s[i][0]
                    i += 1
                else:
                    ans += r[j]
                    j += 1
            else:
                ans += s[i][0]
                i += 1
        else:
            i += 1
            pass
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

x, y, a, b, c = map(int, input().split(" "))
qL = [-1] + sorted(list(map(int, input().split(" "))))
pL = [-1] + sorted(list(map(int, input().split(" "))))
rL = [-1] + sorted(list(map(int, input().split(" "))))

ans = 0
while not (x == 0 and y == 0):
    b = [qL[-1], pL[-1], rL[-1]].index(max([qL[-1], pL[-1], rL[-1]]))
    if b == 0:
        ans += qL.pop()
        x -= 1
    elif b == 1:
        ans += pL.pop()
        y -= 1
    elif b == 2:
        ans += rL.pop()
        if x > y:
            x -= 1
        else:
            y -= 1
    if x == 0:
        qL = [-1]
    if y == 0:
        pL = [-1]

print(ans)

Submission status: Wrong Answer

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

red_apples = X
green_apples = Y

while red_apples > 0 and green_apples > 0 and X+Y-red_apples-green_apples < C:
    if rs[X+Y-red_apples-green_apples] > qs[green_apples-1]:
        if qs[green_apples-1] > ps[red_apples-1]:
            red_apples -= 1
        else:
            green_apples -= 1
    elif rs[X+Y-red_apples-green_apples] > ps[red_apples-1]:
        if ps[red_apples-1] > qs[green_apples-1]:
            red_apples -= 1
        else:
            green_apples -= 1
    else:
        break
print(sum(ps[:red_apples]) + sum(qs[:green_apples]) + sum(rs[:X+Y-red_apples-green_apples]))

Submission status: Wrong Answer

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

red_apples = X
green_apples = Y

while red_apples > 0 and X - red_apples < C and rs[X-red_apples] > ps[red_apples-1]:
    red_apples -= 1

while green_apples > 0 and X+Y-red_apples-green_apples < C and rs[X+Y-red_apples-green_apples] > qs[green_apples-1]:
    green_apples -= 1

print(sum(ps[:red_apples]) + sum(qs[:green_apples]) + sum(rs[:X+Y-red_apples-green_apples]))

Submission status: Wrong Answer

Solution code:
#heapq p,qの最小値側にrの最大値入れていく。
import heapq 

#初期入力
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()
q.sort()
r.sort(reverse=True)

ans_sum =sum(p[-X:]) + sum(q[-Y:])
p_hq = p[-X:]
q_hq = q[-Y:]
heapq.heapify(p_hq)
heapq.heapify(q_hq)
p_change =heapq.heappop(p_hq)
q_change =heapq.heappop(q_hq)
count_p =0
count_q =0
for i in r: #rは大きい順
    if p_change < q_change and p_change < i:
        if  count_p < X:
            heapq.heappush(p_hq,i)
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =heapq.heappop(p_hq)
    elif p_change > q_change and q_change < i:
        if  count_q < Y:
            heapq.heappush(q_hq,i)
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =heapq.heappop(q_hq)
print(ans_sum)

Submission status: Wrong Answer

Solution code:
#heapq p,qの最小値側にrの最大値入れていく。
import heapq 

#初期入力
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()
q.sort()
r.sort(reverse=True)

ans_sum =sum(p[A-X:]) + sum(q[B-Y:])
p_hq = p[A-X:]
q_hq = q[B-Y:]
heapq.heapify(p_hq)
heapq.heapify(q_hq)
p_change =heapq.heappop(p_hq)
q_change =heapq.heappop(q_hq)
count_p =0
count_q =0
for i in r: #rは大きい順
    if p_change < q_change and p_change < i:
        if  count_p < X:
            heapq.heappush(p_hq,i)
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =heapq.heappop(p_hq)
    elif p_change > q_change and q_change < i:
        if  count_q < Y:
            heapq.heappush(q_hq,i)
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =heapq.heappop(q_hq)
print(ans_sum)

Submission status: Wrong Answer

Solution code:
from collections import deque 
#from copy import copy
#初期入力
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()
q.sort()
r.sort()

p_dq =deque(p[A-X:])
q_dq =deque(q[B-Y:])
ans_sum =sum(p[A-X:]) + sum(q[B-Y:])
p_change =p_dq.popleft()
q_change =q_dq.popleft()
count_p =0
count_q =0
for i in r:
    if p_change < q_change:
        if i > p_change and count_p < X:
            count_p +=1
            ans_sum = ans_sum -p_change +i
            if len(p_dq) >0 :
                p_change =p_dq.popleft()

    elif p_change > q_change and count_q < Y:
        if i > q_change:
            count_q +=1
            ans_sum = ans_sum -q_change +i
            if len(q_dq) >0:
                q_change =q_dq.popleft()
print(ans_sum)

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

heapq.heapify(p)
heapq.heapify(q)
r_asc = sorted(r, reverse=True)

for r in r_asc:
    p_min = heapq.heappop(p)
    q_min = heapq.heappop(q)
    if p_min > q_min and r > q_min:
        heapq.heappush(q, r)
        heapq.heappush(p, p_min)
    elif q_min >= p_min and r > p_min:
        heapq.heappush(p, r)
        heapq.heappush(q, q_min)
    else:
        heapq.heappush(q, q_min)
        heapq.heappush(p, p_min)
        break
print(sum(p[-X:]) + sum(q[-Y:]))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()), reverse=True)
pi = len(p) - x
qi = len(q) - y
ri = 0
for _ in range(len(r)):
    if r[ri] <= min(p[pi], q[qi]):
        break
    else:
        if pi < len(p) - 1:
            if p[pi] < r[ri]:
                p[pi] = r[ri]
                pi += 1
                ri += 1
                continue
        if qi < len(q) - 1:
            if q[qi] < r[ri]:
                q[qi] = r[ri]
                qi += 1
                ri += 1
                continue
        else:
            break
print(sum(p[-x:]) + sum(q[-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)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)

red = sorted(P[:X])
gre = sorted(Q[:Y])
ans = sum(red) + sum(gre) 
j, k = 0, 0

for i in range(min(X+Y,C)):
    if(red[j] <= gre[k]):
        if j < X-1:
            if R[i] > red[j] :
                ans = ans - red[j] + R[i]
                j += 1
            else:
                break
        else:
            if R[i] > gre[k] :
                ans = ans - gre[k] + R[i]
                k += 1
            else:
                break
    else:
        if k < Y-1:
            if R[i] > gre[k] :
                ans = ans - gre[k] + R[i]
                k += 1
            else:
                break
        else:
            if R[i] > red[j]:
                ans = ans - red[j] + R[i]
                j = j+1
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:

x,y,red,green, rg= map(int,input().split())
R = sorted(list(map(int, input().split())), reverse=True)
G = sorted(list(map(int, input().split())), reverse=True)
RG = sorted(list(map(int, input().split())), reverse=True)

x_c = 0
y_c = 0
for i in range(x):
    if i >= red or RG[0] > R[i]: break
    x_c += 1
for j in range(y):
    if j >= green or RG[0] > G[j]: break
    y_c += 1

if x_c < x and y_c < y:
    if R[x_c]-RG[0] > G[y_c]-RG[0]:
        print(sum(R[:x_c]) + sum(RG[:x-x_c]) + sum(G[:y]))
    else:
        print(sum(G[:y_c]) + sum(RG[:y-y_c]) + sum(R[:x]))
else:
    if x_c == x:
        print(sum(R[:x]) + sum(G[:y_c]) + sum(RG[:y-y_c]))
    else:
        print(sum(G[:y]) + sum(R[:x_c]) + sum(RG[:x-x_c]))

Submission status: Wrong Answer

Solution code:
import bisect
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
A = p[:X]+q[:Y]
A.sort(reverse=True)
for n in r:
    if A[-1] < n:
        index = bisect.bisect_left(A,n)
        A[index-1] = n
print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')


#import numpy as np

def main():
	x,y,a,b,c=MI()
	p=LI()
	q=LI()
	r=LI()

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

	p=p[a-x:]+[10**10]
	q=q[b-y:]+[10**10]
	r=r[max(0,c-(x+y)):]


	i=0
	j=0

	for k in range(min(x+y,c)):
		if p[i]<=q[j]:
			if p[i]<r[k]:
				p[i]=r[k]
				i+=1
		else:
				if q[j]<r[k]:
					q[j]=r[k]
					j+=1

	print(sum(p)+sum(q)-2*10**10)








if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
x,y,A,B,C=map(int,input().split())
R=list(map(int,input().split()))
G=list(map(int,input().split()))
N=list(map(int,input().split()))
arr=[]
for i in range(A):
    arr.append([R[i],-1])
for i in range(B):
    arr.append([G[i],-2]) 
for i in range(C):
    arr.append([N[i],-3])    
arr.sort(reverse=True)
ans=0
for i in range(len(arr)):
    if x>0:
        if arr[i][1]==-1 or arr[i][1]==-3:
            ans+=arr[i][0]
            x-=1 
    if y>0:
        if arr[i][1]==-2 or arr[i][1]==-3:
            ans+=arr[i][0]
            y-=1
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
p, q, r = [list(map(int, input().split())) for _ in range(3)]

p = list(map(lambda x: [x, 'p'], p))[:X]
q = list(map(lambda x: [x, 'q'], q))[:Y]
r = list(map(lambda x: [x, 'r'], r))

l = p+q+r

l.sort(reverse=True)

x = 0
y = 0

sum = 0

while not (x == X and y == Y):
    apple = l.pop(0)
    if apple[1] == 'p' and x < X:
        x += 1
        sum += apple[0]
    if apple[1] == 'q' and y < Y:
        y += 1
        sum += apple[0]
    if apple[1] == 'r':
        if X-x < Y-y and y < Y:
            y += 1
            sum += apple[0]
        if Y-y <= X-x and x < X:
            x += 1
            sum += apple[0]

print(sum)

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

R = p[:X]
G = q[:Y]

con = True
while con and len(r) > 0:
    rr = r.pop()
    if R[-1] < G[-1]:
        if R[-1] < rr:
            R[0] += rr
            R.pop()
            continue
        else:
            con = False
    else:
        if G[-1] < rr:
            G[0] += rr
            G.pop()
            continue
        else:
            con = False

print(sum(R) + sum(G))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    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)


    mx = sum(P[:X])+sum(Q[:Y])
    p_i = X-1
    q_i = Y-1
    for i in range(C):
        p,q,r = P[p_i], Q[q_i], R[i]

        if p_i >= 0 and p<=q and not r<p:
            p_i -= 1
            mx = mx - p + r
        elif q_i >= 0 and q<=p and not r<q:
            q_i -= 1
            mx = mx - q + r

    print(mx)



if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    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)


    mx = sum(P[:X])+sum(Q[:Y])
    p_i = X-1
    q_i = Y-1
    for i in range(C):
        p,q,r = P[p_i], Q[q_i], R[i]

        if p_i > 0 and p<=q and not r<p:
            p_i -= 1
            mx = mx - p + r
        elif q_i > 0 and q<=p and not r<q:
            q_i -= 1
            mx = mx - q + r

    print(mx)



if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    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)


    mx = sum(P[:X])+sum(Q[:Y])
    p_i = X-1
    q_i = Y-1
    for i in range(C):
        p,q,r = P[p_i], Q[q_i], R[i]

        if p_i > 0 and p<q and not r<p:
            p_i -= 1
            mx = mx - p + r
        elif q_i > 0 and q<p and not r<q:
            q_i -= 1
            mx = mx - q + r


    print(mx)



if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def main():
    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)


    mx = sum(P[:X])+sum(Q[:Y])
    p_i = X-1
    q_i = Y-1
    for i in range(C):
        p,q,r = P[p_i], Q[q_i], R[i]

        if p<q and not r<p:
            p_i -= 1
            mx = mx - p + r
        elif q<p and not r<q:
            q_i -= 1
            mx = mx - q + r


    print(mx)



if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
def red_and_green_apples(X, Y, A, B, C, P, Q, R):
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    P = P[:X]
    Q = Q[:Y]
    q = P + Q + R
    q.sort(reverse=True)

    return sum(q[:X + Y])


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

red_and_green_apples(X, Y, A, B, C, P, Q, R)

# red_and_green_apples(
#     1, 2, 2, 2, 1,
#     [2, 4],
#     [5, 1],
#     [3],
# )
#
# red_and_green_apples(
#     2, 2, 2, 2, 2,
#     [8, 6],
#     [9, 1],
#     [2, 1],
# )