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

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

p=p[(a-x):]
q=q[(b-y):]
p.extend(q)
p.sort()

idx=0
for i in range(len(p)):
    if p[i]>r[idx]:
        break
    else:
        p[i]=r[idx]
        idx+=1
        if c==idx:
            break

print(sum(p))

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    X,Y,A,B,C=map(int,input().split())
    P=list(map(int,input().split()))
    Q=list(map(int,input().split()))
    R=list(map(int,input().split()))
    lis=[]
    for i in range(A):
        lis.append((P[i],0))
    for i in range(B):
        lis.append((Q[i],1))
    for i in range(C):
        lis.append((R[i],2))
        
    lis.sort(reverse=True)
    white=[]
    sumc=0
    xy=[X,Y]
    for i in range(len(lis)):
        if lis[i][1]==2:
            white.append(lis[i])
        elif xy[lis[i][1]]:
            xy[lis[i][1]]-=1
            sumc+=lis[i][0]
        if (sum(xy)<=len(white)):
            break
    for i in range(len(white)):
        sumc+=white[i][0]
    print(sumc)
            
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque

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)

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

Submission status: Accepted

Solution code:
from collections import deque

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)

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

ans = 0
MIN = -1
N = X + Y
for _ in range(N):
    tmp_p, tmp_q, tmp_r = MIN, MIN, MIN
    if len(p) > 0 and X > 0:
        tmp_p = p.popleft()
    if len(q) > 0 and Y > 0:
        tmp_q = q.popleft()
    if len(r) > 0:
        tmp_r = r.popleft()
    
    if tmp_p >= tmp_q and tmp_p >= tmp_r:
        ans += tmp_p
        X -= 1
        if tmp_q != -1:
            q.appendleft(tmp_q)
        if tmp_r != -1:
            r.appendleft(tmp_r)

    elif tmp_q >= tmp_p and tmp_q >= tmp_r:
        ans += tmp_q
        Y -= 1
        if tmp_p != -1:
            p.appendleft(tmp_p)
        if tmp_r != -1:
            r.appendleft(tmp_r)

    else:
        ans += tmp_r
        if tmp_q != -1:
            q.appendleft(tmp_q)
        if tmp_p != -1:
            p.appendleft(tmp_p)

print(ans)

Submission status: Accepted

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)

Submission status: Accepted

Solution code:
import itertools
import functools
import math
from collections import Counter

def CHK():
    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)

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

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

CHK()

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(lambda x:int(x)*-1,input().split())))
q=sorted(list(map(lambda x:int(x)*-1,input().split())))
r=sorted(list(map(lambda x:int(x)*-1,input().split())))
import heapq
v=p[:x]+q[:y]+r
heapq.heapify(v)
ans=0
for i in range(x+y):
  ans+=heapq.heappop(v)
print(-ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
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)
    Q = sorted(list(map(int, input().split())), reverse=True)
    R = sorted(list(map(int, input().split())), reverse=True)
    Apples = sorted(P[:x] + Q[:y] + R, reverse=True)
    print(sum(Apples[: x + y]))


if __name__ == '__main__':
    resolve()

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

ans_p = deque(p[:X])
ans_q = deque(q[:Y])
ans_r = deque(r)

while (ans_p[-1]<ans_r[0]) or (ans_q[-1]<ans_r[0]):
  if ans_p[-1] <= ans_q[-1]:
    ans_p.pop()
    ans_p.appendleft(ans_r[0])
    ans_r.popleft()
  else:
    ans_q.pop()
    ans_q.appendleft(ans_r[0])
    ans_r.popleft()
  if not ans_r:
    break;
    
ans = sum(ans_p) + sum(ans_q)
print(ans)

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())
from heapq import *
p=[-i for i in p]
q=[-i for i in q]
r=[-i for i in r]
heapify(p)
heapify(q)
heapify(r)
ans=0
cnt=0
pt=heappop(p)
qt=heappop(q)
rt=heappop(r)
n=x+y
while (x>=0 or y>=0) and cnt<n:
  if rt==0:
    if pt<=qt:
      ans-=pt
      x-=1
      cnt+=1
      if p and x>0: pt=heappop(p)
      else: pt=0
    else:
      ans-=qt
      y-=1
      cnt+=1
      if q and y>0: qt=heappop(q)
      else: qt=0
  elif pt<=rt:
    ans-=pt
    x-=1
    cnt+=1
    if p and x>0: pt=heappop(p)
    else: pt=0
  elif qt<=rt:
    ans-=qt
    y-=1
    cnt+=1
    if q and y>0: qt=heappop(q)
    else: qt=0
  else:
    ans-=rt
    cnt+=1
    if r: rt=heappop(r)
    else: rt=0
print(ans)

Submission status: Accepted

Solution code:

def resolve():
    X, Y, A, B, C = map(int, input().split())
    apple_A = sorted(map(int, input().split()), reverse=True)[:X]
    apple_B = sorted(map(int, input().split()), reverse=True)[:Y]
    apple_C = sorted(map(int, input().split()), reverse=True)

    ans = apple_A + apple_B + apple_C
    ans.sort(reverse=True)
    
    print(sum(ans[:X+Y]))

if __name__ == "__main__":
    resolve()

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)

l = p[:X] + q[:Y] + r
print(sum(sorted(l, 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()))
ap = sorted(p)[a-x:]
aq = sorted(q)[b-y:]
r = sorted(r, reverse = True)

i,j,k = 0,0,0
flag = True

while k < c:
    if flag:
        if ap[i] <= aq[j]:
            if ap[i] <= r[k]:
                ap[i] = r[k]
                i += 1
                k += 1
                if i == x:
                    flag = False
                    continue
                continue
            else:
                break
        else:
            if aq[j] <= r[k]:
                aq[j] = r[k]
                j += 1
                k += 1
                if j == y:
                    flag = False
                    continue
                continue
    else:
        if i == x:
            if aq[j] <= r[k]:
                aq[j] = r[k]
                j += 1
                k += 1
                if j == y:
                    break
                continue
        else:
            if ap[i] <= r[k]:
                ap[i] = r[k]
                i += 1
                k += 1
                if i == x:
                    break
                continue
    
    break

ans = sum(ap) + sum(aq)
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 = P[::-1]
Q = Q[::-1]
R = R[::-1]
D = P[:X] + Q[:Y] + R
D.sort()
D = D[::-1]
D = D[:X+Y]
ans = sum(D)
print(ans)

Submission status: Accepted

Solution code:
def main():
    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]
    ans = sorted(P + Q + R, reverse = True)
    print(sum(ans[:x + y]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    x, y, a, b, c = map(int, readline().split())
    p = sorted(map(int, readline().split()), reverse=True)
    q = sorted(map(int, readline().split()), reverse=True)
    r = sorted(map(int, readline().split()), reverse=True)

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

if __name__ == "__main__":
    main()
    pass

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

x,y,a,b,c=nm()

ans=0

p=sorted(nl())[::-1][:x]
q=sorted(nl())[::-1][:y]
r=sorted(nl())[::-1]

s=sorted(p+q+r)[::-1]

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

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

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

ans = 0

if len(p) > x:
    p = p[:x]
if len(q) > y:
    q = q[:y]

p.extend(q)
p.extend(r)

p.sort(reverse=True)

p = p[:x+y]

print(sum(p))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

Submission status: Accepted

Solution code:
import numpy as np
inp = input
#fin = open("case_21.txt")
#inp = fin.readline

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

#red = np.array(list(map(int, inp().split())), np.int32)
#green = np.array(list(map(int, inp().split())), np.int32)
#white = np.array(list(map(int, inp().split())), np.int32)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
#fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0
countw = 0
while X > countr and Y > countg and (X+Y > countr+countg+countw):
    if red[idr] >= green[idg]:
        if idw >= C or red[idr] >= white[idw]:
            #eat red
            total += red[idr]
            idr += 1
            countr += 1
        elif idw < C:
            #eat white
            total += white[idw]
            idw += 1
            countw += 1
    else:
        if idw >= C or green[idg] >= white[idw]:
        # eat green
            total += green[idg]
            idg += 1
            countg += 1
        else:
            #eat white
            total += white[idw]
            idw += 1
            countw += 1

#eat remain
if Y <= countg:
    while X > countr+countw:
        # compare red 1st
        if idw < C and red[idr] < white[idw]:
            # eat white
            total += white[idw]
            idw += 1
        else:
            # eat red
            total += red[idr]
            idr += 1
        countr += 1

if X <= countr:
    while Y > countg+countw:
        # compare green 1st
        if idw < C and green[idg] < white[idw]:
            # eat white
            total += white[idw]
            idw += 1
        else:
            # eat green
            total += green[idg]
            idg += 1
        countg += 1

print(int(total))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

x, y, a, b, c = map(int, input().split(" "))
qL = sorted(list(map(int, input().split(" "))), reverse=True)[:x]
pL = sorted(list(map(int, input().split(" "))), reverse=True)[:y]
rL = sorted(list(map(int, input().split(" "))), reverse=True)

print(sum(sorted(qL + pL + rL, reverse=True)[:x + y]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


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

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

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

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

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

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


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

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

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

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

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

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


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


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


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


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
sentinel = 10 ** 9 + 10 ** 8

X, Y, A, B, C = map(int, input().split())
ps = [sentinel] + sorted(map(int, input().split()), reverse = True)
qs = [sentinel] + sorted(map(int, input().split()), reverse = True)
rs = sorted(map(int, input().split()), reverse = True)

X += 1
Y += 1

red_apples = X
green_apples = Y

while X+Y-red_apples-green_apples < C:
    if rs[X+Y-red_apples-green_apples] > qs[green_apples-1]:
        if qs[green_apples-1] > ps[red_apples-1]:
            red_apples -= 1
        else:
            green_apples -= 1
    elif rs[X+Y-red_apples-green_apples] > ps[red_apples-1]:
            red_apples -= 1
    else:
        break

print(sum(ps[1:red_apples]) + sum(qs[1:green_apples]) + sum(rs[:X+Y-red_apples-green_apples]))

Submission status: Accepted

Solution code:
x,y,A,B,C = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = list(map(int, input().split()))
aa = a[len(a)-x:]
bb = b[len(b)-y:]
for i in aa:
  c.append(i)
for i in bb:
  c.append(i)
c = sorted(c)
cc = c[len(c)-x-y:]
print(sum(cc))

Submission status: Accepted

Solution code:
# # -*- coding: utf-8 -*-
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(' ')))

apples = []
apples.extend([(p, 0) for p in P])
apples.extend([(q, 1) for q in Q])
apples.extend([(r, 2) for r in R])
apples.sort(key=lambda x: x[0], reverse=True)

ans = 0
num = X + Y
thresholds = [X, Y, C]
for v, category in apples:
    # もうその色のリンゴを取れない
    if not thresholds[category]:
        continue

    num -= 1
    thresholds[category] -= 1
    ans += v

    if num == 0:
        break

print(ans)

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split()) #x,yだけ見る。
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]
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_p = list(map(int,input().split()))
q_q = list(map(int,input().split()))
r_r = list(map(int,input().split()))
p_p.sort(reverse=True)
q_q.sort(reverse=True)
r_r.sort(reverse=True)

oisisa = sum(p_p[:x])+sum(q_q[:y])
apple = p_p[:x] + q_q[:y]
apple.sort()
seen = 0
for i in range(min(x+y,c)):
    if r_r[i] > apple[seen]:
        oisisa = oisisa + r_r[i] - apple[seen]
        seen += 1
    else:
        break


print(oisisa)

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)

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

for i in range(min(C, X+Y)):
    if R[i] > ans[i]:
        ans[i] = R[i]

print(sum(ans))

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X, Y, A, B, C, Ps, Qs, Rs):
    inf = 10 ** 9 + 1
    Ps.sort(reverse=True)
    Qs.sort(reverse=True)
    Rs.sort(reverse=True)
    a = X - 1
    b = Y - 1
    c = 0
    while True:
        m = min(Ps[a] if a >= 0 else inf,
                Qs[b] if b >= 0 else inf,
                Rs[c])
        if m == Rs[c]:
            break
        elif m == Ps[a]:
            c += 1
            a -= 1
        elif m == Qs[b]:
            c += 1
            b -= 1
        if c == C:
            break

    ans = 0
    if a >= 0:
        ans += sum(Ps[:a + 1])
    if b >= 0:
        ans += sum(Qs[:b + 1])
    if c > 0:
        ans += sum(Rs[:c])

    print(ans)


if __name__ == '__main__':
    X, Y, A, B, C = map(int, input().split())
    Ps = [int(i) for i in input().split()]
    Qs = [int(i) for i in input().split()]
    Rs = [int(i) for i in input().split()]
    solve(X, Y, A, B, C, Ps, Qs, Rs)

Submission status: Accepted

Solution code:
import heapq

X,Y,A,B,C = map(int, input().split())
p_list = sorted([(-v, 'p') for v in map(int, input().split())])
q_list = sorted([(-v, 'q') for v in map(int, input().split())])
r_list = sorted([(-v, 'r') for v in map(int, input().split())])

res = 0
r_cnt = 0
for v, k in heapq.merge(p_list, q_list, r_list):
    v = -v
    if X+Y-r_cnt == 0:
        break
    if k == 'p':
        if X != 0:
            X -= 1
            res += v
        continue
    
    if k == 'q':
        if Y != 0:
            Y -= 1
            res += v
        continue

    res += v
    r_cnt += 1

print(res)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

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

P.sort()
Q.sort()

lista = P[-X:] + Q[-Y:] + R
lista.sort()
print(sum(lista[-(X + Y):]))

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(reverse=True)
B.sort(reverse=True)
# C.sort(reverse=True)

top_x_of_A = A[:X]
top_Y_of_B = B[:Y]
top_x_of_A.extend(top_Y_of_B)
C.extend(top_x_of_A)
C.sort(reverse=True)
print(sum(C[:X+Y]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
x,y,a,b,c = map(int,input().split())
red = list(map(int,input().split()))+[0]
green = list(map(int,input().split()))+[0]
cless = list(map(int,input().split()))+[0]
red.sort(reverse = True)
green.sort(reverse = True)
cless.sort(reverse = True)
red_ind = 0
green_ind = 0
cless_ind = 0
ans = 0
for _ in range(x+y):
    if red_ind == x:
        red_ind = a
    if green_ind == y:
        green_ind = b
    if max(red[red_ind],green[green_ind],cless[cless_ind]) == red[red_ind]:
        ans += red[red_ind]
        red_ind += 1
    elif max(red[red_ind],green[green_ind],cless[cless_ind]) == green[green_ind]:
        ans += green[green_ind]
        green_ind += 1
    else:
        ans += cless[cless_ind]
        cless_ind += 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(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:X]
q=q[:Y]
s=p+q+r
s.sort(reverse=True)
print(sum(s[:X+Y]))

Submission status: Accepted

Solution code:
def main():
    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 = R + P[:X] + Q[:Y]
    R.sort(reverse=True)
    print(sum(R[:(X+Y)]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq


def main():
    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)
    que = []
    for p in P[:X]:
        heapq.heappush(que, p)
    for q in Q[:Y]:
        heapq.heappush(que, q)
    for r in R:
        min_que = heapq.heappop(que)
        if min_que >= r:
            heapq.heappush(que, min_que)
            break
        else:
            heapq.heappush(que, r)
    print(sum(que))


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)

eat = [p[i] for i in range(X)] + [q[i] for i in range(Y)]
eat.sort()
for i in range(len(r)):
    if eat[i] < r[i]:
        eat[i] = r[i]
    else:
        break

print(sum(eat))

Submission status: Accepted

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

pa = sorted(pa)
pb = sorted(pb)
pc = sorted(pc)

pr = pa[-X:] + pb[-Y:]
pr = sorted(pr)

c = 0
r = 0
while True:
  c += 1
  if c > C:
    break
  if pr[r] < pc[-c]:
    pr[r] = pc[-c]
    r += 1
  else:
    break

print(sum(pr))

Submission status: Accepted

Solution code:
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)
P = P[:x]
Q.sort(reverse=True)
Q = Q[:y]
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)
while R:
    if P[0] >= Q[0]:
        if Q[0] < -R[0]:
            heapq.heapreplace(Q, -heapq.heappop(R))
        else:
            break
    else:
        if P[0] < -R[0]:
            heapq.heapreplace(P,-heapq.heappop(R))
        else:
            break
print(sum(P)+sum(Q))

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 = [ -int(i) for i in input().split()]
P.sort(reverse=True)
P = P[:x]
Q.sort(reverse=True)
Q = Q[:y]
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)
while R:
    if P[0] >= Q[0]:
        if Q[0] < -R[0]:
            heapq.heapreplace(Q, -heapq.heappop(R))
        else:
            break
    else:
        if P[0] < -R[0]:
            heapq.heapreplace(P,-heapq.heappop(R))
        else:
            break
print(sum(P)+sum(Q))

Submission status: Accepted

Solution code:
#heapq p,qの最小値側にrの最大値入れていく。
#p_changeとq_changeが等しい場合がおかしかったのを直した
import heapq 

#初期入力
X,Y,A,B,C = (int(x) for x in 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(reverse=True)

ans_sum =sum(p[-X:]) + sum(q[-Y:])
p_hq = p[-X:]
q_hq = q[-Y:]
heapq.heapify(p_hq)
heapq.heapify(q_hq)
p_change =heapq.heappop(p_hq)
q_change =heapq.heappop(q_hq)
count_p =0
count_q =0
for i in r: #rは大きい順
    if i < p_change and i < q_change:
        break
    if p_change <= q_change:
        if  count_p < X:
            heapq.heappush(p_hq,i)
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =heapq.heappop(p_hq)
    elif p_change > q_change:
        if  count_q < Y:
            heapq.heappush(q_hq,i)
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =heapq.heappop(q_hq)
print(ans_sum)