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

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

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

Submission status: Accepted

Solution code:
(x,y,a,b,c),p,q,r=[[*map(int,i.split())]for i in open(0)]
print(sum(sorted(sorted(p)[-x:]+sorted(q)[-y:]+r)[-x-y:]))

Submission status: Accepted

Solution code:
def main():
    import heapq
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())),reverse=True)[0:x]
    q = sorted(list(map(int,input().split())),reverse=True)[0:y]
    r = sorted(list(map(int,input().split())),reverse=True)
    P,Q = [],[]
    for i in range(x):
        heapq.heappush(P,p[i])
    for i in range(y):
        heapq.heappush(Q,q[i])
    for i in range(c):
        p,q = heapq.heappop(P), heapq.heappop(Q)
        if p>q:
            heapq.heappush(P,p)
            if r[i]>q:
                heapq.heappush(Q,r[i])
            else:
                heapq.heappush(Q,q)
        else:
            heapq.heappush(Q,q)
            if r[i]>p:
                heapq.heappush(P,r[i])
            else:
                heapq.heappush(P,p)
    print(sum(P)+sum(Q))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
(x,y,a,b,c),p,q,r=[[*map(int,i.split())]for i in open(0)]
p=sorted(p)[-x:]
q=sorted(q)[-y:]
pq = sorted(p+q)
r.sort(reverse=True)
ans = sum(pq)
for i in range(min(c,x+y)):
    if r[i] > pq[i]:
        ans += r[i] - pq[i]
    else:
        break
print(ans)

Submission status: Accepted

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

    p = p[:X]
    q = q[:Y]
    s = p + q
    s.sort()

    rtmp = r.pop()
    for i in range(len(s)):
        if s[i] < rtmp:
            s[i] = rtmp
            if len(r) == 0:
                break
            rtmp = r.pop()
        else:
            break
    ans = sum(s)
    print(ans)


if __name__ == "__main__":
    main()

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)

PQ = sorted(P+Q)
ans = sum(PQ)
for r, pq in zip(R, PQ):
    if r > pq:
        ans += r - pq
print(ans)

Submission status: Accepted

Solution code:
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)
    Pmax=P[:X]
    Qmax=Q[:Y]

    Pmax.extend(Qmax)
    Pmax.extend(R)
    Pmax.sort(reverse=True)
    res=0
    for i in range(X+Y):
        res+=Pmax[i]

    print(res)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[::-1][:x]
q=sorted(list(map(int,input().split())))[::-1][:y]
r=sorted(list(map(int,input().split())))[::-1]
r=r[:min(len(r),x+y)]
l=sum([p,q,r],[])
print(sum(sorted(l)[::-1][: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()))
s = sorted(p)[::-1][:X] + sorted(q)[::-1][:Y] + r
s = sorted(s)[::-1]
ans = sum(s[:X + Y])
print(ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
rs = [int(i) for i in input().split()]
gs = [int(i) for i in input().split()]
ws = [int(i) for i in input().split()]

rs.sort(reverse=True)
gs.sort(reverse=True)
ws.sort(reverse=True)
weight = 0
rs = rs[:x]
rs = [0] + rs
gs = gs[:y]
gs = [0] + gs
ws = [0] + ws
r = 0
g = 0
w = 0
while r + g + w < x + y:
  if r < x:
    w1 = weight + rs[r + 1]
  else:
    w1 = 0
  if g < y:
    w2 = weight + gs[g + 1]
  else:
    w2 = 0
  if w < c:
    w3 = weight + ws[w + 1]
  else:
    w3 = 0
  weight = max(w1, w2, w3)
  if weight == w1:
    r += 1
  elif weight == w2:
    g += 1
  elif weight == w3:
    w += 1
print(weight)

Submission status: Accepted

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
ls = []
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
lc = list(map(int,input().split()))
la.sort(reverse=True)
lb.sort(reverse=True)
lc.sort(reverse=True)
for i in range(a):
    ls.append([la[i],1])
for j in range(b):
    ls.append([lb[j],2])
for l in range(c):
    ls.append([lc[l],3])
ls.sort(key=lambda x:x[0],reverse=True)
ls = deque(ls)
s,t,k = 0,0,0
cnt = 0
while True:
    now = ls.popleft()
    if now[1] == 1:
        if s < x:
            cnt += now[0]
            s += 1
    elif now[1] == 2:
        if t < y:
            cnt += now[0]
            t += 1
    else:
        cnt += now[0]
        k += 1
    if s + t + k == x + y:
        print(cnt)
        break

Submission status: Accepted

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

Al = Ps[:X] + Qs[:Y] +Rs
Al.sort(reverse=True)

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

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)

pq = sorted(P[:X] + Q[:Y])
cnt = 0
for i in range(min(C, X+Y)):
    if R[i] <= pq[i]: 
        break
    cnt += 1

ans = sum(pq[cnt:]) + sum(R[:cnt])

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

pq = sorted(p[:x] + q[:y])
r = sorted(r)
ans=0
j = r.pop()
for i in pq:
  if i < j:
    ans += j
    j = 0
    if r:
      j = r.pop()
  else:
    ans += i
    
print(ans)

Submission status: Accepted

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.sort()
B.sort()
C.sort()

ans = 0
if X < a:
    A = A[a-X:]
if Y < b:
    B = B[b-Y:]
ans = 0
for i in range(X+Y):
    if len(A) == 0:
        A.append(0)
    if len(B) == 0:
        B.append(0)
    if len(C) == 0:
        C.append(0)
    if max(A[-1],B[-1],C[-1]) == A[-1]:
        ans += A[-1]
        A.pop()
    elif max(A[-1],B[-1],C[-1]) == B[-1]:
        ans += B[-1]
        B.pop()
    else:
        ans += C[-1]
        C.pop()
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=sorted(list(map(int,input().split())),reverse=True)
all=sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(all[: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()
cand = P[-X:] + Q[-Y:] + R
cand.sort()
print(sum(cand[-(X + Y):]))

Submission status: Accepted

Solution code:
import sys,math,collections,itertools,heapq
input = sys.stdin.readline
def f(n):
    return -1*int(n)

x,y,a,b,c=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=1)[:x]
q=sorted(list(map(int,input().split())),reverse=1)[:y]
r=list(map(f,input().split()))

p = collections.deque(p)
q = collections.deque(q)
heapq.heapify(r)

tmp = -1*heapq.heappop(r)
while tmp > p[-1]:
    p.appendleft(tmp)
    tmp = p.pop()
    tmp = -1* heapq.heappushpop(r,-1*tmp)

while tmp > q[-1]:
    q.appendleft(tmp)
    tmp = q.pop()
    tmp = -1 * heapq.heappushpop(r,-1*tmp)

print(sum(p)+sum(q))

Submission status: Accepted

Solution code:
from collections import *
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=True)
q=list(map(int,input().split()))
q.sort(reverse=True)
r=list(map(int,input().split()))
r.sort(reverse=True)
r=r+p[:x]+q[:y]
r.sort(reverse=True)
r=r[:x+y]
print(sum(r))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    x, y, a, b, c = getList()
    anums = getList()
    bnums = getList()
    cnums = getList()
    q = []
    anums.sort(key=lambda x: -x)
    bnums.sort(key=lambda x: -x)
    cnums.sort(key=lambda x: -x)
    for i, num in enumerate(anums):
        if i == x:
            break
        heapq.heappush(q, -num)
    for i, num in enumerate(bnums):
        if i == y:
            break
        heapq.heappush(q, -num)

    for i, num in enumerate(cnums):
        # if i == b:
        #     break
        heapq.heappush(q, -num)

    ans = 0
    for i in range(x + y):
        ans += heapq.heappop(q)

    print(-ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


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

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)

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x,y,a,b,c = inpm()
p = list(reversed(sorted(inpl())))
q = list(reversed(sorted(inpl())))
r = list(reversed(sorted(inpl())))
pp = x-1
qq = y-1
rr = 0

tmp = []
tmp.extend(p[:pp+1])
tmp.extend(q[:qq+1])
tmp.extend(r)

tmp = list(reversed(sorted(tmp)))
ans = sum(tmp[:x+y])
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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=[10**10]+p[:x]
    q=[10**10]+q[:y]
    r+=[0]*(a+b)
    ans=sum(p)+sum(q)-2*10**10
    pcnt,qcnt=0,0
    for i in range(x+y):
        if p[-1-pcnt] >= r[i] and q[-1-qcnt] >= r[i]:
            break
        elif p[-1-pcnt] > q[-1-qcnt]:
            ans += -q[-1-qcnt] + r[i]
            qcnt +=1
        else:
            ans += -p[-1-pcnt] + r[i]
            pcnt +=1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)[0:x]
    q = sorted(list(map(int, input().split())), reverse=True)[0:y]
    r = sorted(list(map(int, input().split())), reverse=True)
    pq = sorted((p + q))
    for i in range(min(c, (x + y))):
        if pq[i] > r[i]:
            break
        pq[i] = r[i]
    print(sum(pq))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
p_l = sorted(list(map(int, input().split())), reverse=True)[:x]
q_l = sorted(list(map(int, input().split())), reverse=True)[:y]
r_l = list(map(int, input().split()))
p_l = sorted(p_l + q_l + r_l, reverse=True)

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

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
p = sorted([int(x) for x in input().split()])[::-1][:x]
q = sorted([int(x) for x in input().split()])[::-1][:y]
r = [int(x) for x in input().split()]
row = sorted(p+q+r)[::-1]
print(sum(row[:x+y]))

Submission status: Accepted

Solution code:
import sys
import itertools

def main():
  x, y, a, b, c = map(int, sys.stdin.buffer.readline().split())
  red = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  green = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  colorless = sorted(map(int, sys.stdin.buffer.readline().split()), reverse=True)
  
  apples = sorted(itertools.chain(red[:x], green[:y], colorless), reverse=True)
  print(sum(apples[:x + y]))

main()

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)
r.sort(reverse=True)
S=[]
T=[]
for i in range(X):
    heapq.heappush(S,-p[i])
for i in range(Y):
    heapq.heappush(S,-q[i])
for i in range(C):
    heapq.heappush(T,-r[i])
ans=0
for i in range(X+Y):
    if len(T)>0:
        if S[0]<T[0]:
            ans+=heapq.heappop(S)
        else:
            ans+=heapq.heappop(T)
    else:
        ans+=heapq.heappop(S)
print(-ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int,input().split())
datp = sorted(list(map(int, input().split())), reverse=True)
datq = sorted(list(map(int, input().split())), reverse=True)
datr = list(map(int, input().split()))
dat = sorted(datp[:x] + datq[:y] + datr, reverse=True)
print(sum(dat[: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, reverse=True)
q = sorted(q, reverse=True)
new_arr = p[:X] + q[:Y] + r
new_arr = sorted(new_arr, reverse=True)
print(sum(new_arr[: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(reverse = 1)
p.append(-1)
pc = 0
q.sort(reverse = 1)
q.append(-1)
qc = 0
r.sort(reverse = 1)
r.append(-1)
rc = 0
count = x + y
ans = 0
while count > 0:
    if x > 0 and y > 0:
        if max(p[pc], max(q[qc], r[rc])) == p[pc]:
            ans += p[pc]
            x -= 1
            count -= 1
            pc += 1
        elif max(q[qc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += q[qc]
            qc += 1
            count -= 1
            y -= 1
    elif y > 0:
        if max(q[qc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += q[qc]
            qc += 1
            count -= 1
            y -= 1
    elif x > 0:
        if max(p[pc], r[rc]) == r[rc]:
            ans += r[rc]
            rc += 1
            count -= 1
        else:
            ans += p[pc]
            pc += 1
            count -= 1
            x -= 1
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()
Q.sort()
R.sort()

P_new = P[-X::]
Q_new = Q[-Y::]


agg = P_new + Q_new +R
agg.sort()
print(sum(agg[-X-Y::]))

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce


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

p = sorted(p, reverse=True)[:x]
q = sorted(q, reverse=True)[:y]
r = sorted(r, reverse=True)

pq = sorted(p+q)
ans = sum(pq)

for i in range(len(r)):
    if pq[i] < r[i]:
        ans = ans + r[i] -pq[i]
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
must_red, must_green, a,b,c = map(int,input().split())
delicious_red_ls = list(map(int, input().split()))
delicious_green_ls = list(map(int, input().split()))
delicious_free_ls = list(map(int, input().split()))
delicious_red_ls.sort(reverse=True)
delicious_green_ls.sort(reverse=True)
first_red = delicious_red_ls[:must_red]
first_green = delicious_green_ls[:must_green]
first_set = first_green + first_red
first_set.sort()
delicious_free_ls.sort()

while delicious_free_ls:
    to_be_erased = heapq.heappop(first_set)
    erase = delicious_free_ls[-1]
    if to_be_erased < erase:
        new = delicious_free_ls.pop()
        heapq.heappush(first_set, new)
    else:
        heapq.heappush(first_set, to_be_erased)
        break
print(sum(first_set))

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

ALL = p + q + r
ALL.sort(reverse=True)
ALL = deque(ALL)

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

p = deque(p)
q = deque(q)
r = deque(r)

ans = 0
p_cnt = 0
q_cnt = 0
r_cnt = 0
loopcnt = 0
while loopcnt < X+Y:
    apple = ALL.popleft()
    if p_cnt < X and apple == p[0]:
        ans += p.popleft()
        p_cnt += 1
        loopcnt += 1
    elif q_cnt < Y and apple == q[0]:
        ans += q.popleft()
        q_cnt += 1
        loopcnt += 1
    elif r_cnt < C and apple == r[0]:
        ans += r.popleft()
        r_cnt += 1
        loopcnt += 1
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 = sorted(list(map(int, input().split())), reverse=True)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    red_worst = red[-red_no_eat - 1] if red_no_eat < X else 10 ** 10
    green_worst = green[-green_no_eat - 1] if green_no_eat < Y else 10 ** 10
    if no > red_worst or no > green_worst:
        if red_worst < green_worst:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

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

x_tmp = P[:x]
y_tmp = Q[:y]

tmp_li = x_tmp+y_tmp
heapq.heapify(tmp_li)

for i in range(c):
    if R[i]>tmp_li[0]:
        heapq.heapreplace(tmp_li,R[i])
print(sum(tmp_li))

Submission status: Accepted

Solution code:
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    X, Y, A, B, C = map(int, input().split())
    P = sorted(list(map(int, input().split())), reverse=True)[:X]
    Q = sorted(list(map(int, input().split())), reverse=True)[:Y]
    R = sorted(list(map(int, input().split())), reverse=True)
    L = sorted(P + Q + R, reverse=True)
    res = sum(L[:X + Y])
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import heapq
import sys
X, Y, A, B, C = map(int, input().split())
Av = list(map(int, input().split()))
Bv = list(map(int, input().split()))
Cv = list(map(int, input().split()))
heapq.heapify(Av)
heapq.heapify(Bv)
heapq.heapify(Cv)
for i in range(A-X):
    heapq.heappop(Av)
for i in range(B-Y):
    heapq.heappop(Bv)
if C > X+Y:
    for i in range(C-(X+Y)):
        heapq.heappop(Cv)
    NotTake = X+Y
else:
    NotTake = C
total = X+Y
C = NotTake
for _ in range(NotTake):
    Amin = heapq.heappop(Av)
    Bmin = heapq.heappop(Bv)
    Cmin = heapq.heappop(Cv)
    if X > 0 and Amin == min(Amin, Bmin, Cmin):
        heapq.heappush(Bv, Bmin)
        heapq.heappush(Cv, Cmin)
        X -= 1
    elif Y > 0 and Bmin == min(Bmin, Cmin):
        heapq.heappush(Av, Amin)
        heapq.heappush(Cv, Cmin)
        Y -= 1
    elif C > 0:
        heapq.heappush(Av, Amin)
        heapq.heappush(Bv, Bmin)
        C -= 1
    if X == 0 or Y == 0 or C == 0:
        break
NotTake = X+Y+C-total
if X == 0:
    Iv = Bv
    Jv = Cv
    I = Y
    J = C
elif Y == 0:
    Iv = Av
    Jv = Cv
    I = X
    J = C
else:
    print(sum(Av)+sum(Bv)+sum(Cv))
    sys.exit()

for _ in range(NotTake):
    Imin = heapq.heappop(Iv)
    Jmin = heapq.heappop(Jv)
    if I > 0 and Imin == min(Imin, Jmin):
        heapq.heappush(Jv, Jmin)
        I -= 1
    elif J > 0:
        heapq.heappush(Iv, Imin)
        J -= 1
    if J == 0 or I == 0:
        break

print(sum(Av)+sum(Bv)+sum(Cv))

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)

s = p[:x] + q[:y]
s.sort()
ans = sum(s)
for si, ri in zip(s, r):
    if si < ri:
        ans += ri - si

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

ans = p[-x:].sum()+q[-y:].sum()

p_cnt = 0
q_cnt = 0
r_cnt = 0
while not(-x+p_cnt == 0 and -y+q_cnt == 0) and -1-r_cnt >= -c:
  if -x+p_cnt == 0:
    if r[-1-r_cnt] > q[-y+q_cnt]:
      ans += r[-1-r_cnt] - q[-y+q_cnt]
      q_cnt += 1
      r_cnt += 1
    else:
      break
  
  elif -y+q_cnt == 0:
    if r[-1-r_cnt] > p[-x+p_cnt]:
      ans += r[-1-r_cnt] - p[-x+p_cnt]
      p_cnt += 1
      r_cnt += 1
    else:
      break

  elif p[-x+p_cnt] <= q[-y+q_cnt] and r[-1-r_cnt] > p[-x+p_cnt]:
    ans += r[-1-r_cnt] - p[-x+p_cnt]
    p_cnt += 1
    r_cnt += 1

  elif p[-x+p_cnt] > q[-y+q_cnt] and r[-1-r_cnt] > q[-y+q_cnt]:
    ans += r[-1-r_cnt] - q[-y+q_cnt]
    q_cnt += 1
    r_cnt += 1

  else:
    break

print(ans)

Submission status: Accepted

Solution code:
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())))[::-1]

i=j=k=0
oi=0
while i<c:
  if x>j and y>k:
    if p[j]>=q[k] and q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
    elif p[j]<q[k] and p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif x>j:
    if p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif y>k:
    if q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
  if oi==i:break
  oi=i

print(sum(p)+sum(q))

Submission status: Accepted

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

p.append(0)
q.append(0)
r.append(0)
for i in range(X,A):
    p[i] = 0
for i in range(Y,B):
    q[i] = 0

a = 0
b = 0
c = 0
cnt = 0

for i in range(X+Y):
    if (not a == X) and p[a] >= q[b] and p[a] >= r[c]:
        cnt += p[a]
        a += 1
    elif (not b == Y) and q[b] >= r[c]:
        cnt += q[b]
        b += 1
    else:
        cnt += r[c]
        c += 1
print(cnt)

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)
r.sort()
apples = p[:x] + q[:y]
heapq.heapify(apples)
while r:
    val = r.pop()
    apple = heapq.heappop(apples)
    if apple>= val:
        heapq.heappush(apples,apple)
        break
    else:
        heapq.heappush(apples,val)
print(sum(apples))

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)

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

Submission status: Accepted

Solution code:

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

cand = sorted(P[-X:] + Q[-Y:] + R)
print(sum(cand[-X-Y:]))

Submission status: Accepted

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

P = sorted(list(map(int, input().split(' '))), reverse=True)[:X]
Q = sorted(list(map(int, input().split(' '))), reverse=True)[:Y]
R = sorted(list(map(int, input().split(' '))), reverse=True)

apples = sorted(P + Q + R, reverse=True)[:X + Y]

print(sum(apples))

Submission status: Accepted

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

apples = []
for p in map(int, input().split(' ')):
    apples.append((p, 0))

for q in map(int, input().split(' ')):
    apples.append((q, 1))

for r in map(int, input().split(' ')):
    apples.append((r, 2))

apples.sort(reverse=True)

pq = []
r = []
x = X
y = Y

for d, t in apples:
    if t == 0:
        if x > 0:
            x -= 1
            pq.append(d)
        else:
            continue
    elif t == 1:
        if y > 0:
            y -= 1
            pq.append(d)
        else:
            continue
    else:
        r.append(d)

pq_len = len(pq)
for i in range(len(r)):
    if i >= pq_len:
        break

    if r[i] <= pq[-(i + 1)]:
        break

    pq[-(i + 1)] = r[i]

print(sum(pq))

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)

red = p[:X]
green = q[:Y]

all_apple = red+green+r
all_apple.sort(reverse=True)

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

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
list_A.sort(reverse=True)
list_B.sort(reverse=True)
list_C.sort(reverse=True)

list_N = list_A[:x] + list_B[:y] + list_C[:min(c, x + y)]
list_N.sort(reverse=True)
print(sum(list_N[: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(reverse=True); Q.sort(reverse=True)
print(sum(sorted(P[:x]+Q[:y]+R, reverse=True)[:x+y]))