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:
from heapq import heapify, heappush, heappop

X, Y, A, B, C = map(int, input().split())
Ps = list(map(int, input().split()))
Qs = list(map(int, input().split()))
Rs = list(map(int, input().split()))

Ps.sort(reverse=True)
Qs.sort(reverse=True)
Rs.sort(reverse=True)

PQRed = Ps[:X]
PQGreen = Qs[:Y]
sumRed = sum(PQRed)
sumGreen = sum(PQGreen)
heapify(PQRed)
heapify(PQGreen)
#print('PQRed:', PQRed)
#print('PQGreen:', PQGreen)
ans = sumNow = sumRed + sumGreen
#print('sumNow:', sumNow)
for R in Rs:
#    print('\n##### R:', R)
    r = PQRed[0]
    g = PQGreen[0]
#    print('r:', r, '/ g:', g)
    if r <= g:
        d = heappop(PQRed)
        heappush(PQRed, R)
    else:
        d = heappop(PQGreen)
        heappush(PQGreen, R)
    if R <= d:
        break
    sumNow += R-d
#    print('sumNow:', sumNow, '/ d:', d)
    if sumNow > ans:
        ans = sumNow

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 = 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:
from functools import lru_cache

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)

red = P[:X]
green = Q[:Y]
best = sum(red) + sum(green)

for x in R:
    smaller = None
    if not red and not red:
        break
    elif red and green:
        if red[-1] < green[-1]:
            smaller = red
        else:
            smaller = green
    elif red:
        smaller = red
    elif green:
        smaller = green
    else:
        assert False

    if smaller[-1] < x:
        best -= smaller.pop()
        best += x
print(best)

Submission status: Accepted

Solution code:
#E - Red and Green Apples
X,Y,A,B,C= map(int, input().split())
a =sorted(list(map(int, input().split())),reverse=True)
b =sorted(list(map(int, input().split())),reverse=True)
c =sorted(list(map(int, input().split())),reverse=True)
DP_a =a[:X]
DP_b =b[:Y]
DP_a.extend(DP_b)
DP_a.extend(c)
ans = sorted(DP_a,reverse=True)
print(sum(ans[:X+Y]))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.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()))
    p.sort()
    q.sort()
    r.sort()
    p = p[-X:]
    q = q[-Y:]
    use = p+q+r
    use.sort(reverse=True)
    print(sum(use[:X+Y]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in p[:X]:
    r.append(i)
for j in q[:Y]:
    r.append(j)
r.sort(reverse=True)
print(sum(r[:X + Y]))

Submission status: Accepted

Solution code:
# E Red and Green Apples
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]

ans = p + q + r

ans.sort(reverse=True)

ans = ans[:x+y]

print(sum(ans))

Submission status: Accepted

Solution code:
x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
A.sort()
B.sort()
C.sort(reverse=True)
A=A[a-x:]
B=B[b-y:]

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,y,a,b,c = LI()
    p = LI()
    q = LI()
    r = LI()
    p.sort(reverse = True)
    q.sort(reverse = True)
    s = p[:x]+q[:y]+r
    s.sort(reverse = True)
    print(sum(s[:x+y]))
    return

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

Submission status: Accepted

Solution code:
LMIIS = lambda: list(map(int,input().split()))
X,Y,*e = LMIIS()
P = LMIIS()
Q = LMIIS()
R = LMIIS()
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq as hq

x,y,a,b,c=map(int,input().split())
R=list(reversed(sorted(map(int,input().split()))))
G=list(reversed(sorted(map(int,input().split()))))
N=list(reversed(sorted(map(int,input().split()))))
A=[]
hq.heapify(A)
for i in range(x):
    hq.heappush(A,-R[i])
for i in range(y):
    hq.heappush(A,-G[i])
for n in N:
    hq.heappush(A,-n)

ans=0
for i in range(x+y):
    ans-=hq.heappop(A)
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()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y]
px = 0
qx = 0
for i in range(C):
    if px == len(p) and qx == len(q):
        break
    elif px == len(p):
        if min(q[qx],r[i])==q[qx]:
            q[qx] =r[i]
            qx += 1
        else:
            break
    elif qx == len(q):
        if min(p[px],r[i])==p[px]:
            p[px] =r[i]
            px += 1
        else:
            break
    else:
        if min(p[px],q[qx],r[i]) ==p[px]:
            p[px] = r[i]
            px +=1
        elif min(p[px],q[qx],r[i]) ==q[qx]:
            q[qx] = r[i]
            qx += 1
        else:
            break
print(sum(p)+sum(q))

Submission status: Accepted

Solution code:
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pa =  [0] + list(itertools.accumulate(p))
qa =  [0] + list(itertools.accumulate(q))
p = [INF] + p
q = [INF] + q
red = X
green = Y
t = 0
pl = 0
while p[red] < r[t] or q[green] < r[t]:
    pl += r[t]
    t += 1
    if p[red] < q[green] :
        red -= 1
    else:
        green -= 1
    if t >=C or (green ==0 and red ==0): break
print (pa[red] + qa[green] + pl)

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)

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

ans = sum(apples[:x+y])
print(ans)

Submission status: Accepted

Solution code:
#!python3.4
# -*- coding: utf-8 -*-
# abc160/abc160_e
import sys
from collections import deque


s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, Y, A, B, C = i2nn()
    p = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:X])
    q = deque(sorted(map(int, i2s().split(' ')), reverse=True)[:Y])
    r = deque(sorted(map(int, i2s().split(' '))))
    s = 0
    while p or q:
        if p and q:
            t = p if p[-1] < q[-1] else q
        else:
            t = p if p else q
        if r and t[-1] < r[-1]:
            t.pop()
            s += r.pop()
        else:
            r.clear()
            s += t.pop()
    print(s)
    return

main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
from copy import copy

X, Y, A, B, C = [int(n) for n in 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()
q.sort()

apple = p[-X:] + q[-Y:] + r
apple.sort()

print(sum(apple[-X-Y:]))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

X, Y, A, B, C = map(int, input().split())
cand = []
p = list(map(int, (input().split())))
p.sort(reverse=True)
cand.extend(p[:X])
q = list(map(int, (input().split())))
q.sort(reverse=True)
cand.extend(q[:Y])
r = list(map(int, (input().split())))
cand.extend(r)
cand.sort(reverse=True)
ans = sum(cand[:X+Y])
print(ans)

Submission status: Accepted

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

P = sorted(p, reverse=True)
Q = sorted(q, reverse=True)
l = P[:x] + Q[:y] + r
L = sorted(l, reverse=True)

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    X, Y, A, B, C = input_nums()
    P = input_nums()
    Q = input_nums()
    R = input_nums()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort()

    P = sorted(P[:X])
    Q = sorted(Q[:Y])
    res = []
    res = P + Q + R
    res.sort(reverse=True)
    print(sum(res[:X+Y]))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
def main():

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

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




if __name__ == '__main__':
    # main()
    print(main())

Submission status: Accepted

Solution code:
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, = map(int, input().split())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

for k in range(1,x+1):
    r.append(p[-k])
for v in range(1,y+1):
    r.append(q[-v])

rs = sorted(r)

for i in range(1,x+y+1):
    ans += rs[-i]
print(str(ans))

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache

sys.setrecursionlimit(10 ** 9)

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[0:X]
q = q[0:Y]

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

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

Submission status: Accepted

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

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

v.sort()

w=0
for i in range(min(x+y,c)):
    if v[i]<r[w]:
        v[i]=r[w]
        w+=1

print(sum(v))

Submission status: Accepted

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
P = deque(sorted(list(map(int,input().split())),reverse=True)[:x])
Q = deque(sorted(list(map(int,input().split())),reverse=True)[:y])
R = deque(sorted(list(map(int,input().split())),reverse=True))
p = P.pop()
q = Q.pop()
r = R.popleft()
ans = 0

while p < r or q < r:
    ans += r
    if len(R) != 0:   
        r = R.popleft()
    else:
        r = 0
    if p < q:
        if len(P) != 0:   
            p = P.pop()
        else:
            p = 10**10
    else:
        if len(Q) != 0:   
            q = Q.pop()
        else:
            q = 10**10
            
ans += sum(P)+sum(Q)
if p != 10**10:
    ans += p
if q != 10**10:
    ans += q
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  x, y, na, nb, nc = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0,
  
  s = 0
  while True:
    if sum([ca, cb, cc]) == x+y:
      break
      
    a = la[ca] if na > ca and ca < x else -1
    b = lb[cb] if nb > cb and cb < y else -1
    c = lc[cc] if nc > cc            else -1
            
    if a >= b and a >= c:
      s += a
      ca += 1
      continue
      
    if b >= a and b >= c:
      s += b
      cb += 1
      continue
      
    if c >= b and c >= a:
      s += c
      cc += 1
      
  print(s)

if __name__=='__main__':
  main()

Submission status: Accepted

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

p = sorted(map(int, input().split()), reverse=True)[:X]
q = sorted(map(int, input().split()), reverse=True)[:Y]
r = list(map(int, input().split()))

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

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

Submission status: Accepted

Solution code:
from functools import lru_cache

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)

red = P[:X]
green = Q[:Y]
best = sum(red) + sum(green)

for x in R:
    a1, a2 = red, green
    if not a1 and not a2:
        break
    if not a1:
        a1 = a2
    if a1 and a2 and a1[-1] > a2[-1]:
        a1, a2 = a2, a1
    if a1[-1] < x:
        best -= a1.pop()
        best += x
print(best)

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
l.sort(reverse=True)
print(sum(l[: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()))

sortp = sorted(p)[::-1]
sortq = sorted(q)[::-1]
redpoints = sortp[:x]
greenpoints = sortq[:y]
sortedpoints = sorted(redpoints+greenpoints+r)[::-1]
print(sum(sortedpoints[:x+y]))

Submission status: Accepted

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

reds.sort(reverse=True)
greens.sort(reverse=True)
nos.sort(reverse=True)

bests = reds[:X]+greens[:Y]+nos
bests.sort(reverse=True)
print(sum(bests[: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)

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 = [int(x) for x in input().split()]
p.sort(reverse=True)
p = p[:x]

q = [int(x) for x in input().split()]
q.sort(reverse=True)
q = q[:y]
r = [int(x) for x in input().split()]
r.sort(reverse=True)

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

Submission status: Accepted

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

if __name__ == "__main__":
    X, Y, A, B, C = MI()
    p = LI()
    p.sort(reverse=True)
    q = LI()
    q.sort(reverse=True)
    pq = p[:X] + q[:Y] + LI()
    pq.sort(reverse=True)
    print(sum(pq[:X+Y]))

Submission status: Accepted

Solution code:
(x,y,*_),*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:
# coding: utf-8
# Your code here!
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.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

r_len = min(X+Y, len(R))
V = P[:X] + Q[:Y] + R[:r_len]
V.sort(reverse=True)

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

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 = 0
z = 0
while x + y + z > 0:
    if p[-1] > max(q[-1], r[-1]) and x:
        x -= 1
        ans += p.pop()
        if not p or not x:
            p.append(-1)
    elif q[-1] > r[-1] and y:
        y -= 1
        ans += q.pop()
        if not q or not y:
            q.append(-1)
    else:
        z -= 1
        ans += r.pop()
        if not r:
            r.append(-1)
print(ans)

Submission status: Accepted

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]


sum_a = x_a + x_b + s_c
sum_a.sort(reverse = True)
sum_a = sum_a[0:x+y]
print(sum(sum_a))

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)

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

Submission status: Accepted

Solution code:
# 2020/03/28
# AtCoder Beginner Contest 160 - E

# 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()))
p.append(-1000000000)
q.append(-1000000000)
r.append(-1000000000)

# Init
ans = 0

# Sort
p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()

anslist = list()

# Make List
for i in range(x):
    anslist.append(p[i])

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

anslist.extend(r)

anslist.sort()
anslist.reverse()

for i in range(x+y):
    ans = ans + anslist[i]

# Output
print(ans)

Submission status: Accepted

Solution code:
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))
p.sort()
q.sort()
t = p[:X] + q[:Y] + r

heapq.heapify(t)

ans = 0
for _ in range(X+Y):
    ap = heapq.heappop(t)
    ans -= ap

print(ans)

Submission status: Accepted

Solution code:
import sys,math,copy,queue,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
X,Y,A,B,C = LI()
p = LI()
q = LI()
r = LI()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pa =  [0] + list(itertools.accumulate(p))
qa =  [0] + list(itertools.accumulate(q))
p = [INF] + p
q = [INF] + q
red = X
green = Y
t = 0
pl = 0
while p[red] < r[t] or q[green] < r[t]:
    pl += r[t]
    t += 1
    if red == 0:
        green -= 1
    elif green == 0:
        red -= 1

    elif p[red] < q[green] :
        red -= 1
    else:
        green -= 1
    if t >=C or (green ==0 and red ==0): break
print (pa[red] + qa[green] + pl)

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 = list(map(int, input().split()))
for i in range(x): r.append(p[a-i-1])
for i in range(y): r.append(q[b-i-1])
r.sort()
print(sum(r[len(r)-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)

p = p[0:x]
q = q[0:y]

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

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

Submission status: Accepted

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

plist = sorted(list(map(int, input().split())))[::-1][:X]
qlist = sorted(list(map(int, input().split())))[::-1][:Y]
rlist = sorted(list(map(int, input().split())))
plist.extend(qlist)
plist.extend(rlist)

print(sum(sorted(plist, reverse=True)[:X + Y]))

Submission status: Accepted

Solution code:
import heapq

X, Y, A, B, C = map(int, input().split())
p = list(map(lambda x:int(x)*(-1), input().split()))
q = list(map(lambda x:int(x)*(-1), input().split()))
r = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(p)
heapq.heapify(q)

for _ in range(X):
    r.append(heapq.heappop(p))
for _ in range(Y):
    r.append(heapq.heappop(q))
heapq.heapify(r)

ans = 0
for _ in range(X+Y):
    ans += (-1) * heapq.heappop(r)
print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-


def main():
  x, y, na, nb, nc = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0
  
  lx = la[:x] + lb[:y] + lc
  lx.sort(reverse=True)
  print(sum(lx[:x+y]))

if __name__=='__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
X,Y,A,B,C = list(map(int,input().split()))
p =list(map(int,input().split()))
p.append(0)
p.sort(reverse = True)
# print(p)
q=list(map(int,input().split()))
q.append(0)
q.sort(reverse = True)
r = list(map(int,input().split()))
r.append(0)
r.sort(reverse = True)
 
p = np.array(p)
q = np.array(q)
r = np.array(r)
kotae = 0
a,b,c = 0,0,0
d,e =False,False
for i in range(X+Y):
    if a >= X:
        if d == False:
            p = p* 0
            d = True
    if b >= Y:
        if e == False:
            q = q*0
            e = True
    if p[a] > q[b]:
        if p[a] > r[c]:
            kotae += p[a]
            a +=1
        else:
            kotae += r[c]
            c += 1
    else:
        if q[b] > r[c]:
            kotae += q[b]
            b +=1
        else:
            kotae += r[c]
            c += 1
    # print(kotae)
print(kotae)

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    swap = True
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                idx ^= 1
                if si[idx] <= 0:
                    break
                swap = False
            elif not swap:
                continue
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

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)
ABC = A[:x] + B[:y] + C
ABC.sort(reverse=True)
print(sum(ABC[:(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 = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    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]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
x,y,a,b,c = list(map(int, input().split()))
r = sum(sorted(sorted(list(map(int, input().split())), reverse = True)[:x] + sorted(list(map(int, input().split())), reverse = True)[:y] + list(map(int, input().split())), reverse = True)[:x+y])
# g = sorted(list(map(int, input().split())), reverse = True)[:y]
# c = sorted(list(map(int, input().split())))
# rc = 0
# gc = 0
# for i in range(x+y):
#     if(r[0]<g[0]):
#         if(rc<x):
#             if(r[0]<)
print(r)