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

A = sorted(A)
B = sorted(B)

A = A[len(A)-x:]
B = B[len(B)-y:]
C = list(map(lambda x: x*(-1), C))

import heapq
heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)

flag = True
while flag:
  a = heapq.heappop(A)
  b = heapq.heappop(B)
  c = heapq.heappop(C)*(-1)
  if c < a and c < b:
    heapq.heappush(A, a)
    heapq.heappush(B, b)
    flag = False
  else:
    if a > b:
      heapq.heappush(A, a)
      heapq.heappush(B, c)
      if not C:
        break
    else:
      heapq.heappush(A, c)
      heapq.heappush(B, b)
      if not C:
        break
print(sum(A) + sum(B))

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_p = p[:X]
B_q = q[:Y]
C_r = r
 
ans = A_p + B_q + C_r
ans.sort(reverse=True)
print(sum(ans[: X+Y]))

Submission status: Accepted

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

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
ansl = pl[-x:] + ql[-y:]

ansl += rl

ansl = sorted(ansl)
print(sum(ansl[-(x+y):]))

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()], reverse=True)
l = sorted(p[:X] + q[:Y])

i = 0
ans = 0
for a in l:
    if i < C and r[i] <= a:
        ans += a
    elif i < C and r[i] > a:
        ans += r[i]
        i += 1
    else:
        ans += a

print(ans)

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse = True)
Q = sorted(list(map(int, input().split())), reverse = True)
R = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
import sys

# import bisect
from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

import heapq


class Reverse:
    def __init__(self, val):
        self.val = val

    def __lt__(self, other):
        return self.val > other.val

    def __repr__(self):
        return repr(self.val)


class PriorityQueue:

    def __init__(self, x=[], desc=False):
        if desc:
            for i in range(len(x)):
                x[i] = Reverse(x[i])
        self._desc = desc
        self._container = x
        heapq.heapify(self._container)

    @property
    def is_empty(self):
        return not self._container

    def pop(self):
        if self._desc:
            return heapq.heappop(self._container).val
        else:
            return heapq.heappop(self._container)

    def push(self, item):
        if self._desc:
            heapq.heappush(self._container, Reverse(item))
        else:
            heapq.heappush(self._container, item)

    def top(self):
        if self._desc:
            return self._container[0].val
        else:
            return self._container[0]

    def sum(self):
        return sum(self._container)

    def __len__(self):
        return len(self._container)


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

    p.sort()
    q.sort()
    r = PriorityQueue(r,desc=True)

    eat = p[-x:]
    eat.extend(q[-y:])
    eat = PriorityQueue(eat)

    while eat.top() < r.top():
        _ = eat.pop()
        eat.push(r.pop())
        c -= 1
        if c == 0:
            break

    print(eat.sum())





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

p.insert(0, 10**9)
p.append(0)
q.insert(0, 10**9)
q.append(0)
r.append(0)

result = sum(p[1:x+1]) + sum(q[1:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Submission status: Accepted

Solution code:
x,y,a,b,c=[int(i) for i in 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=sorted(p)[::-1]
q=sorted(q)[::-1]

s=p[:x]+q[: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())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
ans = r
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
r.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())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

eat_r = p[:x]
eat_g = q[:y]
eat = eat_r + eat_g
sort_eat = sorted(eat)
for i in r:
    if sort_eat[0] < i:
        sort_eat.append(i)
sort_eat.sort(reverse=True)

print(sum(sort_eat[: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()

for _ in range(x):
    r.append(p.pop(-1))

for _ in range(y):
    r.append(q.pop(-1))

r.sort()

d = 0
for _ in range(x + y):
    d += r.pop(-1)

print(d)

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    x,y,a,b,c = map(int,input().split())
    R = list(map(int,input().split()))
    G = list(map(int,input().split()))
    M = list(map(int,input().split()))
    R.sort(reverse = True)
    G.sort(reverse = True)
    M.sort(reverse = True)
    apple = R[:x] + G[:y] + M
    apple.sort(reverse = True)
    ans = sum(apple[:x + y])
    print(ans)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline

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

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

lis = []

for i in range(X):
    lis.append(P[i])

for i in range(Y):
    lis.append(Q[i])

for i in range(min(len(R), X + Y)):
    lis.append(R[i])

lis.sort(reverse=True)

ans = 0

for i in range(X + Y):
    ans += lis[i]

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 = []
for i in range(x):
    all.append(p[i])
for i in range(y):
    all.append(q[i])
for i in range(c):
    all.append(r[i])
all = sorted(all, reverse=True)
res = 0
for i in range(x + y):
    res += all[i]
print(res)

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

e = sorted(P)[-x:]
e += sorted(Q)[-y:]
e += R
print(sum(sorted(e,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()
p.reverse()
q.sort()
q.reverse()
del p[X:]
del q[Y:]
p.extend(q)
p.extend(r)
p.sort()
p.reverse()
del p[X+Y:]
d = sum(p)
print(d)

Submission status: Accepted

Solution code:
import heapq


class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign


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

red = [int(i) for i in input().split()]
green = [int(i) for i in input().split()]
clear = [int(i) for i in input().split()]

red = Heapq(red, True)
green = Heapq(green, True)
clear = Heapq(clear, True)

ans = []
for i in range(x):
    clear.push(red.pop())
for j in range(y):
    clear.push(green.pop())
ans = 0
for k in range(x + y):
    ans += clear.pop()
print(ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))

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()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
j=0
k=0
for i in ans:
	if len(r)>1:
		k=r[-1]
	elif len(r)==1:
		k=r[0]
	else:
		break
	if i<k:
		ans[j]=r.pop()
		j+=1
	else:
		break
print(sum(ans))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

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 = sum(P[:X]) + sum(Q[:Y])
apples = []
for p in P[:X]:
    heappush(apples, p)

for q in Q[:Y]:
    heappush(apples, q)

for r in R:
    amin = heappop(apples)
    if r >= amin:
        heappush(apples, r)
        ans += (r - amin)
    else:
        break

print(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())), )[-X:]
Q=sorted(list(map(int, input().split())), )[-Y:]
R=sorted(list(map(int, input().split())), reverse=True)

PQ=sorted(P+Q)

ans=0
for i in range(len(PQ)):
  if len(R)>0:
    
    now=max(PQ[i], R.pop(0))
  else:
    now=PQ[i]
  ans+=now
  
print(ans)

Submission status: Accepted

Solution code:
import heapq

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

p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

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

heapq.heapify(red)
heapq.heapify(green)

for nc in nocolor:
    R = red[0]
    G = green[0]
    if R > nc and G > nc:
        break
    elif nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green, nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red, nc)
    elif nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red, nc)
    elif nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green, nc)

print(sum(red) + sum(green))

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())))
S=sorted(P[A-X:]+Q[B-Y:])
ans=sum(S)
for i in range(min(len(R),len(S))):
    if S[i]<R[-1-i]:
        S[i]=R[-1-i]
    else:
        break
print(sum(S))

Submission status: Accepted

Solution code:
from itertools import *
from heapq import *

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

S = sum(islice(merge(islice(P, X),islice(Q, Y),R), X+Y))

print(-S)

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 = []
for i in range(x):
    a.append(p[i])

for i in range(y):
    a.append(q[i])

for i in range(c):
    a.append(r[i])

a.sort(reverse=True)
ans = 0
for i in range(x + y):
    ans += a[i]

print(ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = [int(i) for i in input().split()]
p = sorted([int(i) for i in input().split()])[::-1]
q = sorted([int(i) for i in input().split()])[::-1]
r = sorted([int(i) for i in input().split()])[::-1]
 
# print(p, q, r)
pp = x - 1
qp = y - 1
rp = 0
while rp < c:
    if pp < 0 and r[rp] > q[qp]:
        q[qp] = r[rp]
        qp -= 1
    elif qp < 0 and r[rp] > p[pp]:
        p[pp] = r[rp]
        pp -= 1 
    elif pp < 0 and qp < 0:
        break
    elif r[rp] > p[pp] or r[rp] > q[qp]:
        if p[pp] > q[qp]:
            q[qp] = r[rp]
            qp -= 1
        else:
            p[pp] = r[rp]
            pp -= 1
    rp += 1
 
# print(p,q)
print(sum(p[:x]) + sum(q[:y]))

Submission status: Accepted

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif Q[j-1] <= P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

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 = sorted(P)[-x:]
Q = sorted(Q)[-y:]
H = sorted(P+Q)
R.sort()

ans=0
for h in H:
    if R and R[-1] > h:
        ans += R.pop()
    else:
        ans += h
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
r = sorted(list(map(int, input().split())))[a - x:]
g = sorted(list(map(int, input().split())))[b - y:]
m = list(map(int, input().split()))

ans = sorted(r + g + m)
print(sum(ans[len(ans) - x - y:]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()

A.sort(reverse=1)
B.sort(reverse=1)

que = []
que += A[:X]
que += B[:Y]
heapify(que)

for c in C:
    if c > que[0]:
        heappop(que)
        heappush(que, c)
ans = sum(que)
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

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

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 = 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_list = P[:X]
ANS_list.extend(Q[:Y])
ANS_list.sort()
c = 0
for i in range(len(R)):
  if ANS_list[i] >= R[i]:
    break
  c+=1

if i!=0:
  ANS_list[:c] = R[:c]
print(sum(R[:c])+sum(ANS_list[c:]))

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

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

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

ans = sorted(p[A-X:] + q[B-Y:])
ans_sum = [ans[0]]
for i in range(1, X+Y):
    ans_sum.append(ans_sum[i-1] + ans[i])

r_sum = [r[0]]
for i in range(1, C):
    r_sum.append(r_sum[i-1] + r[i])

index, temp = -1, ans_sum[-1]
for i in range(min(C, X+Y)):
    if temp < ans_sum[-1] + r_sum[i] - ans_sum[i]:
        temp = ans_sum[-1] + r_sum[i] - ans_sum[i]
print(temp)

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()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=False)
ans = 0
L = P[:X] + Q[:Y] + R
L.sort(reverse=True)
print(sum(L[: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)

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

Submission status: Accepted

Solution code:
import heapq

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

p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=True)

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


heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)

for nc in nocolor:
    R = heapq.heappop(red)
    G = heapq.heappop(green)
    heapq.heappush(red,R)
    heapq.heappush(green,G)
    if R > nc and G > nc:
        break
    elif nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green,nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red,nc)
    elif nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red,nc)
    elif nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green,nc)


print(sum(red)+sum(green))

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

Submission status: Accepted

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

D=sorted(P, reverse=True)[:X]
E=sorted(Q, reverse=True)[:Y]
Z=X+Y
if C>=Z:
    F=sorted(R, reverse=True)[:Z]
else:
    F=R

D.extend(E)
D.extend(F)
I=sorted(D, reverse=True)[:Z]

print(sum(I))

Submission status: Accepted

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            elif Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Accepted

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

l = pp + qq + r
l.sort(reverse=True)
print(sum(l[:(x + y)]))

Submission status: Accepted

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

pq = sorted(p[:X] + q[:Y])
# print(pq,r)
for i in range(min(X+Y,C)):
  if r[i] < pq[i]:
    break
else:
  i+=1
print(sum(r[:i] + pq[i:]))

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(reverse=True)
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(min(len(ans),c)):
  if ans[i]<=r[rcount]:
    ans[i]=r[rcount]
    rcount+=1
print(sum(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import heapq as hp
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()))
result = 0
cnt_r = x
cnt_g = y
cnt_n = x+y

apples = []
for i in range(a):
    apple = (-p[i], "R")
    hp.heappush(apples, apple)
for i in range(b):
    apple = (-q[i], "G")
    hp.heappush(apples, apple)
for i in range(c):
    apple = (-r[i], "N")
    hp.heappush(apples, apple)

while cnt_n > 0:
    tmp_a = hp.heappop(apples)
    if tmp_a[1] == "R":
        if cnt_r > 0:
            result += -tmp_a[0]
            cnt_r -= 1
            cnt_n -= 1
    elif tmp_a[1] == "G":
        if cnt_g > 0:
            result += -tmp_a[0]
            cnt_g -= 1
            cnt_n -= 1
    else:
        if cnt_n > 0:
            result += -tmp_a[0]
            cnt_n -= 1

print(result)

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)

alist = []
ans = 0

for i in range(X):
    alist.append(p[i])
    
for j in range(Y):
    alist.append(q[j])
    
for k in range(C):
    alist.append(r[k])
    
alist.sort(reverse=True)
    
for k in range(X+Y):
    ans += alist[k]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 19:26:54 2020

@author: matha
"""


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

p = sorted(map(int, input().split()), reverse = 1)
q = sorted(map(int, input().split()), reverse = 1)
r = sorted(map(int, input().split()), reverse = 1)


nl = sorted(p[0:x] + q[0: y] + r, reverse = 1)

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

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

print(ans)

Submission status: Accepted

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

import heapq
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
for _ in range(x):
    r.append(heapq.heappop(p))
for _ in range(y):
    r.append(heapq.heappop(q))
heapq.heapify(r)
s = 0
for i in range(x+y):
    s+=heapq.heappop(r)*(-1)
print(s)

Submission status: Accepted

Solution code:
x,y,a,b,c = (int(x) for x in input().split())

from bisect import insort

p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
r_list = list(map(int,input().split()))


p_list.sort()
q_list.sort()
r_list.sort()

red = 0
green = 0
white = 0

sum_num = 0

for i in range(1,x+y+1):
  if red < x:
  	red_num = p_list[(red*-1)-1]
  else:
    red_num = 0
  if green < y:
  	green_num = q_list[(green*-1)-1]
  else:
    green_num = 0
  if white < c:
  	white_num = r_list[(white*-1)-1]
  else:
    white_num = 0
  
  max_p = max([red_num,green_num,white_num])
  sum_num += max_p
  if max_p == white_num:
    white += 1
  elif max_p == red_num:
    red += 1
  elif max_p == green_num:
    green += 1

print(sum_num)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
v = []
l = list(map(int, input().split()))
for i in range(a):
    v.append([l[i], 1])
l = list(map(int, input().split()))
for i in range(b):
    v.append([l[i], 2])
l = list(map(int, input().split()))
for i in range(c):
    v.append([l[i], 3])
v.sort(reverse=True)
res = 0
cnt = [0, 0, 0]
for i in range(len(v)):
    t = v[i][1]
    if cnt[0] == x and t == 1:
        continue
    if cnt[1] == y and t == 2:
        continue
    if sum(cnt) == x + y:
        break
    cnt[t - 1] += 1
    res += v[i][0]
print(res)

Submission status: Accepted

Solution code:
x,y,a,b,c = map(int,input().split())
p = input().split()
p = [int(s) for s in p]
q = input().split()
q = [int(s) for s in q]
r = input().split()
r = [int(s) for s in r]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y] + r
s.sort(reverse=True)
print(sum(s[:x+y]))

Submission status: Accepted

Solution code:
x,y,a,b,c, = map(int, input().split())
xx = list(map(int, input().split()))
yy = list(map(int, input().split()))
rr = list(map(int, input().split()))
 
xx = sorted(xx, reverse=True)[:x]
yy = sorted(yy, reverse=True)[:y]
rr = rr + xx + yy
print(sum(sorted(rr, reverse=True)[:x+y]))