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

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

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

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
cr = list(map(int,input().split(" ")))
ar = sorted(ar,reverse=True)
br = sorted(br,reverse=True)
ar = ar[0:x]
br = br[0:y]
ar = ar + br + cr
ar = sorted(ar,reverse=True)
count = 0
for i in range(x+y):
    count += ar[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)

ans = []
ans.extend(p[:x])
ans.extend(q[:y])
from heapq import *
heapify(ans)

r = [-i for i in r]
heapify(r)


while True:
    a = heappop(ans)
    b = -heappop(r)
    if a < b:
        heappush(ans, b)
        heappush(r, -a)
    else:
        heappush(ans, a)
        break

print(sum(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 = list(map(int, input().split()))
print(sum(sorted(p + q + r)[-(X + Y):]))

Submission status: Accepted

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

R.sort()
R.reverse()
G.sort()
G.reverse()
C.sort()
C.reverse()

R = R[:X]
G = G[:Y]

temp = 0
  
for i in range(len(C)) :
  if((X==0) and (Y==0)) :
    i = i-1
    break
  if(X==0) :
    last = G[Y-1]
    Y -= 1
    
  else :
    if(Y==0) :
      last = R[X-1]
      X -= 1
    else :
      if(R[X-1] < G[Y-1]) :
        last = R[X-1]
        X -= 1
      else :
        last = G[Y-1]
        Y -= 1

  if(C[i] < last) :
      break
  else :
    last = C[i]
    
print(sum(R[:X])+sum(G[:Y])+sum(C[:i])+last)

Submission status: Accepted

Solution code:
import queue

def main():
    A = list(map(int,input().split()))
    pt = list(map(int,input().split()))
    qt = list(map(int,input().split()))
    rt = list(map(int,input().split()))

    ans = 0

    pt.sort(reverse=True)
    qt.sort(reverse=True)
    rt.sort()

    p = queue.LifoQueue()
    q = queue.LifoQueue()
    r = queue.LifoQueue()

    for i in range(A[0]):
        ans += pt[i]
        p.put(pt[i])
    for i in range(A[1]):
        ans += qt[i]
        q.put(qt[i])
    for i in range(A[4]):
        r.put(rt[i])

    while (not p.empty() or not q.empty()) and not r.empty():
        items = [10**9+1,10**9+1,0]
        if not p.empty():
            items[0] = p.get()
        if not q.empty():
            items[1] = q.get()
        items[2] = r.get()

        mini = items.index(min(items))

        if mini == 0:
            ans = ans - items[0] + items[2]
            q.put(items[1])
        elif mini == 1:
            ans = ans - items[1] + items[2]
            p.put(items[0])
        else:
            break

    print(ans)

main()

Submission status: Accepted

Solution code:
x,y,a,b,c = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:x]
q = sorted([int(x) for x in input().split()], reverse=True)[:y]
r = sorted([int(x) for x in input().split()])
print(sum(sorted(p + q + 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())); P.sort(); P.reverse()
Q = list(map(int, input().split())); Q.sort(); Q.reverse()
R = list(map(int, input().split())); R.sort(); R.reverse()

ans = P[:x] + Q[:y] + R
ans.sort(); ans.reverse()
ans = ans[:(x + y)]

print (sum(ans))

Submission status: Accepted

Solution code:
def main():
    X, Y, A, B, C = tuple(map(int, input().split()))
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    R = tuple(map(int, input().split()))

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

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

    saikyo = sorted(x + y + R, reverse=True)
    print(sum(saikyo[:(X + Y)]))


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

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X + Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[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()
q.sort()
nums=p[-X:]+q[-Y:]+r
nums.sort()
print(sum(nums[-(X+Y):]))

Submission status: Accepted

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

parr.sort(reverse=True)
qarr.sort(reverse=True)
rarr.sort(reverse=True)
parr = parr[:x]
qarr = qarr[:y]
arr = parr + qarr + rarr
arr.sort(reverse=True)
print(sum(arr[:x+y]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import heapq

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

def label(lis,num):
    temp=[]
    for i in range(len(lis)):
        temp.append([lis[i],num])
    return temp

Red=label(list(map(lambda x:int(x)*-1,input().split())),1)
Green=label(list(map(lambda x:int(x)*-1,input().split())),2)
White=label(list(map(lambda x:int(x)*-1,input().split())),0)

App=Red+Green+White

heapq.heapify(App)

a,b,c=X,Y,0
ans=0
while a+b!=c:
    score,color=heapq.heappop(App)
    if color==1 and a>0:
        ans-=score
        a-=1
    elif color==2 and b>0:
        ans-=score
        b-=1
    elif color==0:
        ans-=score
        c+=1
print(ans)
#print(App)

Submission status: Accepted

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

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

pool = pool[:x + y]
ans = sum(pool)
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()

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

for i in range(min(len(ans), len(r))):
    R = r.pop()
    if ans[i]<=R:
        ans[i]=R
    else:
        break
print(sum(ans))

Submission status: Accepted

Solution code:
import numpy as np

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

p.partition(A - X)
q.partition(B - Y)

pqr = np.concatenate((p[-X:], q[-Y:], r))
pqr.partition(len(pqr) - (X + Y))

ans = sum(pqr[-(X + Y) :])

print(ans)

Submission status: Accepted

Solution code:
def merge(A,B):
    C = []
    i = 0
    j = 0
    while i < len(A) and j < len(B):
        if A[i]>B[j]:
            C.append(A[i])
            i += 1
        else:
            C.append(B[j])
            j += 1

    if len(A)-i>len(B)-j:
        C.extend(A[i:])
    else:
        C.extend(B[j:])

    return C

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 = [3,63,12,5,6]
# Q = [3,5,6,7,8]
# R = [13,5,6,8,23,5]
# X = 3
# Y = 2

# P = [63,12,6]
# Q = [8,7]

# i = 2
# j = 2
# C = [63,12,8,7]


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

S = merge(P[:X],Q[:Y])
S = merge(S,R)

score = 0
for i in range(X+Y):
    score += S[i]
print(score)

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)
pp = p[:x]
qq = q[:y]
pq = pp+qq
heapq.heapify(pq)
for rr in r:
    mn = heapq.heappop(pq)
    heapq.heappush(pq, max(mn, rr))
print(sum(pq))

Submission status: Accepted

Solution code:
import numpy as np

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

p = np.partition(p, A - X)
q = np.partition(q, B - Y)

pqr = np.concatenate((p[-X:], q[-Y:], r))
pqr = np.partition(pqr, len(pqr) - (X + Y))

ans = sum(pqr[-(X + Y) :])

print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    x,y,a,b,c = map(int,input().strip().split())
    p = list(map(lambda x : (int(x),0), input().strip().split())) 
    q = list(map(lambda x : (int(x),1), input().strip().split())) 
    r = list(map(lambda x : (int(x),2), input().strip().split())) 
    l = sorted((p+q+r),reverse=True)
    
    # eprint('l ',end=':\n')
    # eprint(l)
    
    n=x+y
    ans=0
    for i in range(len(l)):
        if n==0:
            break

        if (l[i][1]==0 and x==0) or (l[i][1]==1 and y==0):
            continue
        else:
            ans+=l[i][0]
            n-=1
            if l[i][1]==0:
                x = max(x-1,0)
            if l[i][1]==1:
                y = max(y-1,0)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
p,q,r = [sorted(map(int,input().split()),reverse=True) for i in range(3)]
ans = 0
pp,qq = [p[i] for i in range(X)] ,[q[i] for i in range(Y)]
r = r + pp + qq
r = sorted(r,reverse=True)
for i in range(X+Y):
    ans += r[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)
del p[x:]
del q[y:]
t = p + q + r
t.sort(reverse = True)
del t[(x + y):]
print(sum(t))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

t = p + q + r

t.sort(reverse=True)
print(sum(t[0:x + y]))

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
p_a = list(map(int,input().split()))
p_b = list(map(int,input().split()))
p_c = list(map(int,input().split()))
p_a.sort(reverse=True)
p_b.sort(reverse=True)
#p_c.sort(reverse=True)

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

d=[]
for i in range(x):
    d.append(p2[i])
for i in range(y):
    d.append(q2[i])
for i in r2:
    d.append(i)
e=sorted(d,reverse=True)
f=0
for i in range(x+y):
    f+=e[i]
print(f)

Submission status: Accepted

Solution code:
from collections import deque


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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
p.append(10**9)
q.append(10**9)
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
if i==x:
  p1=0
else:
  p1=sum(p[i:x])
if j==y:
  q1=0
else:
  q1=sum(q[j:y])
print(ans+p1+q1)

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 = sorted(list(map(int, input().split())))
 
ans = p[-x:] + q[-y:] + sorted(r)

print(str(sum(sorted(ans)[-x-y:])))

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

filt_p = p[-x:]
filt_q = q[-y:]
filt_p.extend(filt_q)
filt_p.extend(r)
all_apples = sorted(filt_p)

ans = sum(all_apples[-x-y:])

print(str(ans))

Submission status: Accepted

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

filt_p = p[-x:]
filt_q = q[-y:]
filt_p.extend(filt_q)
filt_p.extend(r)
all_apples = sorted(filt_p)

ans = np.sum(np.array(all_apples)[-x-y:])

print(str(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)
ls = []
for i in range(X):
    ls.append(p[i])
for i in range(Y):
    ls.append(q[i])
ls.extend(r)
ls.sort(reverse = True)
print(sum(ls[:X+Y]))

Submission status: Accepted

Solution code:
L = [input() for i in range(4)]
X, Y, A, B, C = map(int, L[0].split())
p = list(map(int, L[1].split()))
q = list(map(int, L[2].split()))
r = list(map(int, L[3].split()))

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

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

s = p + q + r
# print(p)

s = sorted(s, reverse=True)

s = s[:X+Y]

print(sum(s))

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)
 
colored_p = []
colored_q = []
 
for i in r:
    p_min = p[len(p) - 1] if len(p) > 0 else colored_p[len(colored_p) - 1]
    q_min = q[len(q) - 1] if len(q) > 0 else colored_q[len(colored_q) - 1]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        if len(p) > 0:
            p.pop()
        colored_p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        if len(q) > 0:
            q.pop()
        colored_q.append(i)
 
print(sum(p) + sum(q) + sum(colored_p) + sum(colored_q))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
x, y, a, b, c = map(int, input().split()) # 入力が複数

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

reds = reds[:x]
greens = greens[:y]

apples = sorted(reds + greens + whites, reverse=True)
ans = sum(apples[:x + y])
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()))
import heapq
h=[]

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

from collections import deque
r=deque(r)
while True:
    k=heapq.heappop(h)
    m=r.popleft()
    if k>m:
        heapq.heappush(h,k)
        break
    else:
        heapq.heappush(h,m)
    if not h or not r:
        break
print(sum(h))

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(); q.sort(); r.sort();
p.reverse(); q.reverse(); r.reverse();
ans = [sum(p[:X]) + sum(q[:Y])]
que = []
for pi in p[:X]:
    heapq.heappush(que, pi)
for qi in q[:Y]:
    heapq.heappush(que, qi)

for i in range(min(C, X + Y)):
    minimum = heapq.heappop(que)
    ans.append(ans[-1] - minimum + r[i])

print(max(ans))

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)
print(sum(sorted(P+Q+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 = sorted(p)[-x:]
q = sorted(q)[-y:]

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

Submission status: Accepted

Solution code:
import heapq

def main():
    x, y, a, b, c = [int(x) for x in input().split(" ")]
    red = [int(x) for x in input().split(" ")]
    green = [int(x) for x in input().split(" ")]
    white = [int(x) for x in input().split(" ")]

    red.sort(reverse=True)
    green.sort(reverse=True)
    white.sort(reverse=True)

    red1 = red[:x]
    green1 = green[:y]

    heapq.heapify(red1)
    heapq.heapify(green1)

    ans = sum(red1) + sum(green1)
    #print(ans)
    i = 0

    while(i < c and (white[i] > red1[0] or white[i] > green1[0])):
        #print("%d %d %d" % (white[i], red1[0], green1[0]))
        if red1[0] < green1[0]:
            removed = heapq.heappop(red1)
            ans += white[i] - removed
            heapq.heappush(red1, white[i])
        else:
            removed = heapq.heappop(green1)
            ans += white[i] - removed
            heapq.heappush(green1, white[i])
        i += 1

    print(ans)


main()

Submission status: Accepted

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

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = list(sorted(p_list, reverse=True))
q_list = list(sorted(q_list, reverse=True))
# r_list = sorted(r_list, reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]

all_list = p_list + q_list + r_list
all_list = list(sorted(all_list, reverse=True))
total = sum(all_list[: X + Y])


ans = total
print(ans)

Submission status: Accepted

Solution code:
from heapq import *

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)

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

heapify(p2)
heapify(q2)

for i in range(c):
    if r[i] <= p2[0] and r[i] <= q2[0]:
        break

    if p2[0] < q2[0]:
        heappop(p2)
        heappush(p2, r[i])
    else:
        heappop(q2)
        heappush(q2, r[i])

print(sum(p2) + sum(q2))

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] + R
S.sort(reverse=True)
ans = sum(S[:X+Y])

print(ans)

Submission status: Accepted

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

def main():
    x, y, a, b, c = map(int, input().split())
    p = map(int, input().split())
    q = map(int, input().split())
    r = list(map(int, input().split()))
    p = list(reversed(sorted(p)))[:x]
    q = list(reversed(sorted(q)))[:y]
    pqr = list(reversed(sorted(p + q + r)))[:x + y]
    print(sum(pqr))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    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 = list(reversed(sorted(p)))[:x]
    q = list(reversed(sorted(q)))[:y]
    pq = sorted(p + q)
    r = list(reversed(sorted(r)))
    for i in range(min(len(pq), len(r))):
        pq[i] = max(pq[i], r[i])
    print(sum(pq))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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 = list(reversed(sorted(p)))[:x]
    q = list(reversed(sorted(q)))[:y]
    pq = sorted(p + q)
    r = list(reversed(sorted(r)))
    for i in range(min(len(pq), len(r))):
        pq[i] = max(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=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]

z=p+q+r

z.sort(reverse=True)

tot=sum(z[:X+Y])

print(tot)

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)

tot=sum(p[:X])+sum(q[:Y])

a=0
b=0
for i in r:
    if a==X and b==Y:
        break
    elif a==X:
        if i>q[Y-b-1]:
            tot+=i-q[Y-b-1]
            b+=1
        else:
            break
    elif b==Y:
        if i>p[X-a-1]:
            tot+=i-p[X-a-1]
            a+=1
        else:
            break
    else:
        if i>p[X-a-1] and i>q[Y-b-1]:
            if p[X-a-1]<q[Y-b-1]:
                tot+=i-p[X-a-1]
                a+=1
            else:
                tot+=i-q[Y-b-1]
                b+=1
        elif i>p[X-a-1]:
            tot+=i-p[X-a-1]
            a+=1
        elif i>q[Y-b-1]:
            tot+=i-q[Y-b-1]
            b+=1
        else:
            break

print(tot)

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)[:X]
b = sorted(b, reverse=True)[:Y]
print(sum(sorted(a + b + c, reverse=True)[: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 = list(map(int, input().split()))

all_apple = sorted(p + q + r, reverse = True)
print(sum(all_apple[: 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 = list(map(int, input().split()))
print(sum(sorted(p + q + r, reverse=True)[: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)
print(sum(sorted(p + q + r, reverse=True)[: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()))
hq = []
for z in p:
  heapq.heappush(hq, [-z, 1])
for z in q:
  heapq.heappush(hq, [-z, 2])
for z in r:
  heapq.heappush(hq, [-z, 3])
red = 0
green = 0
less = 0
ans = 0
while red + green + less < x + y:
  v, f = heapq.heappop(hq)
  if f == 1 and red < x:
    ans -= v
    red += 1
  elif f == 2 and green < y:
    ans -= v
    green += 1
  elif f == 3:
    ans -= v
    less += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

X, Y, A, B, C = map(int, input().split())
 
p = deque(sorted(list(map(int,input().split())))[-X:])
q = deque(sorted(list(map(int,input().split())))[-Y:])
r = sorted(list(map(int,input().split())), reverse=True)
 
for i in r:
    p_min = p[0]
    q_min = q[0]
 
    if p_min > i and q_min > i:
        break
 
    p_min_diff = i - p_min
    q_min_diff = i - q_min
 
    if p_min_diff >= q_min_diff and p_min_diff > 0:
        p.popleft()
        p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        q.popleft()
        q.append(i)
 
print(sum(p) + sum(q))

Submission status: Accepted

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

ans = 0
red,grn = 0,0
for i in range(X+Y):
    pi = 0 if red>=X else p[-1]
    qi = 0 if grn>=Y else q[-1]
    ri = 0 if len(r)<=0 else r[-1]
    if pi>ri and pi>qi:
        ans += p.pop()
        red += 1
    elif qi>ri:
        ans += q.pop()
        grn += 1
    else:
        ans += r.pop()

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)
pp = p[:x]
qq = q[:y]

m = pp + qq + r
m.sort(reverse=True)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=[int(x) for x in input().split()]
saare=[]
for item in P:
	saare.append([item,'R'])
for item in Q:
	saare.append([item,'G'])
for item in R:
	saare.append([item,'C'])
 
saare.sort(reverse=True)
# print(saare)
 
p=A-X
q=B-Y
 
i=0
 
ans=0
 
while X or Y:
 
	if saare[i][1]=='R' and X:
		X-=1
		# p+=1
		ans+=saare[i][0]
		# print("EAT RED",saare[i][0])
	elif saare[i][1]=='G' and Y:
		Y-=1
		# q+=1
		ans+=saare[i][0]
		# print("EAT GREEN",saare[i][0])
	elif saare[i][1]=='C':
		if not Y:
			X-=1
			p+=1
			ans+=saare[i][0]
			# print("EAT RED",saare[i][0])
		elif not X:
			Y-=1
			q+=1
			ans+=saare[i][0]
			# print("EAT GREEN",saare[i][0])
		else:
			if P[p] >= Q[q]:
				q+=1
				Y-=1
				ans+=saare[i][0]
				# print("EAT GREEN",saare[i][0])
			else:
				p+=1
				X-=1
				ans+=saare[i][0]
				# print("EAT RED",saare[i][0])
	i+=1
print(ans)

Submission status: 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()))
A,B,C=[],[],[]
for i in range(a):
    A.append([p[i],0])
for i in range(b):
    B.append([q[i],1])
for i in range(c):
    C.append([r[i],2])
A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
C=sorted(C,reverse=True)
ABC=A+B+C
AC=A+C
BC=B+C
ABC=sorted(ABC,reverse=True)
AC=sorted(AC,reverse=True)
BC=sorted(BC,reverse=True)
ans=0
numa,numb,numc=0,0,0
for i in  range(x+y): #ABC上位x+yにおけるa,b,cの構成を調べる
    if ABC[i][1]==0:
        numa+=1
    elif ABC[i][1]==1:
        numb+=1
    else:
        numc+=1
    ans+=ABC[i][0]
def delete(ab,over):
    global ans,x,y
    if ab==0: #aが超過
        for i in range(over):
            ans-=A[x+i][0]
    else:
        for i in range(over):
            ans-=B[y+i][0]
def add(ab,over):
    global ans,x,y,numa,numb,numc
    if ab==0: #aが超過
        for i in range(over):
            ans+=BC[numb+numc+i][0]
    else:
        for i in range(over):
            ans+=AC[numa+numc+i][0]
#print(ABC)
if x<numa:
    over=numa-x #本当はaをx個しか選べないのに、aに大きい数字が多いため、aをx+α個選んでしまってる。超過分をb,cで埋め合わせ
    delete(0,over)
    add(0,over)
elif y<numb:
    over=numb-y
    delete(1,over)
    add(1,over)
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()
 
tmp = p[-x:] + q[-y:]
tmp.sort()
 
from collections import deque
tmp = deque(tmp)
 
while r and tmp[0] < r[-1]:
    tmp.popleft()
    tmp.append(r.pop())
#whileの条件文はr=True(rが存在（r.popで中身が無くなるまで）)とrの一番大きい数字がtmpの一番小さなものより大きいこと
#その限りはtmpの一番小さな数を取り除き(tmp.popleft)、rの一番大きい（右側、r.pop）のものをくっつける(append)

print(sum(list(tmp)))