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
import sys
import heapq


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p)
    q = sorted(q)
    r = sorted(r)

    result = 0

    X_count = 0
    Y_count = 0

    while True:
        if len(p) > 0 and p[-1] > r[-1] and p[-1] > q[-1] and X_count < X:
            result += p.pop()
            X_count += 1
        elif len(q) > 0 and q[-1] > r[-1] and q[-1] > p[-1] and Y_count < Y:
            result += q.pop()
            Y_count += 1
        elif len(r) > 0 and X_count < X:
            result += r.pop()
            X_count += 1
        elif len(r) > 0 and Y_count < Y:
            result += r.pop()
            Y_count += 1
        if X_count == X:
            p = [-100]
        if Y_count == Y:
            q = [-100]
        if len(r) == 0:
            r = [-100]
        if X_count == X and Y_count == Y:
            break
    print(result)
    return


def solveold(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p)
    q = sorted(q)
    r = sorted(r)

    result = 0


    for i in range(X):
        if p[-1] < r[-1]:
            result += r.pop()
        else:
            result += p.pop()

    for i in range(Y):
        if q[-1] < r[-1]:
            result += r.pop()
        else:
            result += q.pop()
    print(result)
    return

def solve_slow(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = [-1 * i for i in p]
    q = [-1 * i for i in q]
    r = [-1 * i for i in r]
    heapq.heapify(p)
    heapq.heapify(q)
    heapq.heapify(r)

    result = 0
    for i in range(X):
        smallest_p = heapq.nsmallest(1, p)
        smallest_r = heapq.nsmallest(1, r)
        if smallest_p < smallest_r:
            temp = heapq.heappop(p) * -1
            result += temp
        else:
            temp = heapq.heappop(r) * -1
            result += temp

    for i in range(Y):
        smallest_q = heapq.nsmallest(1, q)
        smallest_r = heapq.nsmallest(1, r)
        if smallest_q < smallest_r:
            temp = heapq.heappop(q) * -1
            result += temp
        else:
            temp = heapq.heappop(r) * -1
            result += temp
    #    print(temp)
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(lambda x:int(x)*(-1),input().split()))
from heapq import *

heapify(lst_r)
for i in range(a-x):
    _ = heappop(lst_r)

heapify(lst_g)
for i in range(b-y):
    _ = heappop(lst_g)
    
heapify(lst_n)

flg = lst_r > lst_g

cur = -1 * heappop(lst_n)
while len(lst_n)>=0:
    if flg and cur > lst_g[0]:
        _ = heappushpop(lst_g,cur)
    elif (not flg) and cur > lst_r[0]:
        _ = heappushpop(lst_r,cur)
    else:
        break
print(sum(lst_g)+sum(lst_r))

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
P = sorted(P[:X])
Q = sorted(Q[:Y])
R.sort()
while R and (P[0] < R[-1] or Q[0] < R[-1]):
    if P[0] < Q[-1]:
        heapq.heappush(P, R.pop())
        heapq.heappop(P)
    else:
        heapq.heappush(Q, R.pop())
        heapq.heappop(Q)
print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline

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)
cumsum_p = list(itertools.accumulate(p))
cumsum_q = list(itertools.accumulate(q))
cnt_p = 0
cnt_q = 0
for i in range(c):
    # print(p[x - 1 - cnt_p], q[y - 1 - cnt_q], cnt_q, cnt_p, cumsum_q, cumsum_p)
    if x - 1 - cnt_p < 0 and y - 1 - cnt_q < 0:
        break
    if x - 1 - cnt_p < 0:
        if r[i] > q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    if y - 1 - cnt_q < 0:
        if r[i] > p[x - 1 - cnt_p]:
            cumsum_p[x - 1] += r[i] - p[x - 1 - cnt_p]
            cnt_p += 1
        else:
            break
    if p[x - 1 - cnt_p] > q[y - 1 - cnt_q]:
        if r[i] > q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    else:
        if r[i] > p[x - 1 - cnt_p]:
            cumsum_p[x - 1] += r[i] - p[x - 1 - cnt_p]
            cnt_p += 1
        else:
            break
print(cumsum_p[x - 1] + cumsum_q[y - 1])

Submission status: Wrong Answer

Solution code:
#200329E
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)
R = sorted(r)
Red = p + r
Red = sorted(Red)
Deli =[]

for i in range(X):
    Deli.append(Red[len(Red)-1-i])
    if Red[len(Red)-1-i] == P[len(P)-1-i]:
        Red[len(Red)-1-i] = 0
        #print(Red)
        Red = sorted(Red)
        P[len(P)-1-i]= 0
    else:
        Red[len(Red)-1-i] = 0
        Red = sorted(Red)
        R[len(R)-1-i]= 0

Green = q + R
Green = sorted(Green)
for i in range(Y):
    Deli.append(Green[len(Green)-1-i])
    Green[len(Green)-1-i] = 0
    
#print(Deli)
print(int(sum(Deli)))

Submission status: Wrong Answer

Solution code:
inputline=input().split()
x=int(inputline[0])
y=int(inputline[1])
a=int(inputline[2])
b=int(inputline[3])
c=int(inputline[4])

reds=sorted((int(i) for i in input().split()),reverse=True)
greens=sorted((int(i) for i in input().split()),reverse=True)
colorless=sorted((int(i) for i in input().split()),reverse=True)

eats=[reds[i] for i in range(x)]
eats.extend([greens[i] for i in range(y)])

print(min(eats))

while min(eats)<max(colorless):

    if max(colorless) > min(eats):

        eats.remove(min(eats))
        eats.append(max(colorless))

print(sum(eats))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline

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)
cumsum_p = list(itertools.accumulate(p))
cumsum_q = list(itertools.accumulate(q))
cnt_p = 0
cnt_q = 0
for i in range(c):
    # print(p[x - 1 - cnt_p], q[y - 1 - cnt_q], cnt_q, cnt_p, cumsum_q, cumsum_p)
    if x - 1 - cnt_p < 0 and y - 1 - cnt_q < 0:
        break
    if x - 1 - cnt_p < 0:
        if r[i] > q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    if y - 1 - cnt_q < 0:
        if r[i] > p[x - 1 - cnt_p]:
            cumsum_p[x - 1] += r[i] - p[x - 1 - cnt_p]
            cnt_p += 1
        else:
            break
    if p[x - 1 - cnt_p] > q[y - 1 - cnt_q]:
        if r[i] > q[y - 1 - cnt_q]:
            cumsum_q[y - 1] += r[i] - q[y - 1 - cnt_q]
            cnt_q += 1
        else:
            break
    else:
        if r[i] > p[x - 1 - cnt_p]:
            cumsum_p[x - 1] += r[i] - p[x - 1 - cnt_p]
            cnt_p += 1
        else:
            break
print(cumsum_p[x - 1], cumsum_q[y - 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()))

goukei = X + Y
delicious = 0
red = 0
green = 0


def max_pop(p):
    pidx = p.index(max(p))
    maxp = p.pop(pidx)
    return maxp


maxp = max_pop(p)
maxq = max_pop(q)
maxr = max_pop(r)
maxdelis = [maxp, maxq, maxr]
for i in range(goukei):
    maxdeli = max(maxdelis)
    idx = maxdelis.index(max(maxdelis))
    delicious += maxdeli
    if idx == 0:
        red += 1
        if red == X:
            maxdelis[0] = 0
        else:
            maxdelis[0] = max_pop(p)
    elif idx == 1:
        green += 1
        if green == X:
            maxdelis[1] = 0
        else:
            maxdelis[1] = max_pop(q)

print(delicious)

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()))
tmp = 0
p.sort(reverse=True)
p.append(0)
q.sort(reverse=True)
q.append(0)
r.sort(reverse=True)
r.append(0)
z = X+Y
for i in range(z):
    if X>0 and ((p[0]>=q[0] and p[0]>=r[0]) or (Y==0 and p[0]>=r[0])):
        tmp = tmp+p[0]
        p.pop(0)
        X -= 1
    elif Y>0 and ((q[0]>=p[0] and q[0]>=r[0]) or (X==0 and q[0]>=r[0])):
        tmp = tmp+q[0]
        q.pop(0)
        Y -= 1
    elif r[0]>=p[0] and r[0]>=q[0]:
        tmp = tmp+r[0]
        r.pop(0)
        
print(tmp)

Submission status: Wrong Answer

Solution code:
(x,y,a,b,c),*t=[map(int,t.split())for t in open(0)]
p,q,r=[[0]+sorted(t)[::-1]for t in t]
pi=p[:]
qi=q[:]
ri=r[:]
for i in range(a):p[i+1]+=p[i]
for i in range(b):q[i+1]+=q[i]
for i in range(c):r[i+1]+=r[i]
m=0
for i in range(x+1):
    # i:赤の個数
    # j:赤に変える無の個数
    # k:無の残り
    j=x-i
    k=c-j
    if j>c:continue
    # 赤の美味しさ総和
    t=p[i]+r[j]
    # 上手いこと緑の美味しさ総和を求める
    # 三分探索？
    # 違うっぽい、もうだめだ
    # 整数の三分探索はにぶたんに帰着
    # 緑をy-t個、無をt個
    solve=lambda t:q[y-t]+r[j+t]-r[j]
    ok=0
    ng=k+1
    while ng-ok>1:
        # 無のうちmid個を緑に変換
        mid=(ok+ng)//2
        if solve(mid)-solve(mid-1)>0:ok=mid
        else:ng=mid
    t+=solve(ok)
    if t>m:m=t
for i in range(y+1):
    j=y-i
    k=c-j
    if j>c:continue
    t=q[i]+r[j]
    solve=lambda t:p[x-t]+r[j+t]-r[j]
    ok=0
    ng=k+1
    while ng-ok>1:
        # 無のうちmid個を緑に変換
        mid=(ok+ng)//2
        if solve(mid)-solve(mid-1)>0:ok=mid
        else:ng=mid
    t+=solve(ok)
    if t>m:m=t
print(m)

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] >= q[j]:
                countA += 1
                ans += p[i]
                i += 1
            elif q[j] > p[i]:
                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:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    x,y,a,b,c = map(int,input().split())
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))
    r = list(map(int,input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    p = p[:x]
    q = q[:y]
    for i in range(x):
        p[i] *= -1
    for i in range(y):
        q[i] *= -1
    biglist = p+q
    heapify(p+q)
    for i in range(c):
        heappush(biglist,-r[i])
    ans = 0
    for i in range(x+y):
        ans += -heappop(biglist)
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================

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

apple_point = 0
orange_point = 0

apple_taste = p + r
apple_taste.sort(reverse=True)

orange_taste = q + r
orange_taste.sort(reverse=True)

for i in range(0, X):
    apple_point += apple_taste[i]

for j in range(0, Y):
    orange_point += orange_taste[j]

print(apple_point + orange_point)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = list(map(int,input().split()))
p = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
q = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
r = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]

pi = 0
qi = 0
ri = 0
res = 0
while pi + qi + ri != X + Y:
  if ( qi == Y or p[pi] >= q[qi] ) and p[pi] >= r[ri]:
    # print("p")
    res += p[pi]
    pi += 1
  elif ( pi == X or q[qi] >= p[pi] ) and q[qi] >= r[ri]:
    # print("q")
    res += q[qi]
    qi += 1
  elif pi == X and qi == Y or r[ri] >= q[qi] and r[ri] >= p[pi]:
    #print("r")
    res += r[ri]
    ri += 1
  # print(pi + qi + ri != X + Y)
print(res)

Submission status: Wrong Answer

Solution code:
aaa=list(map(int,input().split()))
x=aaa[0]
y=aaa[1]
a=aaa[2]
b=aaa[3]
c=aaa[4]

p=[]
q=[]
r=[]

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
for i in range(x):
    if(len(p)!=0 and len(r)!=0):
        t=max(p[0],r[0])
        ans+=t
        if t==p[0]:
            del p[0]
        elif t==r[0]:
            del r[0]
    elif len(p)!=0 and len(r)==0:
        ans+=p[0]
    
for i in range(y):
    if(len(q)!=0 and len(r)!=0):
        u=max(q[0],r[0])
        ans+=u
        if u==q[0]:
            del q[0]
        elif t==r[0]:
            del r[0]
    elif len(q)!=0 and len(r)==0:
        ans+=q[0]
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
Pa = list(map(int, input().strip().split()))
Qb = list(map(int, input().strip().split()))
Rc = list(map(int, input().strip().split()))

Pa.extend(Qb)
Pa.extend(Rc)
Pa.sort(reverse=True)

Z = X + Y
print(sum(Pa[0:Z]))

Submission status: Wrong Answer

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

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, y, a, b, c = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	q = list(map(int, sys.stdin.readline().split()))
	r = list(map(int, sys.stdin.readline().split()))
	allap = []
	for i in range(a):
		allap.append(("r", p[i]))
	for i in range(b):
		allap.append(("g", q[i]))
	for i in range(c):
		allap.append(("n", r[i]))
	allap.sort(key=lambda x:x[1], reverse=True)
	log.print(allap)
	deli = 0
	ap = []
	aq = []
	xcnt = x
	ycnt = y
	for i in range(len(allap)):
		if allap[i][0] == "r" and xcnt > 0:
			ap.append(allap[i])
			xcnt -= 1
		if allap[i][0] == "g" and ycnt > 0:
			aq.append(allap[i])
			ycnt -= 1
	xcnt = x
	ycnt = y
	for i in range(len(allap)):
		log.print(allap[i], xcnt, ycnt, deli)
		if allap[i][0] == "r" and xcnt > 0:
			deli += allap[i][1]
			xcnt -= 1
		if allap[i][0] == "g" and ycnt > 0:
			deli += allap[i][1]
			ycnt -= 1
		if allap[i][0] == "n":
			if len(ap) > 0 and len(aq) > 0 and ap[-1][1] < aq[-1][1] and xcnt > 0:
				deli += allap[i][1]
				ap.pop()
				xcnt -= 1
			if len(ap) > 0 and len(aq) > 0 and ap[-1][1] >= aq[-1][1] and ycnt > 0:
				deli += allap[i][1]
				aq.pop()
				ycnt -= 1
	print(deli)
	


main()

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = list(map(int,input().split()))
p = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = list(map(int,input().split()))
q = sorted(q,reverse=True)
r = list(map(int,input().split()))
r = sorted(r)
c_ori = c
while c >= 1 and (x >= 1 and p[x-1] < r[c-1]) or (y >= 1 and q[y-1] < r[c-1]):
    if x >= 1 and y >= 1 and p[x-1] < q[y-1]:
        x = x-1
        c = c-1
    elif x >= 1 and y >= 1 and p[x-1] >= q[y-1]:
        y = y-1
        c = c-1
    elif y == 0:
        x = x-1
        c = c-1
    else:
        y = y-1
        c = c-1
               
sum = 0
if x >= 1:
    for i in range(x):
        sum += p[i]
#print(sum)
if y >= 1:
    for i in range(y):
        sum += q[i]
#print(sum)
if c_ori > c:
    for i in range(c,c_ori):
        sum += r[i]
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()
q.sort()
r.sort(reverse=True)
x=p[(A-X):]
y=q[(B-Y):]
s=sum(x)+sum(y)
sub=0

for i in range(len(r)):
    if x[0]>y[0]:
        t=y.pop(0)
        if t<r[0]:
            sub=sub+r.pop(0)-t
            if y==[]:
                break
        else:
            break
    else:
        t=x.pop(0)
        if t<r[0]:
            sub=sub+r.pop(0)-t
            if x==[]:
                break
        else:
            break

print(s+sub)

Submission status: Wrong Answer

Solution code:
def LI():
	return [ int(s) for s in input().split() ]
  
X,Y,A,B,C = LI()
if X > Y:
    X,Y = Y,X
    A,B = B,A
    y = LI()
    x = LI()
    c = LI()
else:
    x = LI()
    y = LI()
    c = LI()
    
x = sorted(x,reverse = True)
y = sorted(y,reverse = True)
c = sorted(c,reverse = True)

x_count = 0
y_count = 0
c_count = 0

sweet = 0

for i in range(1, Y+1):
    if i <= X:
        if c_count < C:
            if x[x_count] > y[y_count] and y[y_count] < c[c_count]:
                sweet += (x[x_count] + c[c_count])
                x_count += 1
                c_count += 1
            elif x[x_count] <= y[y_count] and x[x_count] < c[c_count]:
                sweet += (y[y_count] + c[c_count])
                y_count += 1
                c_count+=1
            else:
                sweet+=(x[x_count] + y[y_count])
                x_count+=1
                y_count+=1
        else:
                sweet+=(x[x_count] + y[y_count])
                x_count+=1
                y_count+=1
    else:
        if c_count < C:
            if y[y_count] < c[c_count]:
                sweet+=c[c_count]
                c_count+=1
            else:
                sweet+=y[y_count]
                y_count+=1
        else:
            sweet+=y[y_count]
            y_count+=1
print(sweet)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int,input().split())
listp = list(map(int, input().split()))
listq = list(map(int, input().split()))
listr = list(map(int, input().split()))

listp = sorted(listp, reverse=True)
listq = sorted(listq, reverse=True)
listr = sorted(listr, reverse=True)
listp = listp[:X]
listq = listq[:Y]
listr = listr[:X+Y]
print(listr)

eat_noapple = []
oisisa = 0

for noapple in listr:
    try:
        if listp[-1] >= listq[-1] and listq[-1] < noapple:
            listq.pop(-1)
            eat_noapple.append(noapple)
        elif listp[-1] < listq[-1] and listp[-1] < noapple:
            listp.pop(-1)
            eat_noapple.append(noapple)
    except:
        a = 0
    else:
        break
try:
    for papple in listq:
        oisisa += papple
except:
    a = 0
try:
    for qapple in listp:
        oisisa += qapple
except:
    a = 0
try:
    for rapple in eat_noapple:
        oisisa += rapple
except:
    a = 0
print(oisisa)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p += [0]
q = list(map(int, input().split()))
q += [0]
r = list(map(int, input().split()))
r += [0]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
n, m, l = 0, 0, 0
ans = 0
for i in range(x+y):
    if (p[n] >= r[l] or q[n] >= r[l]) and n < x and m < y:
        if p[n] >= q[m]:
            ans += p[n]
            n += 1
        else:
            ans += q[m]
            m += 1
    elif n == x:
        if q[m] >= r[l]:
            ans += q[m]
            m += 1
        else:
            ans += r[l]
            l += 1
    elif m == y:
        if p[n] >= r[l]:
            ans += p[n]
            n += 1
        else:
            ans += r[l]
            l += 1    
    else:
        if p[n] >= q[m]:
            ans += r[l]
            m += 1
            l += 1
        else:
            ans += r[l]
            n += 1
            l += 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())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
S=sorted(P[A-X:]+Q[B-Y:])
i=0
while S[i]<R[-1-i]:
    i+=1
    if len(R)>i or len(S)>i:
        break
if i==0:
    R=[]
print(sum(S[i:])+sum(R[-i:]))

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

P = sorted(P, reverse=True)
Q = sorted(Q, reverse=True)
R = sorted(R, reverse=True)

X_ind = X - 1
Y_ind = Y - 1
P_score = sum(P[:X])
Q_score = sum(Q[:Y])
for r in R:
    p_flag = r > P[X_ind]
    q_flag = r > Q[Y_ind]
    if p_flag and q_flag:
        if P[X_ind] < Q[Y_ind]: # paint the apple of r to be Red
            P_score = P_score + r - P[X_ind]
            X_ind -= 1
        elif P[X_ind] == Q[Y_ind]:
            if P_score < Q_score: # paint the apple of r to be Red
                P_score = P_score + r - P[X_ind]
                X_ind -= 1
            else: # paint the apple of r to be blue
                Q_score = Q_score + r - Q[Y_ind]
                Y_ind -= 1
        else:
            Q_score = Q_score + r - Q[Y_ind]
            Y_ind -= 1
    elif p_flag and not(q_flag):
        P_score = P_score + r - P[X_ind]
        X_ind -= 1
    elif not(p_flag) and q_flag:
        Q_score = Q_score + r - Q[Y_ind]
        Y_ind -= 1
    else:
        break
print(P_score + Q_score)

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()))
tmp=sorted(p)
P=tmp[::-1]
tmp=sorted(q)
Q=tmp[::-1]
tmp=sorted(r)
R=tmp[::-1]
R=R+([0]*(10**5))
ans=0
i=X-1
j=Y-1
k=0
while(1):
	if R[k]==0:
		break
	elif min(P[i],Q[j])==P[i]:
		if P[i]>R[k]:
			break
		else:
			P[i]=R[k]
			k+=1
			i-=1
	elif min(P[i],Q[j])==Q[j]:
		if Q[j]>R[k]:
			break
		else:
			Q[j]=R[k]
			k+=1
			j-=1
ans=sum(P[:X])+sum(Q[:Y])
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)[a-x:]
q=sorted(q)[b-y:]
r=sorted(r,reverse=True)
minp_idx=0
minq_idx=0
for i in range(c):
  if minp_idx>=x and minq_idx>=y:
    break
  elif minp_idx>=x:
    if q[minq_idx]<r[i]:
      q[minq_idx]=r[i]
      minq_idx+=1
    else:
      break
  elif minq_idx>=y:
    if p[minp_idx]<r[i]:
      p[minp_idx]=r[i]
      minp_idx+=1
    else:
      break
  elif p[minp_idx]==q[minq_idx]:
    tmp=minp_idx
    tmp2=minq_idx
    smaller=False
    while tmp<x and tmp2<y:
      if p[tmp]<q[tmp2]:
        smaller=minp_idx
        minp_idx+=1
        break
      elif p[tmp]>q[tmp2]:
        smaller=minq_idx
        minq_idx+=1
        break
      else:
        tmp+=1
        tmp2+=1
    if smaller:
      if p[smaller]<r[i]:
        p[smaller]=r[i]
      else:
        break
    else:
      if x-minp_idx>y-minq_idx:
        if p[minp_idx]<r[i]:
          p[minp_idx]=r[i]
          minp_idx+=1
        else:
          break
      else:
        if q[minq_idx]<r[i]:
          q[minq_idx]=r[i]
          minq_idx+=1
        else:
          break
  elif p[minp_idx]<q[minq_idx]:
    if p[minp_idx]<r[i]:
      p[minp_idx]=r[i]
      minp_idx+=1
    else:
      break
  elif p[minp_idx]>q[minq_idx]:
    if q[minq_idx]<r[i]:
      q[minq_idx]=r[i]
      minq_idx+=1
    else:
      break
#print(p)
#print(q)
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)
a = P[:X]
b = Q[:Y]
c = a[:]
a.extend(b)
a.sort(reverse=True)
# print(a,b,c)
if max(R) > min(a):
    a.remove(min(a))
    a.append(max(R))
    R.remove(max(R))
print(sum(a))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=[int(x) for x in input().split()]
saare=[]
for item in P:
	saare.append([item,'R'])
for item in Q:
	saare.append([item,'G'])
for item in R:
	saare.append([item,'C'])

saare.sort(reverse=True)
# print(saare)

p=A-X
q=B-Y

i=0

ans=0

while X or Y:

	if saare[i][1]=='R' and X:
		X-=1
		p+=1
		ans+=saare[i][0]
		# print("EAT RED",saare[i][0])
	elif saare[i][1]=='G' and Y:
		Y-=1
		q+=1
		ans+=saare[i][0]
		# print("EAT GREEN",saare[i][0])
	elif saare[i][1]=='C':
		if not Y:
			X-=1
			p+=1
			ans+=saare[i][0]
			# print("EAT RED",saare[i][0])
		elif not X:
			Y-=1
			q+=1
			ans+=saare[i][0]
			# print("EAT GREEN",saare[i][0])
		else:
			if P[p] >= Q[q]:
				q+=1
				Y-=1
				ans+=saare[i][0]
				# print("EAT GREEN",saare[i][0])
			else:
				p+=1
				X-=1
				ans+=saare[i][0]
				# print("EAT RED",saare[i][0])
	i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
X, Y, A, B, C = map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1]
q = sorted(list(map(int,input().split())))[::-1]
r = sorted(list(map(int,input().split())))[::-1]
p = deque(p)
q = deque(q)
r = deque(r)
ans = 0

while len(p) > 0 and X > 0 and p[0] > r[0]:
    ans += p.popleft()
    X -= 1
while len(q) > 0 and Y > 0 and q[0] > r[0]:
    ans += q.popleft()
    Y -= 1

while X > 0 or Y > 0:
    if X > 0 and Y > 0 and len(r) > 0 and p[0] < q[0] and p[0] < r[0]:
        ans += r.popleft()
        X -= 1
    elif X > 0 and Y > 0 and len(r) > 0 and p[0] > q[0] and q[0] < r[0]:
        ans += r.popleft()
        Y -= 1
    elif X == 0 and Y > 0:
        if len(r) == 0:
            ans += q.popleft()
            Y -= 1
        elif r[0] > q[0]:
            ans += r.popleft()
            Y -= 1
        else:
            ans += q.popleft()
            Y-= 1
    else:
        if len(r) == 0:
            ans += p.popleft()
            X -= 1
        elif r[0] > p[0]:
            ans += r.popleft()
            X -= 1
        else:
            ans += p.popleft()
            X -= 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)
q = sorted(q)
r = sorted(r)
P = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C):
    if P < A:
        if (r[R-i] >= p[P]):
            if (q[Q] >= p[P]):
                P += 1
                R -= 1
        elif Q < B:
            if (r[R-i] > q[Q]):
                Q += 1
                R -= 1
            else:
                break
    elif Q < B:
        if (r[R-i] > q[Q]):
                Q += 1
                R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))