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

red = [0] + list(map(int,input().split()))
red.sort()
green = [0] + list(map(int,input().split()))
green.sort()
colorless = [0] + list(map(int,input().split()))
colorless.sort()

#print(red,green, colorless)

z = x + y
deliscious = 0
countx = 0
county = 0
for i in range(z):
    p = red[len(red)-1]
    q = green[len(green)-1]
    r = colorless[len(colorless)-1]
    #print(p,q,r,countx,x,county,y)
    if p >= q and p > r and countx < x:
        deliscious += p
        red.pop()
        countx += 1
    elif q >= p and q > r and county < y:
        deliscious += q
        green.pop()
        county += 1
    else:
        deliscious += r
        colorless.pop()
    if countx == x:
        red.append(0)
        countx += 1
    if county == y:
        green.append(0)
        county += 1
        
    
    #print(red,green, colorless,deliscious)
    
print(deliscious)

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

red = sorted(red)[-x:]
gre = sorted(gre)[-y:]
uni = tra + red + gre

ans = sum(sorted(uni)[-(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()))

# step1: sort red/green apples in descending order
p.sort(reverse=True)
q.sort(reverse=True)

# step2:clip necessary apples
p = p[:x]
q = q[:y]

# step3: sort red/green apples in ascending order
p.sort()
q.sort()

# step4: sort non-color apples in descending order
r.sort(reverse=True)

# step5:swap apples to eliminate the least delicious apple
d = []

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

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

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

Submission status: Accepted

Solution code:
import heapq
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
candidates = []
for i in range(X):
    candidates.append(-1 * p[i])
for i in range(Y):
    candidates.append(-1 * q[i])
for i in range(C):
    candidates.append(-1 * r[i])
heapq.heapify(candidates)
ans = 0
for _ in range(X + Y):
    val = heapq.heappop(candidates)
    ans += val
print(-ans)

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = [int(a) for a in input().split()]
q = [int(a) for a in input().split()]
r = [int(a) for a in input().split()]
s = []

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

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

s = s[:(X + Y)]
        
print(sum(s))

Submission status: Accepted

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

resolve()

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

print(su)

Submission status: Accepted

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

pList = list(map(int, input().split()))
qList = list(map(int, input().split()))
rList = list(map(int, input().split()))

pList.sort(reverse=True)
qList.sort(reverse=True)
rList.sort(reverse=True)

pList = pList[:X]
qList = qList[:Y]

appleList = pList + qList + rList
appleList.sort(reverse=True)
appleList = appleList[:X+Y]

print(sum(appleList))

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)

memo = []

for i in range(x):
    memo.append(p[i])
for j in range(y):
    memo.append(q[j])
for k in r:
    memo.append(k)

memo.sort(reverse=True)
ans = 0

for l in range(x+y):
    ans += memo[l]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline

rl = lambda: list(map(int, input().split()))

x, y, a, b, c = rl()
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = sum(sorted(p[:x] + q[:y] + r, reverse=True)[:x+y])
print(res)

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = [int(n) for n in input().split()]
q = [int(n) for n in input().split()]
r = [int(n) for n in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
px = p[0: X]
qx = q[0: Y]
t = px + qx + r
t.sort(reverse=True)
print(sum(t[0: X + Y]))

Submission status: Accepted

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

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

s = p[:X] + q[:Y] + r

s.sort(reverse = True)
answer = sum(s[:X+Y])    

print(answer)

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, aa, bb, cc, = 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)

ary = a[:x] + b[:y] + c
ary.sort(reverse=True)
print (sum(ary[:x+y]))

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
list_of_red = list(map(int, input().split()))
list_of_green = list(map(int, input().split()))
list_of_colorless = list(map(int, input().split()))

list_of_green.sort(reverse=True)
list_of_red.sort(reverse=True)
list_of_colorless.sort(reverse=True)

max_of_red = list_of_red[:x]
max_of_green = list_of_green[:y]

temp = (max_of_red+max_of_green+list_of_colorless)
temp.sort(reverse=True)
ans = sum(temp[:x+y])
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())
P, Q = sorted(P, reverse=True), sorted(Q, reverse=True)
P, Q = P[:X], Q[:Y]
ans = sum(sorted(P + Q + R, reverse=True)[:X + Y])
print(ans)

Submission status: Accepted

Solution code:
import bisect

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

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

for i in range(min(x+y,c)):
    if l[i]<r[-1]:
        l[i]=r.pop()
    else:
        break
print(sum(l))

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)
i=0
j=0
k=0
c1=(x+y)-min(c,x+y)
count=0
res=[]
s=0
while(i<x and j<y):
    if(p[i]>q[j]):
        ans=p[i]
        i+=1
    else:
        ans=q[j]
        j+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1
while(i<x):
    ans=p[i]
    i+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1

while(j<y):
    ans=q[j]
    j+=1
    if(count>=c1):
        res.append(ans)
    else:
        s+=ans
    count+=1
c1=min(c,x+y)
count=0
i=0
j=0
while(i<c1 and j<c1):
    if(count>=c1):
        break
    if(res[i]>r[j]):
        s+=res[i]
        i+=1
    else:
        s+=r[j]
        j+=1
    count+=1
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)
p = p[:X]
q.sort(reverse=True)
q = q[:Y]

apples = []
for i in p:
    apples.append(i)
for j in q:
    apples.append(j)
for h in r:
    apples.append(h)

apples.sort(reverse=True)
apples = apples[:A+B]
print(sum(apples[:X+Y]))
"""
red = 0
green = 0
trans = 0
ans = 0
for i in range(A+B):
    num = apples[i][1]
    if num == 0 and red <= A:
        ans += apples[i][0]
        red += 1
    elif num == 1 and green <= B:
        ans += apples[i][0]
        green += 1
    elif num == 2 and trans <= C:
        ans += apples[i][0]
        if red < green:
            red += 1
        else:
            green += 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]
p[len(p):len(p)]=q
p[len(p):len(p)]=r
p.sort(reverse=True)
print(sum(p[:x+y]))

Submission status: Accepted

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

P = [0]*(A+1)
P[1] = p[0]
for i in range(2,A+1):
    P[i] = P[i-1] + p[i-1]

Q = [0]*(B+1)
Q[1] = q[0]
for i in range(2,B+1):
    Q[i] = Q[i-1] + q[i-1]

R = [0]*(C+1)
R[1] = r[0]
for i in range(2,C+1):
    R[i] = R[i-1] + r[i-1]

z = 0
res = []
#print(P,Q,R)
x = X
y = Y
p.append(10000000000)
q.append(10000000000)

for i in range(C+1):
    #print(x,y,z)
    hp = P[x] + Q[y] + R[z]
    if p[x-1] <= q[y-1] and x > 0:
        x -= 1
        z += 1
    elif p[x-1] >= q[y-1] and y > 0:
        y -= 1
        z += 1

    res.append(hp)
#print(res)
print(max(res))

Submission status: Accepted

Solution code:
X,Y,A,B,C = map(int,input().split())
p_s = list(map(int,input().split()))
q_s = list(map(int,input().split()))
r_s = list(map(int,input().split()))
p_s.sort()
q_s.sort()
r_s.sort()
p = p_s[A-X:]
q = q_s[B-Y:]
r = r_s[max(C-(X+Y),0):]
p.reverse()
q.reverse()
r.reverse()
p.append(0)
q.append(0)
r.append(0)
i=0
j=0
k = 0
SUM = 0
cnt = 0
while cnt < X+Y:
    if i<len(p)-1 and p[i] >= q[j] and p[i] >= r[k]:
        SUM += p[i]
        i+=1
    elif j<len(q)-1 and q[j] >= p[i] and q[j] >= r[k]:
        SUM += q[j]
        j+=1
    elif k<len(r)-1 and r[k] >= q[j] and r[k] >= p[i]:
        SUM += r[k]
        k+=1
    cnt += 1
print(SUM)

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
1 2 2 2 1
2 4
5 1
3
'''

def solve(p,q,r,x,y):
	a,b,c = len(p),len(q),len(r)
	p = sorted(p)[::-1][:x]
	q = sorted(q)[::-1][:y]
	r = sorted(r)[::-1]
	t = p + q + r
	t = sorted(t)[::-1][:x+y]
	return sum(t)


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

Submission status: Accepted

Solution code:
# E - Red and Green Apples
def main():
    X, Y, *_, = map(int, input().split())
    P = sorted(map(int, input().split()), reverse=True)[:X]
    Q = sorted(map(int, input().split()), reverse=True)[:Y]
    R = list(map(int, input().split()))
    PQR = P + Q + R
    PQR.sort(reverse=True)
    ans = sum(PQR[: X + Y])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# E - Red and Green Apples
def main():
    X, Y, A, B, C = map(int, input().split())
    P = sorted(map(int, input().split()), reverse=True)[:X]
    Q = sorted(map(int, input().split()), reverse=True)[:Y]
    R = list(map(int, input().split()))
    PQR = P + Q + R
    PQR.sort(reverse=True)
    ans = sum(PQR[: X + Y])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


X, Y, A, B, C = inpl()
P = inpl()
Q = inpl()
R = inpl()
P.sort()
Q.sort()
R.sort(reverse=True)

ans = sum(P[A - X:]) + sum(Q[B - Y:])
P.append(10**10)
Q.append(10**10)


pi = A - X
qi = B - Y
for ri in range(C):
    if P[pi] >= R[ri] and Q[qi] >= R[ri]:
        break
    elif P[pi] > Q[qi]:
        ans -= Q[qi]
        qi += 1
        ans += R[ri]
    else:
        ans -= P[pi]
        pi += 1
        ans += R[ri]

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
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,Q = p[:X],q[:Y]

heapify(P)
heapify(Q)

for i in range(C):
  if min(P[0],Q[0]) > r[i]:
    break
  if P[0] < Q[0]:
    heappop(P)
    heappush(P,r[i])

  else:
    heappop(Q)
    heappush(Q,r[i])
print(sum(P)+sum(Q))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]



def main():
    a=LI()
    x=a[0]
    y=a[1]
    b=a[3]
    c=a[4]
    a=a[2]
    pa=LI()
    pb=LI()
    pc=LI()
    pa.sort()
    pb.sort()
    pc.sort()
    pa.reverse()
    pb.reverse()
    pc.reverse()
    pa=pa[0:x]
    pb=pb[0:y]
    pa+=pb
    pa.sort()
    pa.reverse()
    j=len(pa)-1
    summ=0
    for i in range(0, len(pa)):
        summ+=pa[i]
    for i in range(0, len(pc)):
        if j>=0 and pc[i]<=pa[j]:
            break
        else:
            summ-=pa[j]
            summ+=pc[i]
            j-=1
    print(summ)
main()

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:
from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
aka = x-1
midori = y-1
ps = p[:x]
qs = q[:y]
li = ps + qs
li.sort(reverse=True)
i = 0
z = d.popleft()
while li[x+y-1-i] < z:
  li[x+y-1-i] = z
  i += 1
  if not d:
    break
  z = d.popleft()
ans = 0
for i in range(x+y):
  ans += li[i]
print(ans)

Submission status: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

X,Y,A,B,C=acinput()

p=acinput()
q=acinput()
r=acinput()



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

tmp=p[:X]
tmp.extend(q[:Y])

tmp.extend(r)

tmp=sorted(tmp,reverse=True)

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

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
AC=[]
for a in map(int,input().split()):
  AC.append((a,1))
for a in map(int,input().split()):
  AC.append((a,2))
for a in map(int,input().split()):
  AC.append((a,0))
AC.sort(reverse=1)

red=0
green=0
cnt=0
res=0
for a,c in AC:
  if c==0:
    res+=a
    cnt+=1
  elif c==1:
    if red<x:
      res+=a
      red+=1
      cnt+=1
  else:
    if green<y:
      res+=a
      green+=1
      cnt+=1
  if cnt==x+y:
    print(res)
    exit(0)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

#print(p, q, r)

#print(p[:x])
#print(q[:y])

merge_list = []
merge_list.extend(p[:x])
merge_list.extend(q[:y])
merge_list.extend(r)

merge_list.sort(reverse=True)

# print(merge_list)
print(sum(merge_list[:x + y]))

Submission status: Accepted

Solution code:
from collections import deque
x,y,r, g, n  = map(int,input().split())

R = list(map(int, input().split()))
G = list(map(int, input().split()))
N = list(map(int, input().split()))

R.sort(reverse = True)
G.sort(reverse = True)
N.sort()
R_dq = deque(R[:x])
G_dq = deque(G[:y])
N_dq = deque(N)

flag =True
while flag:
    r_tail = R_dq[-1]
    g_tail = G_dq[-1]
    if len(N_dq) ==0:
        break
    else:
        n_tail = N_dq[-1]

    if r_tail < g_tail:#r_tail がg_tailより小さい
        if r_tail < n_tail:
            R_dq.pop()
            R_dq.appendleft(n_tail)
            N_dq.pop()
        else:
            break
    else:#g_tailがr_tailより小さい
        if g_tail < n_tail:
            G_dq.pop()
            G_dq.appendleft(n_tail)
            N_dq.pop()
        else:
            break
print(sum(R_dq) + sum(G_dq))

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

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

Submission status: Accepted

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
l = sorted(p + q + r, reverse=True)
print(sum(l[:X+Y]))

Submission status: Accepted

Solution code:
from heapq import heappop, heappush

x, y, a, b, c = map(int, input().split())
apple = []
# Red is 0, Green is 1, Colorless is 2
for p in map(int, input().split()):
  heappush(apple, (-p, 0))
for q in map(int, input().split()):
  heappush(apple, (-q, 1))
for r in map(int, input().split()):
  heappush(apple, (-r, 2))
delicious = 0
colorless = 0
while x + y > colorless:
  minus_taste, color = heappop(apple)
  if color == 0:
    if x > 0:
      delicious -= minus_taste
      x -= 1
  elif color == 1:
    if y > 0:
      delicious -= minus_taste
      y -= 1
  else:
    delicious -= minus_taste
    colorless += 1
print(delicious)

Submission status: Accepted

Solution code:
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

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

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

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

ct1 = x - 1
ct2 = y - 1
ct3 = c - 1
ans = 0

while ct3 >= 0:
    if ct1 >= 0 and ct2 >= 0:
        if p[ct1] > r[ct3] and q[ct2] > r[ct3]:
            break
        elif p[ct1] < q[ct2]:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    elif ct1 >= 0:
        if p[ct1] > r[ct3]:
            break
        else:
            p[ct1] = r[ct3]
            ct1 -= 1
            ct3 -= 1
    elif ct2 >= 0:
        if q[ct2] > r[ct3]:
            break
        else:
            q[ct2] = r[ct3]
            ct2 -= 1
            ct3 -= 1
    else:
      break
for i in range(x):
    ans += p[i]
for i in range(y):
    ans += q[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()))
r += sorted(p)[-x:]
r += sorted(q)[-y:]
ans = sum(sorted(r)[-(x+y):])
print(ans)

Submission status: Accepted

Solution code:
x, y, a, b, c = map(int, input().split())
pa = sorted(list(map(int, input().split())), reverse=True) # 赤
qb = sorted(list(map(int, input().split())), reverse=True) # 緑
rc = list(map(int, input().split())) # 透明

ans = []
ans += pa[:x]
ans += qb[:y]
ans += rc

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

Submission status: Accepted

Solution code:
#apples
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
white = list(map(int, input().split()))
red.sort()
green.sort()
white.sort()

apples = []
for i in range(x):
    apples.append(red[(a-1)-i])
for i in range(y):
    apples.append(green[(b-1)-i])
    
add = min(x+y, c)
for i in range(add):
    apples.append(white[(c-1)-i])

apples.sort()
sum = 0
for j in range(x+y):
    sum += apples[(x + y + add -1)-j]
print(sum)

Submission status: Accepted

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

X,Y,A,B,C=map(int, sys.stdin.readline().split())
R=map(int, sys.stdin.readline().split())
G=map(int, sys.stdin.readline().split())
N=map(int, sys.stdin.readline().split())
R.sort(reverse=True)
G.sort(reverse=True)

L=R[:X]+G[:Y]+N
L.sort(reverse=True)
print sum(L[:X+Y])

Submission status: Accepted

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

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

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

p = p[:X]
q = q[:Y]
heapq.heapify(p)
heapq.heapify(q)

jdg = True

while r and jdg:
    hp = heapq.heappop(p)
    hq = heapq.heappop(q)
    rr = r.pop()
    if hp > hq:
        heapq.heappush(p, hp)
        if rr > hq:
            heapq.heappush(q, rr)
        else:
            heapq.heappush(q, hq)
            r.append(rr)
            jdg = False            
    else:
        heapq.heappush(q, hq)
        if rr > hp:
            heapq.heappush(p, rr)
        else:
            heapq.heappush(p, hp)
            r.append(rr)
            jdg = False
print(sum(p) + sum(q))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop

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

hP = []
hQ = []

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

for i in range(min(A, X)):
    heappush(hP, P[i])
for _ in range(X - A):
    heappush(hP, 0)

for i in range(min(B, Y)):
    heappush(hQ, Q[i])
for _ in range(Y - B):
    heappush(hQ, 0)

for r in R:
    hp = heappop(hP)
    hq = heappop(hQ)
    if r <= hp and r <= hq:
        heappush(hP, hp)
        heappush(hQ, hq)
    else:
        if hp <= hq:
            heappush(hP, r)
            heappush(hQ, hq)
        else:
            heappush(hP, hp)
            heappush(hQ, r)
            
print(sum(hP) + sum(hQ))

Submission status: Accepted

Solution code:
X, Y, A, B, C = map( int, input().split(" "))
scoreA = list( map(int, input().split(" ")))
scoreB = list( map(int, input().split(" ")))
scoreC = list( map(int, input().split(" ")))

scoreA.sort(reverse=True)
scoreB.sort(reverse=True)
scoreC.sort(reverse=True)

scoreAll = scoreA[:X] + scoreB[:Y] + scoreC

scoreAll.sort(reverse=True)

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

Submission status: Accepted

Solution code:
from sys import stdin
X,Y,A,B,C = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
Q = [int(x) for x in stdin.readline().rstrip().split()]
R = [int(x) for x in stdin.readline().rstrip().split()]

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

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

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

Submission status: Accepted

Solution code:
import sys
X, Y, A, B, C = sys.stdin.readline().split()
X = int(X)
Y = int(Y)
C = int(C)
scoreA = list(map(int, sys.stdin.readline().split()))
scoreB = list(map(int, sys.stdin.readline().split()))
scoreC = list(map(int, sys.stdin.readline().split()))
scoreA.sort(reverse=True)
scoreB.sort(reverse=True)
scoreC.sort(reverse=True)
scoreA = scoreA[:X]
scoreB = scoreB[:Y]
scoreAll = scoreA + scoreB + scoreC
scoreAll.sort(reverse=True)
print(sum(scoreAll[: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)
ate = p[0:X] +q[0:Y] + r
# print(ate)
# for i in range(len(r)):
#     if r[i] > ate[-1]:
#         ate[-1] = r[i]
#         ate.sort(reverse=True)
#     else:
#         break
# print(sum(ate))
ate.sort(reverse=True)
ate = ate[0:X+Y]
print(sum(ate))

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify

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)

R = p[:x]
B = q[:y]

heapify(R)
heapify(B)
for i in range(c):
  if min(R[0],B[0]) > r[i]:
    break
  if R[0] < B[0]:
    heappop(R)
    heappush(R,r[i])
  else:
    heappop(B)
    heappush(B,r[i])

print(sum(R) + sum(B))

Submission status: Accepted

Solution code:
import heapq

def main():
    X, Y, A, B, C, *Z = map(int, open(0).read().split())
    P = sorted(Z[:A], reverse=True)
    Q = sorted(Z[A: A + B], reverse=True)
    R = sorted(Z[A + B:], reverse=True)
    # print(X, Y, A, B, C, P, Q, R)
    q = []
    ans = 0
    for i in range(X):
        v = P[i]
        heapq.heappush(q, v)
        ans += v
    for i in range(Y):
        v = Q[i]
        heapq.heappush(q, v)
        ans += v
    for i in range(C):
        vr = R[i]
        v = heapq.heappop(q)
        if v < vr:
            heapq.heappush(q, vr)
            ans += vr - v
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
l_r=sorted(map(int,input().split()),reverse=True)[:x]
l_b=sorted(map(int,input().split()),reverse=True)[:y]
l_w=sorted(map(int,input().split()),reverse=True)

ans=[]
ans+=l_r
ans+=l_b
ans+=l_w

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

Submission status: Accepted

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