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: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    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()))
    i,j,k = 0,0,0
    p.sort(reverse=1)
    q.sort(reverse=1)
    r.sort(reverse=1)
    res = 0
    #[値, 種類, インデックス]
    hq = [[-p[0], 0, 0], [-q[0], 1, 0], [-r[0], 2, 0]]
    heapify(hq)
    n = 0
    while X+Y>n:
        x,y,z = heappop(hq)
        res += -x
        n += 1
        if y==0 and z+1<X:
            heappush(hq, [-p[z+1], 0, z+1])
        if y==1 and z+1<Y:
            heappush(hq, [-q[z+1], 1, z+1])
        if y==2 and z+1<c:
            heappush(hq, [-r[z+1], 2, z+1])
    print(res)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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)

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

print(ans)

Submission status: Accepted

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

pqr = sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(pqr[:x+y]))

Submission status: Accepted

Solution code:
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_1 = deque(sorted(p))
q_1 = deque(sorted(q))
r_1 = sorted(r)
while len(p_1) > x:
  p_1.popleft()
while len(q_1) > y:
  q_1.popleft()
pqr = deque(sorted(list(p_1) + list(q_1) + r_1))
i = 0
ans = 0
while i < x+y:
  ans += pqr.pop()
  i += 1
print(ans)

Submission status: Accepted

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

def readlines(*xy):
    for n in xy:
        yield sorted(map(int, input().split()), reverse=True)[:n]
    
    yield list(map(int, input().split()))

def main():
    x, y, a, b, c = map(int, input().split())
    apples = sorted(chain(*readlines(x,y)), reverse=True)
    print(sum(apples[:x+y]))


main()

Submission status: Accepted

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

def readlines(*xy):
    for n in xy:
        yield sorted(map(int, input().split()), reverse=True)[:n]
    
    yield map(int, input().split())

def main():
    x, y, a, b, c = map(int, input().split())
    apples = sorted(chain(*readlines(x,y)), reverse=True)
    print(sum(apples[:x+y]))


main()

Submission status: Accepted

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

def readlines(*xy):
    for n in xy:
        yield sorted(map(int, input().split()), reverse=True)[:n]

def main():
    x, y, a, b, c = map(int, input().split())
    apples = sorted(chain(*readlines(x,y,c)), reverse=True)
    print(sum(apples[:x+y]))


main()

Submission status: Accepted

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

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

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];

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

p.sort();
p.reverse();
q.sort();
q.reverse();
r.sort();
r.reverse();
for i in range(x) :
    um[i] = p[i];
for i in range(y) :
    um[i+x] = q[i];
for i in range(c) :
    um[i+x+y] = r[i];

um.sort();
um.reverse();

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

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

ans = 0;
for i in range(x+y) :
    ans += um[i];

print(ans);

Submission status: Accepted

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

ans = 0
for i in range(x+y):
    ans += al[-(i+1)]

print(ans)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


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

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


main()

Submission status: Accepted

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

all1 = p0 + q0 + r
all1.sort()

print(sum(all1[-(x+y):]))

Submission status: Accepted

Solution code:
import heapq

x,y,a,b,c=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
arr3=list(map(int,input().split()))
q=[]
for val in arr1:
  heapq.heappush(q,(-val,1))
for val in arr2:
  heapq.heappush(q,(-val,2))
for val in arr3:
  heapq.heappush(q,(-val,3))
ans=0
cnt1=0
cnt2=0
cnt3=0
while cnt1+cnt2+cnt3<x+y:
  tmp,flag=heapq.heappop(q)
  tmp*=-1
  if flag==1:
    if cnt1<x:
      ans+=tmp
      cnt1+=1
  elif flag==2:
    if cnt2<y:
      ans+=tmp
      cnt2+=1
  elif flag==3:
    ans+=tmp
    cnt3+=1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
X, Y, A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
ps = list(map(int, stdin.readline().rstrip().split()))
qs = list(map(int, stdin.readline().rstrip().split()))
rs = list(map(int, stdin.readline().rstrip().split()))

ps.sort()
qs.sort()

del ps[0:A-X]
del qs[0:B-Y]

l = ps + qs + rs

l.sort()
del l[0:len(l)-X-Y]

print(sum(l))

Submission status: Accepted

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

P = P[:X]
Q = Q[:Y]

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

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

Submission status: Accepted

Solution code:
X, Y, A, B, C = list(map(lambda x: int(x) ,input().split(" ")))
li = []
p = list(map(lambda x: int(x) ,input().split(" ")))
q = list(map(lambda x: int(x) ,input().split(" ")))
r = list(map(lambda x: int(x) ,input().split(" ")))

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

X, Y, A, B, C = LI()
P = LI()
Q = LI()
R = LI()

P.sort(reverse=True)
Q.sort(reverse=True)
P = P[0 : X]
Q = Q[0 : Y]

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

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

Submission status: Accepted

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)
red = P[:X]
green = Q[:Y]
ALL = red + green
R = list(map(lambda x: x*(-1), R))
ALL = list(map(lambda x: x*(-1), ALL))

heapq.heapify(R)
heapq.heapify(ALL)

ans = 0
loop = len(ALL)

for _ in range(loop):
    if len(R) == 0:
        ans += heapq.heappop(ALL)*(-1)
    elif len(ALL) == 0:
        ans += heapq.heappop(R)*(-1)
    elif R[0]*(-1) < ALL[0]*(-1):
        ans += heapq.heappop(ALL)*(-1)
    else:
        ans += heapq.heappop(R)*(-1)

print(ans)

Submission status: Accepted

Solution code:
#abc160e
x,y,a,b,c=map(int,raw_input().split())
p=map(int,raw_input().split())
q=map(int,raw_input().split())
r=map(int,raw_input().split())
p.sort(reverse=True)
q.sort(reverse=True)
z=p[:x]+q[:y]+r
z.sort(reverse=True)
print sum(z[:x+y])

Submission status: Accepted

Solution code:
import heapq

X,Y,A,B,C = map(int,input().split())
P = list(map(lambda x: -int(x),input().split()))
Q = list(map(lambda x: -int(x),input().split()))
R = list(map(lambda x: -int(x),input().split()))
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)

for _ in range(X):
    a = heapq.heappop(P)
    heapq.heappush(R,a)

for _ in range(Y):
    a = heapq.heappop(Q)
    heapq.heappush(R,a)

s = 0
for _ in range(X+Y):
    s += heapq.heappop(R)

print(-s)

Submission status: Accepted

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

Submission status: Accepted

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)[::-1]
Q = sorted(Q)[::-1]
# R = sorted(R)[::-1]

P = P[:X]
Q = Q[:Y]

# print(P, Q, R)

L = P + Q + R
L = sorted(L)[::-1]

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

Submission status: Accepted

Solution code:
## coding: UTF-8
#最後の方のテストケースでREになってしまう。時間切れ。
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

s = input().split()
t = [int(p) for p in s]


sA = input().split()
p = [int(w) for w in sA]
p.sort(reverse=True) #大きい順に並べ替える


sB = input().split()
q = [int(p) for p in sB]
q.sort(reverse=True)

sC = input().split()
r = [int(p) for p in sC]
r.sort(reverse=True)

X = t[0]
Y = t[1]
A = t[2]
B = t[3]
C = t[4]
p = p[:X] #下の方はいらない子
q = q[:Y] #下の方はいらない子
r = r[:X+Y] #下の方はいらない子だけど、全部無色の可能性もある。
#print('{} {} {} {} {}'.format(X,Y,A,B,C))
#print(p)
#print(q)
#print(r)

def delete_min(p, q, r):
    if(len(p) == 0 and len(q) == 0):
        del r[-1]
    elif(len(p) == 0):
        if(q[-1] <= r[-1]):
            del q[-1]
        else:
            del r[-1]
    elif(len(q) == 0):
        if(p[-1] <= r[-1]):
            del p[-1]
        else:
            del r[-1]
    elif(len(r) == 0):
        if(p[-1] <= q[-1]):
            del p[-1]
        else:
            del q[-1]
    else:
        if(p[-1] <= q[-1] and p[-1] <= r[-1]):
            del p[-1]
        elif(q[-1] <= r[-1]):
            del q[-1]
        else:
            del r[-1]
    #要素数が0になることもありうるので、その回避処理が必要だった

while len(p) + len(q) + len(r) > X + Y:
    delete_min(p, q, r)
    #print('p:{}, q:{}, r:{}'.format(p,q,r))

answer = sum(p) + sum(q) + sum(r)
print(answer)

Submission status: Accepted

Solution code:
#create date: 2020-03-28 21:26

import sys
stdin = sys.stdin
import bisect

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    x, y, a, b, c = na()
    p = na()
    q = na()
    r = na()
    p.sort(reverse=True)
    q.sort(reverse=True)
    l = p[:x]
    l += q[:y]
    l += r
    l.sort(reverse=True)
    ans = sum(l[:(x+y)])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, y, a, b, c = [int(i) for i in input().split()]
pa = [int(i) for i in input().split()]
pb = [int(i) for i in input().split()]
pc = [int(i) for i in input().split()]

pa = sorted(pa, reverse=True)
pa = pa[:x]
pb = sorted(pb, reverse=True)
pb = pb[:y]
pc = sorted(pc, reverse=True)

l = pa + pb + pc
l = sorted(l, reverse=True)
l = l[:int(x+y)]
print(sum(l))

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
P = [int(x) for x in input().split()]
Q = [int(y) for y in input().split()]
R = [int(z) for z in input().split()]
P.sort(reverse = True)
Q.sort(reverse = True)
P = P[:X]
Q = Q[:Y]
apple = P + Q + R
apple.sort(reverse=True)
print(sum(apple[:X+Y]))

Submission status: Accepted

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.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)

P = p[0:X]
Q = q[0:Y]
R = r[0:X+Y]

S = P + Q + R

S.sort(reverse = True)

ans = sum(S[0:X+Y])

print(ans)

Submission status: Accepted

Solution code:
X, Y, p, q, r = list(map(int, input().split()))
P = list(sorted(list(map(int, input().split())), reverse = True))
Q = list(sorted(list(map(int, input().split())), reverse = True))
R = list(sorted(list(map(int, input().split())), reverse = True))
all_values = P[:X] + Q[:Y] + R[:X+Y]
all_values = list(sorted(all_values, reverse = True))
print(sum(all_values[:X+Y]))

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
red_apple = list(map(int, input().split()))
green_apple = list(map(int, input().split()))
transparent_apple = list(map(int, input().split()))
red_apple.sort(reverse=True)
green_apple.sort(reverse=True)
red_apple = red_apple[:X]
green_apple = green_apple[:Y]
transparent_apple.extend(red_apple)
transparent_apple.extend(green_apple)
transparent_apple.sort(reverse=True)
print(sum(transparent_apple[:X+Y]))

Submission status: Accepted

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

if x < a:
    del p[: a - x]
if y < b:
    del q[: b - y]

delicious = p[:] + q[:] + r[:]
delicious.sort(reverse=True)

cnt = 0
for i in range(x + y):
    cnt += delicious[i]
    
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s=sorted
(x,y,*_),p,q,r=eval('map(int,input().split()),'*4)
print(sum(s(s(p)[-x:]+s(q)[-y:]+s(r))[-x-y:]))

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
r = sorted([i for i in map(int,input().split())],reverse = True)[0:x]
g = sorted([i for i in map(int,input().split())],reverse = True)[0:y]
n = sorted([i for i in map(int,input().split())],reverse = True)
com = sorted(r + g + n,reverse = True)
print(sum(com[0:x + y]))

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
r = sorted([i for i in map(int,input().split())],reverse = True)
r = r[0:x]
g = sorted([i for i in map(int,input().split())],reverse = True)
g = g[0:y]
n = sorted([i for i in map(int,input().split())],reverse = True)
#print(r,g,n)
com = sorted(r + g + n,reverse = True)
print(sum(com[0:x + y]))

Submission status: Accepted

Solution code:
sel='E'

if sel=='A':
    S=input()
    if S[2]==S[3] and S[4]==S[5]:
        print('Yes')
    else:
        print('No')

if sel=='B':
    X=int(input())
    ans=0
    ans+=(X//500)*1000
    ans+=((X%500)//5)*5
    print(ans)

if sel=='C':
    K,N=map(int,input().split())
    A=[int(i) for i in input().split()]
    d=[A[0]+K-A[-1]]
    for i in range(N-1):
        d.append(A[i+1]-A[i])
    d.sort()
    print(K-d[-1])

if sel=='D':
    N,X,Y=map(int,input().split())
    cnt={}
    for k in range(1,N):
        cnt[k]=0
    for i in range(1,N):
        for j in range(i+1,N+1):
            k=j-i # まっすぐ
            k=min(k,abs(i-X)+1+abs(j-Y)) # う回路１
            k=min(k,abs(i-Y)+1+abs(X-j)) # う回路２
            cnt[k]+=1

    for k in range(1,N):
        print(cnt[k])

if sel=='E':
    import heapq
    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(reverse=True)
    Q.sort(reverse=True)
    red=P[:X]
    gre=Q[:Y]
    heapq.heapify(red)
    heapq.heapify(gre)
    for r in R:
        if red[0]<=gre[0]:
            if red[0]<r:
                heapq.heapreplace(red,r)
        else:
            if gre[0]<r:
                heapq.heapreplace(gre,r)
    print(sum(red)+sum(gre))

Submission status: Accepted

Solution code:
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = sorted(list(map(int, input().split())), reverse=True)[:na]
ab_list[na:] = sorted(list(map(int, input().split())), reverse=True)[:nb]
ab_list += sorted(list(map(int, input().split())), reverse=True)[:min(na + nb, c)]

ab_list.sort(reverse=True)

print(sum(ab_list[:na + nb]))

Submission status: Accepted

Solution code:
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
d=a-x+b-y
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))
an.sort(reverse=True)
bn.sort(reverse=True)

an=an[:x]
bn=bn[:y]

for a in an :
  cn.append(a)
for b in bn :
  cn.append(b)
cn.sort(reverse=True)
count=0
for i in range(x+y) :
  count+=cn[i]

print(count)

Submission status: Accepted

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

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt
# import decimal
import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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)
    e = p[0:x] + q[0:y] + r
    e.sort(reverse=True)
    ans = 0
    for i in range(x+y):
        ans += e[i]
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
x, y, a, b, c = [int(e) for e in input().split()]
pa = sorted([int(e) for e in input().split()], reverse=True)
pb = sorted([int(e) for e in input().split()], reverse=True)
pr = sorted([int(e) for e in input().split()], reverse=True)

print(sum(sorted(pa[:x] + pb[:y] + pr, reverse=True)[:x+y]))

Submission status: Accepted

Solution code:
inf = 10 ** 9 + 1
x, y, a, b, c = map(int, input().split())

r = [int(i) for i in input().split()] + [inf]
g = [int(i) for i in input().split()] + [inf]
m = [int(i) for i in input().split()]
r.sort()
g.sort()
m.sort(reverse=True)
i = -x-1
j = -y-1
S = 0

for k in range(c):
    if r[i] <= g[j]:
        if m[k] > r[i]:
            S += m[k]
            i += 1
        else:
            break
    else:
        if m[k] > g[j]:
            S += m[k]
            j += 1
        else:
            break

S += sum(r[i:-1]) + sum(g[j:-1])
print(S)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
pa = sorted(list(map(int, input().split())), reverse=True)
pb = sorted(list(map(int, input().split())), reverse=True)
pc = sorted(list(map(int, input().split())), reverse=True)
ans = sorted(pa[:x] + pb[:y])
for i in range(min(len(ans), len(pc))):
    if pc[i] > ans[i]:
        ans[i] = pc[i]
    else:
        break
print(sum(ans))

Submission status: Accepted

Solution code:
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 = sorted( map( int, input().split() ), reverse=True)

total = sum((sorted(p+q+r, reverse=True)[:x+y]))
print( total )

Submission status: Accepted

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()
P.reverse()
Q.reverse()

P = P[:X]
Q = Q[:Y]

eatable_apple = P+Q+R
eatable_apple.sort()
eatable_apple.reverse()

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=[0]*a
q=[0]*b
r=[0]*c
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
List=[]
newp=sorted(p,reverse=True)
newq=sorted(q,reverse=True)
for i in range(max(x,y,c)):
  if (i<x):
    List.append(newp[i])
  if (i<y):
    List.append(newq[i])
  if (i<c):
    List.append(r[i])

#print(List)
ans=sorted(List,reverse=True)
print(sum(ans[:x+y]))

Submission status: Accepted

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

red_apple = list(map(int, input().split()))
green_apple = list(map(int, input().split()))
all_apple = list(map(int, input().split()))

red_apple = sorted(red_apple, reverse=True)
green_apple = sorted(green_apple, reverse=True)

all_apple += red_apple[:X]
all_apple += green_apple[:Y]
ans = sum(sorted(all_apple)[::-1][:X+Y])
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappop,heappush
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=1)
q=list(map(int,input().split()))
q.sort(reverse=1)
r=list(map(int,input().split()))+[0]
r.sort(reverse=1)
h=[]
m=p[0]
for i in range(x):
  heappush(h,p[i])
  m=min(m,p[i])
for i in range(y):
  heappush(h,q[i])
  m=min(m,q[i])
i=0
while m<r[i]:
  _=heappop(h)
  heappush(h,r[i])
  m=heappop(h)
  heappush(h,m)
  i+=1
print(sum(h))

Submission status: Accepted

Solution code:
import sys
from heapq import heappop, heapify


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    x, y, a, b, c = map(int, input().split())
    red = [(-int(s), 'r') for s in input().split()]
    green = [(-int(s), 'g') for s in input().split()]
    colorless = [(-int(s), 'n') for s in input().split()]
    apples = red + green + colorless
    heapify(apples)
    cnt = {'r': x, 'g': y, 'n': -1}
    res = 0
    while sum(cnt.values()) + 1 and apples:
        num, clr = heappop(apples)
        if cnt[clr] == 0:
            continue
        cnt[clr] -= 1
        res -= num
    print(res)


if __name__ == "__main__":

    main()

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]

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

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

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

Submission status: Accepted

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)
pq = p[:x]+q[:y]
heapq.heapify(pq)

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))

Submission status: Accepted

Solution code:
import sys
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)

d = []
d_append = d.append
for i in range(x):
    d_append(P[i])

for i in range(y):
    d_append(Q[i])

for i in range(c):
    d_append(R[i])

d.sort(reverse=True)

ans = 0
for i in range(x+y):
    ans += d[i]
    
print(ans)

Submission status: Accepted

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

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

ans=[]
ans.append(p[:X])
ans.append(q[:Y])
ans.append(r)
ans=sum(ans,[])
ans.sort(reverse=True)
ans=ans[:X+Y]
print(sum(ans))

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
n = a+b+c
ar = list(map(int,input().split()))
br = list(map(int,input().split()))
cr = list(map(int,input().split()))
ls = []
for i in ar:
  ls.append([i,1])
for i in br:
  ls.append([i,2])
for i in cr:
  ls.append([i,3])
ls.sort(reverse = True)
nx = 0
ny = 0
cnt = 0
res = 0
for item in ls:
  if item[1]==1:
    if nx==x: continue
    nx+=1
  if item[1]==2:
    if ny==y: continue
    ny+=1
  res+=item[0]
  cnt+=1
  if cnt==x+y:
    break
print(res)

Submission status: Accepted

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()]
from collections import deque
P_sort = sorted(P,reverse=True)[0:X]
Q_sort = sorted(Q,reverse=True)[0:Y]
R_sort = deque(sorted(R,reverse=True)[0:X+Y])
PQ = sorted(P_sort + Q_sort)
for i in range(len(PQ)):
    if R_sort[0] > PQ[i]:
        r = R_sort.popleft()
        PQ[i] = r
    if not R_sort:
      break
print(sum(PQ))

Submission status: Accepted

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pp = sorted(pl,reverse=True)[:x]
qq = sorted(ql,reverse=True)[:y]
al = pp + qq + rl
#print(al,pp,qq,rl)
print(sum(sorted(al,reverse=True)[:x+y]))

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if len(aX) == 0 and len(aY) == 0:
        break
    if len(aX) == 0:
        if s <= aY[-1]:
            break
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        if s <= aX[-1]:
            break
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()

print(sumX + sumY)

Submission status: Accepted

Solution code:
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i] <= right[r_i]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged

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()))
PP=merge_sort(P)
QQ=merge_sort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=merge_sort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)

Submission status: Accepted

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

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

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

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

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