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 =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n]:
    n -= 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C:
    break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
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)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = [(-int(i),1) for i in input().split()]
    G = [(-int(i),2) for i in input().split()]
    M = [(-int(i),0) for i in input().split()]
    
    flag = False
    M.sort(key =lambda x:x[0])
    idx = 0
    heapify(R)
    heappush(R,M[idx])
    idx += 1
    ans = 0
    for _ in range(x):
        p,color = heappop(R)
        ans -= p
        if idx == c and color == 0:
            flag = True
        if color == 0 and idx < c:
            heappush(R,M[idx])
            idx += 1
            
    
    heapify(G)
    if flag == False:
        heappush(G,M[idx - 1])

    for _ in range(y):
        p,color = heappop(G)
        ans -= p
        if color == 0 and idx < c:
            heappush(G,M[idx])
            idx += 1
    print(ans)
 
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

h = []
for i in p:
    heappush(h, (-i,0))
for i in q:
    heappush(h, (-i,1))
for i in r:
    heappush(h, (-i,2))
ans = 0
red = 0
green = 0
not_col = 0
while h:
    d, col = heappop(h)
    if col == 0 and red + not_col < x:
        red += 1
        ans += -d
    elif col == 1 and green + not_col < y:
        green += 1
        ans += -d
    elif col == 2 and red + green + not_col < x+y:
        not_col += 1
        ans += -d
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) + [-1]

ans = 0
i,j,k = 0,0,0
s,t = 0,0
while s < x or t < y:
    if s < x and p[i] >= r[k] and (t == y or p[i] >= q[j]):
        ans += p[i]
        i += 1
        s += 1
        continue
    elif t < y and q[j] >= r[k] and (s == x or q[j] >= p[i]):
        ans += q[j]
        j += 1
        t += 1
        continue
    if s < x and r[k] >= p[i] and (t == y or p[i] <= q[j]):
        ans += r[k]
        k += 1
        s += 1
        continue
    if t < y and r[k] >= q[j] and (s == x or q[j] <= p[i]):
        ans += r[k]
        k += 1
        t += 1
        continue


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

apple=[[p[i],1] for i in range(a)]
apple+=[[q[i],2] for i in range(b)]
apple+=[[r[i],0] for i in range(c)]
apple=sorted(apple,reverse=True)
tx,ty=0,0
ans=0
for d,c in apple:
    if c==1 and tx<x: ans+=d;tx+=1
    elif c==2 and ty<y: ans+=d;ty+=1
    elif c==0 and tx<x: ans+=d;tx+=1
    elif c==0 and ty<y: ans+=d;ty+=1
print(ans)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  if RA[eatRA - 1] > GA[eatGA -1]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C:
    break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
print(ans)

Submission status: Wrong Answer

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

X,Y,A,B,C=map(int,readline().split())
P=sorted(list(map(int,readline().split())))
Q=sorted(list(map(int,readline().split())))
R=sorted(list(map(int,readline().split())))


# X,Y子を越えたP,Qは使わない
P=P[-X:]
Q=Q[-Y:]

PQ=sorted(P+Q)

allsum=sum(PQ)

ind=0
for i in range(len(R)):
    if R[i]>PQ[ind]:
        allsum+=R[i]-PQ[ind]
        ind+=1
        if ind==len(PQ):
            break
        
print(allsum)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, 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()]
P.sort()
Q.sort()
R.sort()

p, q, r = A - 1, B - 1, C - 1
ans = 0
flag = True
for i in range(Y):
    if Q[q] < R[r] and flag:
        ans += R[r]
        r -= 1
    else:
        ans += Q[q]
        q -= 1
    if r <= 0:
        flag = False
        
for i in range(X):
    if P[p] < R[r] and flag:
        ans += R[r]
        r -= 1
    else:
        ans += P[p]
        p -= 1
    if r <= 0:
        flag = False

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()
l = p[a-x:a] + q[b-y:b]
l.sort()

j = 0
for i in range(min(c,x+y)):
    if l[j] < r[i]:
        l[j] = r[i]
        j += 1
print(sum(l))

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()
    xlist = []
    ylist = []
    for i in range(x):
        if len(r) != 0:
            if p[i] >= r[-1]:
                xlist.append(p[i])
            else:
                rele = r.pop()
                xlist.append(rele)
        else:
            xlist.append(p[i])
    for i in range(y):
        if len(r) != 0:
            if q[i] >= r[-1]:
                ylist.append(q[i])
            else:
                rele = r.pop()
                ylist.append(rele)
        else:
            ylist.append(q[i])

    print(sum(xlist)+sum(ylist))


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

Submission status: Wrong Answer

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

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

def eat(l, x):
	global r
	delish = 0
	for i in range(x):
		red = 0
		if l:
			red = l[-1]
		colorless = 0
		if r:
			colorless = r[-1]
		if red > colorless:
			delish += l.pop()
		else:
			delish += r.pop()
	return delish

delish = eat(p, x)
delish += eat(q, y)
print(delish)

Submission status: Wrong Answer

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


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    d = sorted(p[:X] + q[:Y])
    e = [max(d, c) for d, c in zip(d, r+[0]*(X+Y))]
    print(sum(e))

# 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())
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]
ans=0
while(1):
	if X==0 and Y==0:
		print(ans)
		break
	elif X>0 and Y>0:
		tmp=max(P[0],Q[0],R[0])
		ans+=tmp
		if tmp==P[0]:
			P.pop(0)
			X-=1
		elif tmp==Q[0]:
			Q.pop(0)
			Y-=1
		elif tmp==R[0]:
			if P[0]>=Q[0]:
				R.pop(0)
				Y-=1
			else:
				R.pop(0)
				X-=1
	elif X==0:
		tmp=max(Q[0],R[0])
		ans+=tmp
		if tmp==Q[0]:
			Q.pop(0)
			Y-=1
		elif tmp==R[0]:
			R.pop(0)
			Y-=1
	elif Y==0:
		tmp=max(P[0],R[0])
		ans+=tmp
		if tmp==P[0]:
			P.pop(0)
			X-=1
		elif tmp==R[0]:
			R.pop(0)
			X-=1

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = [(-int(i),1) for i in input().split()]
    G = [(-int(i),2) for i in input().split()]
    M = [(-int(i),0) for i in input().split()]
    
    flag = False
    M.sort(key =lambda x:x[0])
    idx = 0
    heapify(R)
    heappush(R,M[idx])
    idx += 1
    ans = 0
    for _ in range(x):
        p,color = heappop(R)
        ans -= p
        if p == M[-1]:
            flag = True
        if color == 0 and idx < c:
            heappush(R,M[idx])
            idx += 1
            
    
    heapify(G)
    if flag == False:
        heappush(G,M[idx - 1])

    for _ in range(y):
        p,color = heappop(G)
        ans -= p
        if color == 0 and idx < c:
            heappush(G,M[idx])
            idx += 1
    print(ans)
 
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
red_que = p[:x]
green_que = q[:y]
for i in range(c):
    if red_que[-1] < green_que[-1]:
        if red_que[-1] < r[i]:
            red_que.pop()
            bisect.insort_left(red_que, r[i])
        else:
            break
    else:
        if green_que[-1] < r[i]:
            green_que.pop()
            bisect.insort_left(green_que, r[i])
print(sum(green_que) + sum(red_que))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = (int(num) for num in input().split())
p = [int(num) for num in input().split()]
q = [int(num) for num in input().split()]
r = [int(num) for num in input().split()]
apples = []
for i in range(a):
    apples.append((p[i],"r"))
for i in range(b):
    apples.append((q[i],"g"))    
for i in range(c):
    apples.append((r[i],"n"))
    
apples.sort(reverse = True)

cntr = 0
cntg = 0
cntall = 0
i = 0
ans = 0
#print(apples)
while True:
    if apples[i][1] == "r" and cntr < x:
        ans += apples[i][0]
        cntr += 1
        cntall += 1
    if apples[i][1] == "g" and cntg < x:
        ans += apples[i][0]
        cntg += 1
        cntall += 1
    if apples[i][1] == "n":
        ans += apples[i][0]
        cntall += 1
        
    if cntall == x + y:
        break
    i += 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()))
L = p + r
L.sort(reverse = True)
ans = 0
for i in range(X):
  ans += int(L[i])
M = q + r
M.sort(reverse = True)
abc = 0  
for i in range(Y):
  abc += int(M[i])
print(ans + abc)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split()) 
p = sorted(list(map(int, input().split())))[a - x:]
q = sorted(list(map(int, input().split())))[b - y:]
r = sorted(list(map(int, input().split())))[max(0, c - x - y):]

s = sorted(p + q)
i = 0
for r_j in r:
  if s[i] < r_j:
    s[i] = r_j
    i += 1

print(sum(s))

Submission status: Wrong Answer

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

INF = 1 << 30
p.append(-INF)
q.append(-INF)
r.append(-INF)

ans = 0
pi = 0
qi = 0
ri = 0
while X > 0 or Y > 0:
  v = max([p[pi], q[qi], r[ri]])
  if v == p[pi] and X > 0:
    ans += p[pi]
    pi += 1
    X -= 1
  elif v == q[qi] and Y > 0:
    ans += q[qi]
    qi += 1
    Y -= 1
  elif v == r[ri]:
    ans += r[ri]
    ri += 1
    if X > 0 and p[pi] <= q[qi]: X -= 1
    elif Y > 0 and q[qi] <= p[pi]: Y -= 1
    elif X > 0: X -= 1
    elif Y > 0: Y -= 1
  elif v == p[pi] and X == 0:
    Y -= 1
    if q[qi] >= r[ri]:
      ans += q[qi]
      qi += 1
    else:
      ans += r[ri]
      ri += 1
  elif v == q[qi] and Y == 0:
    X -= 1
    if p[pi] >= r[ri]:
      ans += p[pi]
      pi += 1
    else:
      ans += r[ri]
      ri += 1
      
print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
rrr.sort(reverse=True)
ppp.insert(0, 0)
qqq.insert(0, 0)
rrr.insert(0, 0)

i = x
j = y
k = 1

while True:
    if k > c:
        break
    if i > 0 and (j == 0 or ppp[i] < qqq[j]) and ppp[i] < rrr[k]:
        i -= 1
        k += 1
        # print('i', i, j, k)
        continue
    if j > 0 and (i == 0 or ppp[i] > qqq[j]) and qqq[j] < rrr[k]:
        j -= 1
        k += 1
        # print('j', i, j, k)
        continue
    break
# print(ppp)
# print(qqq)
# print(rrr)
# print(i, j, k)
print(sum(ppp[:i + 1]) + sum(qqq[:j + 1]) + sum(rrr[:k]))

Submission status: Wrong Answer

Solution code:
import sys
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def LI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))
# from heapq import heappop,heappush,heapify
import heapq
x,y,a,b,c = MI()
p = LI()
q = LI()
r = LI()

result = 0
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

for _ in range(x):
	if not r==[]:
		max_a = heapq.heappop(p)*(-1)
		max_c = heapq.heappop(r)*(-1)
		if max_a>=max_c:
			result += max_a
			a -= 1
			heapq.heappush(r,max_c*(-1))
		else:
			result += max_c
			c -= 1
			heapq.heappush(p,max_a*(-1))
	else:
		max_a = heapq.heappop(p)*(-1)
		result += max_a
		a -= 1

for _ in range(y):
	if not r==[]:
		max_b = heapq.heappop(q)*(-1)
		max_c = heapq.heappop(r)*(-1)
		if max_b>=max_c:
			result += max_b
			b -= 1
			heapq.heappush(r,max_c*(-1))
		else:
			result += max_c
			c -= 1
			heapq.heappush(q,max_b*(-1))
	else:
		max_b = heapq.heappop(q)*(-1)
		result += max_b
		b -= 1

print(result)

Submission status: Wrong Answer

Solution code:
#heapだけ？
#x<=a,y<=b
import heapq
x,y,a,b,c = map(int, input().split( ))

*p, = map(int, input().split( ))
*q, = map(int, input().split( ))
*r, = map(int, input().split( ))
#p = [(pi,0) for pi in p_]
#q = [(qi,1) for qi in q_]
#r = [(ri,2) for ri in r_]
p = p[-x:]
q = q[-y:]
e = p+q
heapq.heapify(e)
assert (len(e)==x+y)
for ri in r:
    heapq.heappush(e,ri)
    heapq.heappop(e)
print(sum(e))

Submission status: Wrong Answer

Solution code:

X, Y, A, B, C = [int(s) for s in input().split()]
p_list = [int(s) for s in input().split()]
q_list = [int(s) for s in input().split()]
r_list = [int(s) for s in input().split()]

p_list = list(reversed(sorted(p_list)))
# print(p_list)
q_list = list(reversed(sorted(q_list)))
# print(q_list)
r_list = list(reversed(sorted(r_list)))
# print(r_list)

p_i = 0
temp_p = p_list[p_i]

q_i = 0
temp_q = q_list[q_i]

r_i = 0
temp_r = r_list[r_i]

d = 0

for i in range(X):
    if temp_p >= temp_r:
        d += temp_p
        p_i += 1
        if p_i == A:
            temp_p = 0
        else:
            temp_p = p_list[p_i]
    else:
        d += temp_r
        r_i += 1
        if r_i == C:
            temp_r = 0
        else:
            temp_r = r_list[r_i]

for i in range(Y):
    if temp_q >= temp_r:
        d += temp_q
        q_i += 1
        if q_i == B:
            temp_q = 0
        else:
            temp_q = q_list[q_i]
    else:
        d += temp_r
        r_i += 1
        if r_i == C:
            temp_r = 0
        else:
            temp_r = r_list[r_i]

print(d)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = list(map(int, input().split()))
ppp = list(map(int, input().split()))
qqq = list(map(int, input().split()))
rrr = list(map(int, input().split()))
ppp.sort(reverse=True)
qqq.sort(reverse=True)
rrr.sort(reverse=True)
ppp.insert(0, 0)
qqq.insert(0, 0)
rrr.insert(0, 0)

i = x
j = y
k = 1

while True:
    if k > c:
        break
    if i > 0 and ppp[i] < qqq[j] and ppp[i] < rrr[k]:
        i -= 1
        k += 1
        # print('i', i, j, k)
        continue
    if j > 0 and ppp[i] > qqq[j] and qqq[j] < rrr[k]:
        j -= 1
        k += 1
        # print('j', i, j, k)
        continue
    break
# print(ppp)
# print(qqq)
# print(rrr)
# print(i, j, k)
print(sum(ppp[:i + 1]) + sum(qqq[:j + 1]) + sum(rrr[:k]))

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, 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()]
P.sort()
Q.sort()
R.sort()

p,q,r = A - 1, B - 1, C - 1
ans = 0
flag = True
for i in range(X):
    if P[p] < R[r] and flag:
        ans += R[r]
        r -= 1
    else:
        ans += P[p]
        p -= 1
for i in range(Y):
    if Q[q] < R[r] and flag:
        ans += R[r]
        r -= 1
    else:
        ans += Q[q]
        q -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P.sort()
Q.sort()
R.sort()
ans = 0
for i in range(X):
    if R and R[-1] > P[-1]:
        a = R.pop()
    else:
        a = P.pop()
    ans += a
for i in range(Y):
    if R and R[-1] > Q[-1]:
        a = R.pop()
    else:
        a = Q.pop()
    ans += a
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    x,y,a,b,c=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    P.sort()
    Q.sort()
    R.sort()
    P_=P[a-x:][::-1]
    Q_=Q[b-y:][::-1]
    ans=sum(P_)+sum(Q_)
    for i in range(c):
        r=R.pop()
        if not P_:
          	P_.append(float("INF"))
        if not Q_:
          	Q_.append(float("INF"))
        if r<=P_[-1] and r<=Q_[-1]:
            break
        elif r>P_[-1] and P_[-1]<=Q[-1]:
            p=P_.pop()
            ans+=r-p
        else:
            q=Q_.pop()
            ans+=r-q
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import chain
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    xy = sorted(chain(
        ((p[i], 0) for i in range(X)),
        ((q[i], 1) for i in range(Y)),
    ))
    x = X
    y = Y
    a = 0
    while a < X + Y and X + Y - x - y < C and xy[a][0] < r[X + Y - x - y]:
        if xy[a][1] == 0 and x > 0:
            x -= 1
            a += 1
        if xy[a][1] == 1 and y > 0:
            y -= 1
            a += 1
    print(sum(p[:x]) + sum(q[:y]) + sum(r[:X + Y - x - y]))


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:
def examA():
    S = SI()
    if S[2]==S[3] and S[4]==S[5]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    X = I()
    ans = 0
    ans += (X//500) * 1000
    X %= 500
    ans += (X//5) * 5
    print(ans)
    return

def examC():
    K, N = LI()
    A = LI()
    L = [0]*N
    L[0] = K-A[-1] + A[0]
    for i in range(1,N):
        L[i] = A[i]-A[i-1]
    ans = sum(L) - max(L)
    #print(L)
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = nowW + 1
                    que.append(ne)
        return W
    N, X, Y = LI()
    V = [[]for _ in range(N)]
    for i in range(N-1):
        V[i].append(i+1)
        V[i+1].append(i)
    V[X-1].append(Y-1)
    V[Y-1].append(X-1)
    #print(V)
    ans = [0]*(N-1)
    for i in range(N):
        L = bfs(N,i,V)
        for l in L:
            if l==0:
                continue
            ans[l-1] += 1
    for v in ans:
        print(v//2)
    return

def examE():
    X, Y, A, B, C = LI()
    P = LI()
    Q = LI()
    R = LI()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    cnt = sum(P[:X]) + sum(Q[:Y])
    #print(cnt)
    X -= 1; Y -= 1
    for c in range(C):
        if X>=0 and Y>=0:
            if P[X] <= Q[Y]:
                if P[X] >= R[c]:
                    break
                cnt += (R[c] - P[X])
                X -= 1
            else:
                if Q[Y] >= R[c]:
                    break
                cnt += (R[c] - Q[Y])
                Y -= 1
        if X>=0:
            if P[X] >= R[c]:
                break
            cnt += (R[c] - P[X])
            X -= 1
        if Y>=0:
            if Q[Y] >= R[c]:
                break
            cnt += (R[c] - Q[Y])
            Y -= 1
    ans = cnt
    print(ans)
    return

def examF():
    N = I()
    V = [[]for _ in range(N)]

    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Submission status: Wrong Answer

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

fr = sorted(red, reverse= True)
fg = sorted(green, reverse= True)
candidate = fr + fg + trans
candidate = sorted(candidate, reverse= True)
candidate = candidate[:x+y]
print(sum(candidate))

Submission status: Wrong Answer

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

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

A = sorted(A)
B = sorted(B)
C = sorted(C)[::-1]

t = 0
s = 0

for i in range(c):
    if A[t] < B[s] and A[t] < C[i]:
        A[t] = C[i]
        t += 1
    elif B[s] < A[t] and B[s] < C[i]:
        B[s] = C[i]
        s += 1
A = sorted(A)
B = sorted(B)
print(sum(A[-x:]) + sum(B[-y:]))

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    if S[2]==S[3] and S[4]==S[5]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    X = I()
    ans = 0
    ans += (X//500) * 1000
    X %= 500
    ans += (X//5) * 5
    print(ans)
    return

def examC():
    K, N = LI()
    A = LI()
    L = [0]*N
    L[0] = K-A[-1] + A[0]
    for i in range(1,N):
        L[i] = A[i]-A[i-1]
    ans = sum(L) - max(L)
    #print(L)
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = nowW + 1
                    que.append(ne)
        return W
    N, X, Y = LI()
    V = [[]for _ in range(N)]
    for i in range(N-1):
        V[i].append(i+1)
        V[i+1].append(i)
    V[X-1].append(Y-1)
    V[Y-1].append(X-1)
    #print(V)
    ans = [0]*(N-1)
    for i in range(N):
        L = bfs(N,i,V)
        for l in L:
            if l==0:
                continue
            ans[l-1] += 1
    for v in ans:
        print(v//2)
    return

def examE():
    X, Y, A, B, C = LI()
    P = LI()
    Q = LI()
    R = LI()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    cnt = sum(P[:X]) + sum(Q[:Y])
    #print(cnt)
    X -= 1; Y -= 1
    for c in range(C):
        if P[X]<=Q[Y]:
            if P[X]>=R[c]:
                break
            cnt += (R[c]-P[X])
            X -= 1
        else:
            if Q[Y]>=R[c]:
                break
            cnt += (R[c]-Q[Y])
            Y -= 1
    ans = cnt
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Submission status: Wrong Answer

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

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

A = sorted(A)
B = sorted(B)
C = sorted(C)

t = 0
s = 0

for i in range(c):
    if A[t] < B[s] and A[t] < C[i]:
        A[t] = C[i]
        t += 1
    elif B[s] < A[t] and B[s] < C[i]:
        B[s] = C[i]
        s += 1
print(sum(A[-x:]) + sum(B[-y:]))