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

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect




from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline

sys.setrecursionlimit(2147483647)

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 += p[:x] + q[:y]
  r.sort(reverse=True)
  ans = sum(r[:x+y])
  print(ans)
  

if __name__ == '__main__':
  main()

Solution (Python):
import sys
from collections import Counter
input = sys.stdin.readline

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

ans = []

ans.extend(sorted(p, reverse=True)[:X])
ans.extend(sorted(q, reverse=True)[:Y])
ans.extend(r)
ans.sort(reverse=True)

print(sum(ans[:X+Y]))

Solution (Python):
import sys
input = sys.stdin.readline
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in input().split()]
q = [[int(x), "B"] for x in input().split()]
r = [[int(x), "C"] for x in input().split()]

apples = p+q+r


apples.sort(reverse=True)

ans = 0
pend = 0


for hapi, col in apples:
    if col == "C":
        pend += 1
        ans += hapi
    elif col == "A":
        if X > 0:
            ans += hapi
            X -= 1

    elif col == "B":
        if Y>0:
            ans += hapi
            Y -= 1

    if (X < 1 and Y < 1) or X+Y == pend:
        break
    
    

print(ans)

Solution (Python):
x, y, a, b, c = map(int, input().split())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
cl = list(map(int, input().split()))
r.sort(reverse=True)
g.sort(reverse=True)
ans = r[:x] + g[:y] + cl
print(sum(sorted(ans, reverse=True)[:x+y]))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
x,y,a,b,c=LI()
p=sorted(LI())[-x:]
q=sorted(LI())[-y:]
r=LI()+p+q

print(sum(sorted(r)[-x-y:]))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

s = sorted(p + q + r, reverse=True)
print(sum(s[:X + Y]))

Solution (Python):
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()


all = p[:x] + q[:y] + r
all.sort(reverse=True)

print(sum(all[:x+y]))

Solution (Python):
def main():
    s = open(0).readlines()

    x, y, a, b, c = map(int, s[0].split())
    f = lambda x: list(map(int, x.split()))

    p, q, r = map(f, s[1:])

    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    r = sorted(r, reverse=True)

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

    i = max(r)
    j = sum(x > i for x in p)
    k = sum(x > i for x in q)

    pd = p[j:]
    qd = q[k:]

    m = (x - j) + (y - k)

    rem = sorted(pd + qd + r, reverse=True)
    ans = sum(p[:j] + q[:k]) + sum(rem[:m])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys


def main():
    x, y, a, b, c = [int(s) for s in sys.stdin.readline().strip().split()]
    p = [int(s) for s in sys.stdin.readline().strip().split()]
    q = [int(s) for s in sys.stdin.readline().strip().split()]
    r = [int(s) for s in sys.stdin.readline().strip().split()]

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

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

    combined = p + q + r
    combined.sort(reverse=True)
    print(sum(combined[:x+y]))

main()

Solution (Python):
def resolve():
    import heapq
    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 = sorted(p, reverse=True)[:x]
    q = sorted(q, reverse=True)[:y]
    heapq.heapify(p)
    heapq.heapify(q)
    r = deque(sorted(r, reverse=True))
    while r:
        testp = heapq.heappop(p)
        testq = heapq.heappop(q)
        testr = r.pop()
        if testp <= testq:
            heapq.heappush(q, testq)
            if testp <= testr:
                heapq.heappush(p, testr)
            else:
                heapq.heappush(p, testp)

        if testp > testq:
            heapq.heappush(p, testp)
            if testq <= testr:
                heapq.heappush(q, testr)
            else:
                heapq.heappush(q, testq)
    print(sum(p+q))
resolve()

Solution (Python):



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)

x_p = []
y_q = []
xy_r = []
c = 0
for p in P[::-1]:
    if c == X: break
    x_p.append(p)
    c += 1
c = 0
for q in Q[::-1]:
    if c == Y: break
    y_q.append(q)
    c += 1
c = 0
for r in R[::-1]:
    if c == X+Y: break
    xy_r.append(r)
    c += 1



p_i = len(x_p)-1
q_i = len(y_q)-1
xy_i = 0


f = True

while f:
    if xy_i == len(xy_r): break
    p = x_p[p_i]
    q = y_q[q_i]
    s = ''
    if p > q:
        s = 'q'
        mi = q_i
    else:
        s = 'p'
        mi = p_i
    if s == 'p' and p < xy_r[xy_i]:
        x_p[p_i] = xy_r[xy_i]
        p_i -= 1
        xy_i += 1
    elif s == 'q' and q < xy_r[xy_i]:
        y_q[q_i] = xy_r[xy_i]
        q_i -= 1
        xy_i += 1
    else:
        f = False

ans = sum(x_p) + sum(y_q)
print(ans)

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

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))

Solution (Python):
import sys

X, Y, A, B, C = map(int, sys.stdin.readline().strip().split())

P = list(map(int, sys.stdin.readline().strip().split()))
Q = list(map(int, sys.stdin.readline().strip().split()))
R = list(map(int, sys.stdin.readline().strip().split()))

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

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

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

ans = []

ans.extend(sorted(p,reverse=True)[:x])
ans.extend(sorted(q,reverse=True)[:y])
ans.extend(r)
ans.sort(reverse=True)

print(sum(ans[:x+y]))

Solution (Python):
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+1):
    if R < 0:
        break
    if P < A:
        if (r[C-i-1] >= p[P]):
            if Q < B:
                if (q[Q] >= p[P]):
                    P += 1
                    R -= 1
                elif r[C-i-1] > q[Q]:
                    Q += 1
                    R -= 1
                else:
                    break
            else:
                P += 1
                R -= 1
        elif Q < B:
            if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
            else:
                break
        else:
            break
    elif Q < B:
        if r[C-i-1] > q[Q]:
            Q += 1
            R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))

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

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))

Solution (Python):
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)
    ans=r+p[:x]+q[:y]
    ans.sort(reverse=True)
    print(sum(ans[:x+y]))

if __name__ == '__main__':
    main()

Solution (Python):
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(int,input().split()))
lst_r = sorted(lst_r, reverse=True)[:x]
lst_g = sorted(lst_g, reverse=True)[:y]
lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[:x+y]
print(sum(lst_all))

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

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))

Solution (Python):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0
P=[]
for i in range(X):
    P.append(p[i])
    
for i in range(Y):
    P.append(q[i])
    
P.sort()
tmp=0
Q=[]
count=0
for i in range(C):
    if count>=(X+Y):
        break
    if r[i]>P[count]:
        Q.append(r[i])
        count+=1
    else:
        break
R=[]
ans=0
for i in range(len(Q)):
    ans+=Q[i]
for i in range(len(Q),X+Y):
    ans+=P[i]


print(ans)

Solution (Python):
f=lambda:list(map(int,input().split()))
X,Y,*e=f()
P=f()
Q=f()
R=f()
P.sort()
Q.sort()
R.sort()
print(sum(sorted(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Solution (Python):
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x:]
q=sorted(list(map(int,input().split())))[-y:]
r=sorted(list(map(int,input().split())))
s=sorted(p+q+r)[-x-y:]
print(sum(s))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    X, Y, A, B, C = Scanner.map_int()
    P = Scanner.map_int()
    Q = Scanner.map_int()
    R = Scanner.map_int()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)
    P = P[:X]
    Q = Q[:Y]
    A = P + Q + R
    A.sort(reverse=True)
    print(sum(A[:X + Y]))


if __name__ == "__main__":
    main()

Solution (Python):
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)

l = p[:x] + q[:y] + r
l.sort(reverse=True)

print(sum(l[:x+y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
pp = list(sorted(map(int, input().split()), reverse=True))[:x]
qq = list(sorted(map(int, input().split()), reverse=True))[:y]
rr = list(map(int, input().split()))

xx = list(sorted(pp + qq + rr, reverse=True))[:x+y]
print(sum(xx))

Solution (Python):
X, Y, A, B, C = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
list = list(map(int, input().split()))

Alist.sort(reverse = True)
Blist.sort(reverse = True)

for i in range(X):
    list.append(Alist[i])
for i in range(Y):
    list.append(Blist[i])
list.sort(reverse = True)

ans =0
for i in range(X + Y):
    ans += list[i]
    
print(ans)

Solution (Python):
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)

apples = p[:X] + q[:Y] + r
apples.sort(reverse=True)

value = sum(apples[:X+Y])
print(value)

Solution (Python):
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:]
p.extend(q)
p.extend(r)
p.sort(reverse=True)
print(sum(p[:x+y]))

Solution (Python):
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)
rr = [0]
for i in r:
    rr.append(rr[-1]+i)
p = p[:x]
q = q[:y]
pq = sorted(p+q)
ppqq = [sum(pq)]
for i in pq:
    ppqq.append(ppqq[-1]-i)
result = []
for i in range(min(x+y, c+1)):
    result.append(ppqq[i]+rr[i])
print(max(result))

Solution (Python):

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()
z = p[-x:]
z.extend(q[-y:])
z.extend(r)
z.sort()

print(sum(z[-x-y:]))

Solution (Python):
from heapq import heapify, heappush, heappop

X, Y, A, B, C = map(int, input().split())
Ps = list(map(int, input().split()))
Qs = list(map(int, input().split()))
Rs = list(map(int, input().split()))

Ps.sort(reverse=True)
Qs.sort(reverse=True)
Rs.sort(reverse=True)

PQRed = Ps[:X]
PQGreen = Qs[:Y]
sumRed = sum(PQRed)
sumGreen = sum(PQGreen)
heapify(PQRed)
heapify(PQGreen)


ans = sumNow = sumRed + sumGreen

for R in Rs:

    r = PQRed[0]
    g = PQGreen[0]

    if r <= g:
        d = heappop(PQRed)
        heappush(PQRed, R)
    else:
        d = heappop(PQGreen)
        heappush(PQGreen, R)
    if R <= d:
        break
    sumNow += R-d

    if sumNow > ans:
        ans = sumNow

print(ans)

Solution (Python):
f=lambda:list(map(int,input().split()))
X,Y,*e=f()
P=f()
Q=f()
R=f()
P.sort()
Q.sort()
R.sort()
print(sum(sorted(P[-X:]+Q[-Y:]+R)[-X-Y:]))

Solution (Python):
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 = sorted(P, reverse=True)[:X]
Q = sorted(Q, reverse=True)[:Y]
print(sum(sorted(P + Q + R, reverse=True)[:X + Y]))

Solution (Python):
from functools import lru_cache

X, Y, A, B, C = [int(x) for x in 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()]

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

red = P[:X]
green = Q[:Y]
best = sum(red) + sum(green)

for x in R:
    smaller = None
    if not red and not red:
        break
    elif red and green:
        if red[-1] < green[-1]:
            smaller = red
        else:
            smaller = green
    elif red:
        smaller = red
    elif green:
        smaller = green
    else:
        assert False

    if smaller[-1] < x:
        best -= smaller.pop()
        best += x
print(best)

Solution (Python):

X,Y,A,B,C= map(int, input().split())
a =sorted(list(map(int, input().split())),reverse=True)
b =sorted(list(map(int, input().split())),reverse=True)
c =sorted(list(map(int, input().split())),reverse=True)
DP_a =a[:X]
DP_b =b[:Y]
DP_a.extend(DP_b)
DP_a.extend(c)
ans = sorted(DP_a,reverse=True)
print(sum(ans[:X+Y]))

Solution (Python):
import sys
input = sys.stdin.buffer.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()))
    p.sort()
    q.sort()
    r.sort()
    p = p[-X:]
    q = q[-Y:]
    use = p+q+r
    use.sort(reverse=True)
    print(sum(use[:X+Y]))

if __name__ == "__main__":
    main()

Solution (Python):
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)

for i in p[:X]:
    r.append(i)
for j in q[:Y]:
    r.append(j)
r.sort(reverse=True)
print(sum(r[:X + Y]))

Solution (Python):

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]

ans = p + q + r

ans.sort(reverse=True)

ans = ans[:x+y]

print(sum(ans))

Solution (Python):
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.sort(reverse=True)
A.sort()
B.sort()
C.sort(reverse=True)
A=A[a-x:]
B=B[b-y:]

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
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)
mod = 1000000007

def solve():
    x,y,a,b,c = LI()
    p = LI()
    q = LI()
    r = LI()
    p.sort(reverse = True)
    q.sort(reverse = True)
    s = p[:x]+q[:y]+r
    s.sort(reverse = True)
    print(sum(s[:x+y]))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
LMIIS = lambda: list(map(int,input().split()))
X,Y,*e = LMIIS()
P = LMIIS()
Q = LMIIS()
R = LMIIS()
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))

Solution (Python):
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)[:x]
q = sorted(map(int, input().split()), reverse=True)[:y]
r = list(map(int, input().split()))
ls = sorted(p+q+r, reverse=True)[:x+y]
print(sum(ls))

Solution (Python):
import heapq as hq

x,y,a,b,c=map(int,input().split())
R=list(reversed(sorted(map(int,input().split()))))
G=list(reversed(sorted(map(int,input().split()))))
N=list(reversed(sorted(map(int,input().split()))))
A=[]
hq.heapify(A)
for i in range(x):
    hq.heappush(A,-R[i])
for i in range(y):
    hq.heappush(A,-G[i])
for n in N:
    hq.heappush(A,-n)

ans=0
for i in range(x+y):
    ans-=hq.heappop(A)
print(ans)

Solution (Python):
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y]
px = 0
qx = 0
for i in range(C):
    if px == len(p) and qx == len(q):
        break
    elif px == len(p):
        if min(q[qx],r[i])==q[qx]:
            q[qx] =r[i]
            qx += 1
        else:
            break
    elif qx == len(q):
        if min(p[px],r[i])==p[px]:
            p[px] =r[i]
            px += 1
        else:
            break
    else:
        if min(p[px],q[qx],r[i]) ==p[px]:
            p[px] = r[i]
            px +=1
        elif min(p[px],q[qx],r[i]) ==q[qx]:
            q[qx] = r[i]
            qx += 1
        else:
            break
print(sum(p)+sum(q))

Solution (Python):
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pa =  [0] + list(itertools.accumulate(p))
qa =  [0] + list(itertools.accumulate(q))
p = [INF] + p
q = [INF] + q
red = X
green = Y
t = 0
pl = 0
while p[red] < r[t] or q[green] < r[t]:
    pl += r[t]
    t += 1
    if p[red] < q[green] :
        red -= 1
    else:
        green -= 1
    if t >=C or (green ==0 and red ==0): break
print (pa[red] + qa[green] + pl)

Solution (Python):
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)

apples = p[:x] + q[:y] + r
apples.sort(reverse=True)

ans = sum(apples[:x+y])
print(ans)

Solution (Python):



import sys
from collections import deque


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, Y, A, B, C = i2nn()
    p = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:X])
    q = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:Y])
    r = deque(sorted(map(int, i2s().split(' '))))
    s = 0
    while p or q:
        if p and q:
            t = p if p[-1] < q[-1] else q
        else:
            t = p if p else q
        if r and t[-1] < r[-1]:
            t.pop()
            s += r.pop()
        else:
            r.clear()
            s += t.pop()
    print(s)
    return

main()

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

s = p+q+r
s.sort(reverse = True)
print(sum(s[:x+y]))

Solution (Python):
from copy import copy

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

p.sort()
q.sort()

apple = p[-X:] + q[-Y:] + r
apple.sort()

print(sum(apple[-X-Y:]))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

X, Y, A, B, C = map(int, input().split())
cand = []
p = list(map(int, (input().split())))
p.sort(reverse=True)
cand.extend(p[:X])
q = list(map(int, (input().split())))
q.sort(reverse=True)
cand.extend(q[:Y])
r = list(map(int, (input().split())))
cand.extend(r)
cand.sort(reverse=True)
ans = sum(cand[:X+Y])
print(ans)

Solution (Python):
x,y,a,b,c = [int(x) for x in 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()]

P = sorted(p, reverse=True)
Q = sorted(q, reverse=True)
l = P[:x] + Q[:y] + r
L = sorted(l, reverse=True)

print(sum(L[:(x+y)]))

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    X, Y, A, B, C = input_nums()
    P = input_nums()
    Q = input_nums()
    R = input_nums()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort()

    P = sorted(P[:X])
    Q = sorted(Q[:Y])
    res = []
    res = P + Q + R
    res.sort(reverse=True)
    print(sum(res[:X+Y]))
if __name__ == '__main__':
    main()

Solution (Python):
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)

    p = p[:X]
    q = q[:Y]
    pqr = p + q + r
    pqr.sort(reverse = True)
    return sum(pqr[:X+Y])




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

Solution (Python):
def main():
    X, Y, A, B, C = map(int, input().split())
    *p, = sorted(map(int, input().split()), reverse=True)
    *q, = sorted(map(int, input().split()), reverse=True)
    *r, = map(int, input().split())

    pool = p[:X] + q[:Y] + r
    pool.sort(reverse=True)
    ret = sum(pool[:X + Y])
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())))
q = sorted(list(map(int,input().split())))
r = list(map(int,input().split()))
ans = 0

for k in range(1,x+1):
    r.append(p[-k])
for v in range(1,y+1):
    r.append(q[-v])

rs = sorted(r)

for i in range(1,x+y+1):
    ans += rs[-i]
print(str(ans))

Solution (Python):
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 9)

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[0:X]
q = q[0:Y]

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

print(sum(s[0:(X + Y)]))

Solution (Python):
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]

if y >= 1:
    for i in range(y):
        sum += q[i]

if c_ori > c:
    for i in range(c,c_ori):
        sum += r[i]
print(sum)

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

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

ans=0
v=[]
for i in range(x):
    v.append(p[i])
for i in range(y):
    v.append(q[i])

v.sort()

w=0
for i in range(min(x+y,c)):
    if v[i]<r[w]:
        v[i]=r[w]
        w+=1

print(sum(v))