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: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
rs = [int(i) for i in input().split()]
gs = [int(i) for i in input().split()]
ws = [int(i) for i in input().split()]

rs.sort(reverse=True)
gs.sort(reverse=True)
ws.sort(reverse=True)
weight = 0
rs_sum = [0]
gs_sum = [0]
ws_sum = [0]
s = 0
for i in range(a):
  s += rs[i]
  rs_sum.append(s)
s = 0
for i in range(b):
  s += gs[i]
  gs_sum.append(s)
s = 0
for i in range(c):
  s += ws[i]
  ws_sum.append(s)
if x < a:
  r = x
else:
  r = a
weight += rs_sum[r]
if y < b:
  g = y
else:
  g = b
weight += gs_sum[g]
if x + y > r + g:
  w = x + y - r - g
  weight += ws_sum[w]
else:
  w = 0
#print(r,g,w)
#print(weight)
while True:
  if r > -1 and w < c:
    if rs_sum[r] + ws_sum[w] < rs_sum[r-1] + ws_sum[w+1]:
      weight = rs_sum[r-1] + gs_sum[g] + ws_sum[w+1]
      r -= 1
      w += 1
      #print(r,g,w)
      #print(weight)
      continue
  if g > -1 and w < c:
    if gs_sum[g] + ws_sum[w] < gs_sum[g-1] + ws_sum[w+1]:
      weight = rs_sum[r] + gs_sum[g-1] + ws_sum[w+1]
      g -= 1
      w += 1
      #print(r,g,w)
      #print(weight)
      continue
  break
print(weight)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
rs = [int(i) for i in input().split()]
gs = [int(i) for i in input().split()]
ws = [int(i) for i in input().split()]

rs.sort(reverse=True)
gs.sort(reverse=True)
ws.sort(reverse=True)
weight = 0
if x > a:
  max_rs = a
else:
  max_rs = x
if y > b:
  max_gs = b
else:
  max_gs = y
for i in range(max_rs):
  weight += rs[i]
r = max_rs - 1
for i in range(max_gs):
  weight += gs[i]
g = max_gs - 1
if max_rs + max_gs < x + y:
  for i in range(x + y - max_rs - max_gs):
    weight += ws[i]
  w = x + y - max_rs - max_gs - 1
else:
  w = -1
#print(r,g,w)
#print(weight)
while True:
  if rs[r] < gs[g]:
    if r > -1 and w < c - 1:
      if rs[r] < ws[w + 1]:
        weight = weight + ws[w + 1] - rs[r]
        w += 1
        r -= 1
        #print(r,g,w)
        #print(weight)
        continue
  else:
    if g > -1 and w < c - 1:
      if gs[g] < ws[w + 1]:
        weight = weight + ws[w + 1] - gs[g]
        w += 1
        g -= 1
        #print(r,g,w)
        #print(weight)
        continue
  break
print(weight)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

pq = P[:X]
pq.extend(Q[:Y])
pq.sort()

cnt = -1
for i, r in enumerate(R):
    if bisect.bisect_left(pq, r) == 0:
        cnt = i
        break

ans = 0
if cnt == -1: 
    ans += sum(pq[C:])
    ans += sum(R)
else:
    ans += sum(pq[cnt:])
    ans += sum(R[:cnt])

print(ans)

Submission status: Wrong Answer

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

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

pq = sorted(p[:x] + q[:y])
r = sorted(r)
ans=0
j = r.pop()
for i in pq:
  if i < j:
    ans+=j
    j = 0
    if r:
      j = r.pop()
    else: break
  else:
    ans += i
    
print(ans)

Submission status: Wrong Answer

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()
B.sort()
C.sort()
ans = 0
if a < X:
    ans += sum(A)
    for i in range(X - a):
        ans += C[-1]
        C.pop()
else:
    for i in range(X):
        try:
            if A[-1] >= C[-1]:
                ans += A[-1]
                A.pop()
            else:
                ans += C[-1]
                C.pop()
        except:
            ans += A[-1]
            A.pop()
if b < Y:
    ans += sum(B)
    for i in range(X - b):
        ans += C[-1]
        C.pop()
else:
    for i in range(Y):
        try:
            if B[-1] >= C[-1]:
                ans += B[-1]
                B.pop()
            else:
                ans += C[-1]
                C.pop()
        except:
            ans += B[-1]
            B.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

x,y,a,b,c=list(map(int,input().split()))
p=sorted(list(map(int,input().split())),reverse=1)[:x]
q=sorted(list(map(int,input().split())),reverse=1)[:y]
r=sorted(list(map(int,input().split())),reverse=1)

while True:
    if (p[-1]>= r[0] and  q[-1] >= r[0] ):
        break
    if p[-1] >= q[-1] and q[-1] < r[0]:
        q = [r[0]]+q[:-1]
        r = r[1:]
    elif p[-1] < q[-1] and p[-1] < r[0]:
        q = [r[0]]+q[:-1]
        r = r[1:]
    if len(r)==0:
        break
print(sum(p)+sum(q))

Submission status: Wrong Answer

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)

cx = x-1
cy = y-1

while r:
    cz = r.pop()
    if p[cx] <= q[cy] and cz > p[cx]:
        p[cx] = cz
        cx -= 1
    elif p[cx] > q[cy] and cz > q[cy]:
        q[cy] = cz
        cy -= 1

print(sum(p[:x]) + sum(q[:y]))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x,y,a,b,c = inpm()
p = list(reversed(sorted(inpl())))
q = list(reversed(sorted(inpl())))
r = list(reversed(sorted(inpl())))
pp = x-1
qq = y-1
rr = 0
for i in range(c):
    if rr > c:
        break
    if pp > 0 and p[pp] >= q[qq] and r[i] > p[pp]:
        pp -= 1
        rr += 1
        continue
    elif qq > 0 and r[i] > q[qq]:
        qq -= 1
        rr += 1
        continue
    else:
        break

ans = sum(p[:pp+1]) + sum(q[:qq+1]) + sum(r[:rr])
print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p_l = sorted(list(map(int, input().split())), reverse=True)[:x]
q_l = sorted(list(map(int, input().split())), reverse=True)[:y]
p_l = sorted(p_l + q_l, reverse=True)
r_l = sorted(list(map(int, input().split())), reverse=True)

idx = 0
for r in r_l:
    while idx < len(p_l):
        if p_l[idx] < r:
            p_l[idx] = r
            idx += 1
            continue 
        idx += 1

print(sum(p_l))

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c = map(int,input().split())
p = [[int(x),1] for x in input().split()]
q = sorted([int(x) for x in input().split()])[::-1]
r = [[int(x),0] for x in input().split()]
pr = sorted(p+r)[::-1]
ps = sum([x[0] for x in pr[:x]])
qt = q[:y]
qs = sum(qt)
heapq.heapify(qt)
ans = 0
for item in pr[::-1]:
  if item[1]:
    continue
  if item[0]>(m:=heapq.heappop(qt)):
    if item[0]>=pr[x-1][0]:
      ps -= item[0]
    qs -= m
    qs += item[0]
    heapq.heappush(qt,item[0])
  else:
    heapq.heappush(qt,m)
  ans = max(ans, ps+qs)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
X, Y, A, B, C = map(int, input().split())
Av = list(map(int, input().split()))
Bv = list(map(int, input().split()))
Cv = list(map(int, input().split()))
heapq.heapify(Av)
heapq.heapify(Bv)
heapq.heapify(Cv)
for i in range(A-X):
    heapq.heappop(Av)
for i in range(B-Y):
    heapq.heappop(Bv)
if C > X+Y:
    for i in range(C-(X+Y)):
        heapq.heappop(Cv)
    NotTake = X+Y
else:
    NotTake = C
C = NotTake
for _ in range(NotTake):
    if X > 0:
        Amin = heapq.heappop(Av)
    else:
        Amin = 1000000001
    if Y > 0:
        Bmin = heapq.heappop(Bv)
    else:
        Bmin = 1000000001
    if C > 0:
        Cmin = heapq.heappop(Cv)
    else:
        Cmin = 1000000001
    if X > 0 and Amin == min(Amin, Bmin, Cmin):
        heapq.heappush(Bv, Bmin)
        heapq.heappush(Cv, Cmin)
        X -= 1
    elif Y > 0 and Bmin == min(Bmin, Cmin):
        heapq.heappush(Av, Amin)
        heapq.heappush(Cv, Cmin)
        Y -= 1
    elif C > 0:
        heapq.heappush(Av, Amin)
        heapq.heappush(Bv, Bmin)
        C -= 1
    else:
        break
print(sum(Av)+sum(Bv)+sum(Cv))

Submission status: Wrong Answer

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())))[::-1]

i=j=k=0
oi=0
while i<c:
  if x>j and y>k:
    if p[j]>=q[k] and q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
    elif p[j]<q[k] and p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif x>i:
    if p[j]<r[i]:
      p[j]=r[i]
      j+=1
      i+=1
  elif y>i:
    if q[k]<r[i]:
      q[k]=r[i]
      k+=1
      i+=1
  if oi==i:break
  oi=i
  
print(sum(p)+sum(q))

Submission status: Wrong Answer

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

xy = p[:x] + q[:y]
xy.sort()
j=0
for i in range(x+y):
    while j<c:
        if xy[i] < r[j]:
          xy[i] = r[j]
          j+=1
          break
        else:
           j+=1
print(sum(xy))

Submission status: Wrong Answer

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

xy = p[:x] + q[:y]
xy.sort()
j=0
for i in range(x+y):
    if j==c: break
    if xy[i]<r[j]:
        xy[i]=r[j]
        j+=1
    else:
        break
print(sum(xy))

Submission status: Wrong Answer

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
for _ in range(X):
    if not R or P[-1] > R[-1]:
        ans += P.pop()
    else:
        ans += R.pop()

for _ in range(Y):
    if not R or Q[-1] > R[-1]:
        ans += Q.pop()
    else:
        ans += R.pop()

print(ans)

Submission status: Wrong Answer

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
for _ in range(X):
    if not P:
        ans += R.pop()
    elif not R:
        ans += P.pop()
    elif P[-1] > R[-1]:
        ans += P.pop()
    else:
        ans += R.pop()

for _ in range(Y):
    if not Q:
        ans += R.pop()
    elif not R:
        ans += Q.pop()
    elif Q[-1] > R[-1]:
        ans += Q.pop()
    else:
        ans += R.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
list_C = list(map(int, input().split()))
z = len(list_C)
list_A.sort(reverse=True)
list_B.sort(reverse=True)
list_C.sort(reverse=True)

list_AS = [0]
list_BS = [0]
list_CS = [0]

k = 0
for i in list_A:
    k += i
    list_AS.append(k)

k = 0
for i in list_B:
    k += i
    list_BS.append(k)

k = 0
for i in list_C:
    k += i
    list_CS.append(k)

ans = 0
for i in range(min(z, x+y)+1):
    for j in range(max(0, x-i), x+1):
        cnt = list_CS[i] + list_AS[j] + list_BS[max(0, x+y-i-j)]
        ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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)

sa = sum(p[:X])
sb = sum(q[:Y])

p.append(float('inf'))
q.append(float('inf'))


ans = sa + sb
nr = 0
np = X-1
nq = Y-1
while nr < len(r):
  if r[nr] <= min(p[np], q[nq]):
    break
  elif p[np] > r[nr] > q[nq]:
    ans += r[nr] - q[nq]
    nr += 1
    nq -= 1
    continue
  else:
    ans += r[nr] - p[np]
    nr += 1
    np -= 1
    continue
  
print(ans)

Submission status: Wrong Answer

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)

sa = sum(p[:X])
sb = sum(q[:Y])

p.append(float('inf'))
q.append(float('inf'))


ans = sa + sb
nr = 0
np = X-1
nq = Y-1
while nr < len(r):
  if r[nr] <= min(p[np], q[nq]):
    break
  elif p[np] > r[nr] > q[nq]:
    ans += r[nr] - q[nq]
    nr += 1
    nq -= 1
    continue
  else:
    ans += r[nr] - p[np]
    nr += 1
    nq -= 1
    continue
  
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappush, heappop
x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
s = 0
for i in range(x):
  s += li_p[i]
for i in range(y):
  s += li_q[i]
li_p.extend(li_q)
li_p.sort(reverse=True)
s_p = [0] * (a+b+1)
s_r = [0] * (c+1)
for i in range(1,a+b):
  s_p[i] = s_p[i-1] + li_p[i]
for i in range(1, c):
  s_r[i] = s_r[i-1] + li_r[i]
delta = -1
zz = -1
for i in range(min(c, a+b)):
  k = s_r[i] - s_p[i]
  if k > delta:
    zz = i
    delta = k
print(s+delta)

Submission status: Wrong Answer

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)

dp = [[0 for i in range(Y+1)] for j in range(X+1)]
dp[0][0] = sum(p[:X]) + sum(q[:Y])
max_ = dp[0][0]
maxr = 0
finish=0
for i in range(X+1):
  if finish==1:break
  for j in range(1,Y+1):
    if i+j-1 > len(r)-1:
      finish=1
      break
    else:
      if X-i <= len(p)-1 and Y-j <= len(q)-1:
        dp[i][j] = max(dp[i-1][j]+r[i-1+j]-p[X-i], dp[i][j-1]+r[i-1+j]-q[Y-j])
      elif X-i <= len(p)-1:
        dp[i][j] = dp[i-1][j]+r[i-1+j]-p[X-i]
      elif Y-j <= len(q)-1:
        dp[i][j] = dp[i][j-1]+r[i-1+j]-q[Y-j]
      else:
        finish=1
        break
      if dp[i][j] > max_:
        max_ = dp[i][j]
        maxr = i+j
      elif i+j >= maxr:break
print(max_)

Submission status: Wrong Answer

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)

dp = [[0 for i in range(Y+1)] for j in range(X+1)]
dp[0][0] = sum(p[:X]) + sum(q[:Y])
max_ = dp[0][0]
finish=0
for i in range(X+1):
  if finish==1:break
  for j in range(1,Y+1):
    if i+j-1 > len(r)-1:
      finish=1
      break
    else:
      if X-i <= len(p)-1 and Y-j <= len(q)-1:
        dp[i][j] = max(dp[i-1][j]+r[i-1+j]-p[X-i], dp[i][j-1]+r[i-1+j]-q[Y-j])
      elif X-i <= len(p)-1:
        dp[i][j] = dp[i-1][j]+r[i-1+j]-p[X-i]
      elif Y-j <= len(q)-1:
        dp[i][j] = dp[i][j-1]+r[i-1+j]-q[Y-j]
      else:
        finish=1
        break
      if dp[i][j] > max_:
        max_ = dp[i][j]
print(max_)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
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)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansq[eq]<ansp[ep]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
        else:
          break
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
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)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
print(ans,sum(ansp),sum(ansq))
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
    print(ans,ep,eq)
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
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)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
for i in range(c):
    if ep<0 and eq<0:
        break
    if ansp[ep]<ansq[eq]:
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    else:
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


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

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

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

i = j = k = 0
while True:
  dprint(i, j, k)
  dprint(P[i], Q[j], R[k])
  if min(P[i], Q[j]) < R[k]:
    if P[i] <= Q[j]:
      P[i] = R[k]
      i += 1
    else:
      Q[j] = R[k]
      j += 1
    k += 1
  else:
    i += 1
    j += 1

  if i >= X and j >= Y or k >= C:
    break
  i = min(i, X - 1)
  j = min(j, Y - 1)
  k = min(k, C - 1)

dprint(P, Q)
print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(u)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(v)
        if t[1] == 'r':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(u)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(v)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)

Submission status: Wrong Answer

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
q = 0
r = 0
red = 0
green = 0
ans = 0
while red < X and green < Y:
    if P[p] < Q[q]:#Pが小さいとき
        #Red
        if P[p] < R[r] and r != c-1: 
            ans += R[r]
            if r != c-1:
                r += 1
        else:
            ans += P[p]
            p += 1
        red += 1
        #Green
        ans += Q[q]
        q += 1
        green += 1
    else:
        #Red
        ans += P[p]
        p += 1
        red += 1
        #Green
        if Q[q] < R[r] and r != c-1:
            ans += R[r]
            if r != c-1:
                r += 1
        else:
            ans += Q[q]
            q += 1
        green += 1
if red < X:
    while red < X:
        if P[p] < R[r] and r!= c-1: 
            ans += R[r]
            if r != c-1:
                r += 1
        else:
            ans += P[p]
            p += 1
        red += 1
else:
    while green < Y:
        if Q[q] < R[r] and r != c-1:
            ans += R[r]
            if r != c-1:
                r += 1
        else:
            ans += Q[q]
            q += 1
        green += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.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)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s

for i in range(min(len(l), C)):
    ans = max(ans, s-l[i]+r[i])

print(ans)

Submission status: Wrong Answer

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

Ap.sort()
Bq.sort()

print(Ap[A-X:] + Bq[B-Y:] + Cr)

print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[C:]))

Submission status: Wrong Answer

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

Ap.sort()
Bq.sort()

print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[A+B+C-2*X-2*Y:]))

Submission status: Wrong Answer

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

Ap.sort()
Bq.sort()

print(Ap[A-X:] + Bq[B-Y:] + Cr)

print(sum(sorted(Ap[A-X:] + Bq[B-Y:] + Cr)[A+B+C-2*X-2*Y:]))

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,y,a,b,c = readInts()
p = list(sorted(readInts(),reverse=True))
q = list(sorted(readInts(),reverse=True))
r = list(sorted(readInts(),reverse=True))
po = 0
idx = -1
cy = 0
i = 0
while i < min(x,len(r)):
    if cy == x:
        break
    if r[i] > p[po]:
        idx = i+1
        i += 1
    else:
        po += 1
    cy += 1
ans = 0
if idx == -1:
    ans += sum(p[:x])
else:
    ans += sum(p[:x-idx]) + sum(r[:idx])
    r = r[idx:]
#print('-',ans)
po = 0
idx = -1
cy = 0
i = 0
while i < min(y,len(r)):
    if cy == y:
        break
    if r[i] > q[po]:
        idx = i+1
        i += 1
    else:
        po += 1
    cy += 1
#print(idx)
if idx == -1:
    ans += sum(q[:y])
else:
    ans += sum(q[:y-idx]) + sum(r[:idx])
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c =map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1]
q = sorted(list(map(int,input().split())))[::-1]
r = sorted(list(map(int,input().split())))
su = 0
p1 = p[:x]
q1 = q[:y]
su += sum(p1) + sum(q1)



a = True
while a and len(r)!=0 and len(p)!=0 and len(q)!=0:
  if p[-1]<q[-1] and p[-1]<r[-1]:
    p0 = p.pop()
    r0 = r.pop()
    su += r0-p0
  elif q[-1]<p[-1] and q[-1]<r[-1]:
    q0 = q.pop()
    r0 = r.pop()
    su += r0-q0
  else:
    a = False
    
if len(p)==0 and len(r)!=0:
  a = True
  while a and len(r)!=0 and len(q)!=0:
    if q[-1]<r[-1]:
      q0 = q.pop()
      r0 = r.pop()
      su += r0-q0
    else:
      a = False
      
if len(q)==0 and len(r)!=0:
  a = True
  while a and len(r)!=0 and len(p)!=0:
    if p[-1]<r[-1]:
      p0 = p.pop()
      r0 = r.pop()
      su += r0-p0
    else:
      a = False
    
print(su)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = 2, 2, 4, 4, 4

prr = [11, 12, 13, 14]
qrr = [21, 22, 23, 24]
rcc = [1, 2, 3, 4]


X, Y, A, B, C = 2, 2, 2, 2, 2
prr = [8, 6]
qrr = [9, 1]
rcc = [2, 1]


X, Y, A, B, C = 1, 2, 2, 2, 1
prr = [2, 4]
qrr = [5, 1]
rcc = [3]

X, Y, A, B, C = map(int,input().split())
prr = list(map(int,input().split()))
qrr = list(map(int,input().split()))
rcc = list(map(int,input().split()))

trr = []


for pr in prr:
    trr.append({"type": "A", "value": pr})

for qr in qrr:
    trr.append({"type": "B", "value": qr})

for rc in rcc:
    trr.append({"type": "C", "value": rc})


arr = sorted(trr,key=lambda x:-x["value"])


result = 0
for ar in arr:

    if X == 0 and Y == 0:
        break

    if ar["type"] == "A":
        if X > 0:
            X -= 1
            result += ar["value"]
            continue


    if ar["type"] == "B":
        if Y > 0:
            Y -= 1
            result += ar["value"]
            continue

    if ar["type"] == "C":
        if X > 0:
            X -= 1
            result += ar["value"]
            continue

        if Y > 0:
            Y -= 1
            result += ar["value"]
            continue


print(result)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = 2, 2, 4, 4, 4

prr = [11, 12, 13, 14]
qrr = [21, 22, 23, 24]
rcc = [1, 2, 3, 4]


X, Y, A, B, C = 2, 2, 2, 2, 2
prr = [8, 6]
qrr = [9, 1]
rcc = [2, 1]


X, Y, A, B, C = 1, 2, 2, 2, 1
prr = [2, 4]
qrr = [5, 1]
rcc = [3]

X, Y, A, B, C = map(int,input().split())
prr = list(map(int,input().split()))
qrr = list(map(int,input().split()))
rcc = list(map(int,input().split()))

trr = []


for pr in prr:
    trr.append({"type": "A", "value": pr})

for qr in qrr:
    trr.append({"type": "B", "value": qr})

for rc in rcc:
    trr.append({"type": "C", "value": rc})


arr = sorted(trr,key=lambda x:-x["value"])


result = 0
for ar in arr:

    if X == 0 and Y == 0:
        break

    if X > 0:
        if ar["type"] == "A":
            X -= 1
            result += ar["value"]
            continue

    if Y > 0:
        if ar["type"] == "B":
            Y -= 1
            result += ar["value"]
            continue

    if ar["type"] == "C":
        if X > 0:
            X -= 1
            result += ar["value"]
            continue

        if Y > 0:
            Y -= 1
            result += ar["value"]
            continue


print(result)

Submission status: Wrong Answer

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