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:
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(lambda x :-int(x), input().split()))

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

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

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

heapq.heapify(r)
ans = 0

for i in range(x+y) :
    #print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]

print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
n = a+b+c
ar = list(map(int,input().split()))
br = list(map(int,input().split()))
cr = list(map(int,input().split()))
ls = []
for i in ar:
  ls.append([i,1])
for i in br:
  ls.append([i,2])
for i in cr:
  ls.append([i,3])
ls.sort(reverse = True)
nx = 0
ny = 0
cnt = 0
res = 0
for item in ls:
  if item[1]==x:
    if nx==x: continue
    nx+=1
  if item[1]==y:
    if ny==y: continue
    ny+=1
  res+=item[0]
  cnt+=1
  if cnt==x+y:
    break
print(res)

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

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

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if len(aX) == 0:
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()


print(sumX + sumY)

Submission status: Wrong Answer

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

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(float('inf'))
q.append(float('inf'))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=0

tmpx,tmpy=x,y
for i in range(c):
    if r[i]>p[tmpx] and r[i]>q[tmpy]:
        if p[tmpx-1]>q[tmpy-1]:
            q.append(r[i])
            tmpy-=1
        else:
            p.append(r[i])
            tmpx-=1
    elif r[i]>p[tmpx]:
        p.append(r[i])
        tmpx-=1
    elif r[i]>q[tmpy]:
        q.append(r[i])
        tmpy-=1
p.sort()
q.sort()
# print(p)
# print(q)
lp,lr=len(p),len(r)
ans=0
for i in range(x):
    ans+=p[-2-i]
for i in range(y):
    ans+=q[-2-i]
print(ans)

Submission status: Wrong Answer

Solution code:
def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)
if non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
print(sum(ans))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
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[0:x]
q[0:y]

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

ans = 0

for i in range(x + y):
  ans += p[i]
  
print("{}".format(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)

num = []
n1 = 0
n2 = 0
n3 = 0
flg_0 = False
flg_1 = False
for i in range(x+y):
    if flg_0 is False:
        u = p[min(a-1, n1)]
    else:
        u = 0
    if flg_1 is False:
        uu = q[min(b-1, n2)]
    else:
        uu = 0
    uuu = r[min(c-1, n3)]
    if max(u, uu, uuu) == u:
        num.append(u)
        n1 += 1
    elif max(u, uu, uuu) == uu:
        num.append(uu)
        n2 += 1
    else:
        num.append(uuu)
        n3 += 1
    if n1 >= x:
        flg_0 = True
    if n2 >= y:
        flg_1 = True
    if (n1 + n2 + n3) == (x + y):
        break

print(sum(num))

Submission status: Wrong Answer

Solution code:
import numpy as np

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)

#initial

x_ans = p[:X]
y_ans = q[:Y]

ans = sum(x_ans) + sum(y_ans)

x_mark = -1
y_mark = -1
for i in range(len(r)):
    
    if -x_mark > len(x_ans):
        x_mark +=len(x_ans)
    if -y_mark > len(y_ans):
        y_mark +=len(y_ans)
        
    del_x = r[i] - x_ans[x_mark]
    del_y = r[i] - y_ans[y_mark]
    if (del_x<=0) & (del_y<=0):
        break
    else:
        if del_x>=del_y:
            ans = ans +del_x 
            x_mark-=1
        else:
            ans = ans +del_y
            y_mark-=1
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy

x , y , a , b , c = map(int,input().split())
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))

pa.sort()
pb.sort()
pc.sort()

if x <= a:
    pa = pa[a-x::]
    a = x
if y <= b:
    pb = pb[b-y::]
    b = y
if x+y <= c:
    print(c-x+y)
    pc = pc[(c-(x+y))::]
    c = x+y

ain = 0
bin = 0
cin = 0

total = 0
for times in range(x+y):
    if ain < a:
        ta = pa[a-1 - ain ]
    else:
        ta = 0
    
    if bin < b :
        tb = pb[b-1 - bin]
    else:
        tb = 0
    
    if cin < c:
        tc = pc[c-1 - cin]
    else:
        tc = 0
    
    if tb <= ta and tc <= ta:
        total += ta
        ain += 1
    elif ta <= tb and tc <= tb:
        total += tb
        bin += 1
    elif ta <= tc and tb <= tc:
        total += tc
        cin += 1
    else:
        print("error")

print(total)

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

for j in range(b):
    tmp.append(q[j])

for k in range(len(r)):
    tmp.append(r[k])

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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]



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()]
ans = 0


p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
pp = p[:X]
qq = q[:Y]
pp.sort()
qq.sort()
for i in range(len(r)):
  pp.append(0)
  qq.append(0)
r.append(0)
count = 0
pidx = 0
qidx = 0
ridx = 0

while True:
  #print(pidx, qidx, ridx)
  if(pidx>=X and qidx>=Y):
    break
  if(pp[pidx]<=qq[qidx] and pp[pidx]<r[ridx] and pidx<X):
    ans += r[ridx]
    ridx += 1
    pidx += 1
  elif(qq[qidx]<=pp[pidx] and qq[qidx]<r[ridx] and qidx<Y):
    ans += r[ridx]
    ridx += 1
    qidx += 1
  else:
    if(pidx>=X):
      ans += qq[qidx]
      qidx += 1
    elif(qidx>=Y):
      ans += pp[pidx]
      pidx += 1
    else:
      ans += pp[pidx] + qq[qidx]
      pidx += 1
      qidx += 1



print(ans)

Submission status: Wrong Answer

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

for i in range(min(x+y, len(r))):
  if p[x-1] >= q[y-1] and r[0] > q[y-1]:
    heapq.heapify(q)
    heapq.heappop(q)
    q.append(r[0])
    r.pop(0)
  elif q[y-1] >= p[x-1] and r[0] > p[x-1]:
    heapq.heapify(p)
    heapq.heappop(p)
    p.append(r[0])
    r.pop(0)

print(sum(p) + sum(q))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
white=sorted(list(map(int,input().split())),reverse=True)
eat_list=sorted(red[:x]+green[:y])
for i in range(min(len(eat_list),len(white))):
  if eat_list[i]<white[i]:
    eat_list[i]=white[i]
  else:
    break
print(eat_list)
print(sum(eat_list))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=(int(i) for i in input().split())
p=sorted([int(i) for i in input().split()])
q=sorted([int(i) for i in input().split()])
r=sorted([int(i) for i in input().split()])
l=sorted(p+q+r)
print(sum(l[a+b+c-x-y:]))

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
redq = deque(red[:x])
ans = 0
oisr = 0
lgw = len(gw)
#print(red,gw,gwrui)
for i in range(1,x+1):
    oisr += redq.popleft()
    temp = oisr
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
def qsort(a: int, left: int, right: int) -> None:
  pl=left
  pr=right
  x=a[(left+right)//2]

  while pl<=pr:
    while a[pl]>x: pl+=1    # 降順
    while a[pr]<x: pr-=1
    if pl <= pr:
      a[pl],a[pr] = a[pr],a[pl]
      pl+=1
      pr-=1
  
  if left  <pr: qsort(a,left,pr)
  if right >pl: qsort(a,pl,right)
    
def quick_sort(a: int) -> None:
  qsort(a,0,len(a)-1)
  
if __name__ == '__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()))

  quick_sort(p)
  quick_sort(q)
  quick_sort(r)

  j=0
  k=0
  for i in range(C):
    if p[X-j-1] < r[i] and q[Y-k-1] < r[i]:
      if q[Y-k-1] < p[X-j-1]:
        q[Y-k-1]=r[i]
        k+=1
      else:
        p[X-j-1]=r[i]
        j+=1
    elif p[X-j-1] < r[i]:
      p[X-j-1]=r[i]
      j+=1
    elif q[Y-k-1] < r[i]:
      q[Y-k-1] = r[i]
      k+=1
  
  x=0
  for i in range(X):
    x+=p[i]
  for i in range(Y):
    x+=q[i]
  print(x)

Submission status: Wrong Answer

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

def mergef(a,b):
    c = []
    h = j = 0
    while j<len(a) and h<len(b):
        if a[j]>b[h]:
            c.append(a[j])
            j+=1
        else:
            c.append(b[h])
            h+=1
    if j==len(a):
        for i in b[h:]:
            c.append(i)
    else:
        for i in a[j:]:
            c.append(i)
    return c

def merge_sortf(lists):
    if len(lists) <= 1:
        return lists
    middle = int(len(lists)/2)
    left = merge_sortf(lists[:middle])
    right = merge_sortf(lists[middle:])
    return mergef(left,right)


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

pm=merge_sortf(p)
qm=merge_sortf(q)
rm=merge_sortf(r)

k=0;i=X-1;j=Y-1
while i>=0 and j>=0 and k<C:
    if min((pm[i]-rm[k]),(qm[j]-rm[k])) < 0 :
        if pm[i]>=qm[j] :
            qm[j]=rm[k]
            j=j-1
        elif pm[i]<qm[j]:
            pm[i]=rm[k]
            i=i-1
    elif min((pm[i]-rm[k]),(qm[j]-rm[k])) > 0:
        break
    k=k+1

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

Submission status: Wrong Answer

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

def mergef(a,b):
    c = []
    h = j = 0
    while j<len(a) and h<len(b):
        if a[j]>b[h]:
            c.append(a[j])
            j+=1
        else:
            c.append(b[h])
            h+=1
    if j==len(a):
        for i in b[h:]:
            c.append(i)
    else:
        for i in a[j:]:
            c.append(i)
    return c

def merge_sortf(lists):
    if len(lists) <= 1:
        return lists
    middle = int(len(lists)/2)
    left = merge_sortf(lists[:middle])
    right = merge_sortf(lists[middle:])
    return mergef(left,right)


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

pm=merge_sortf(p)
qm=merge_sortf(q)
rm=merge_sortf(r)

k=0;i=X-1;j=Y-1
while i>=0 and j>=0 and k<C:
    if min((pm[i]-rm[k]),(qm[j]-rm[k])) < 0 :
        if pm[i]>qm[j] :
            qm[j]=rm[k]
            j=j-1
        elif pm[i]<qm[j]:
            pm[i]=rm[k]
            i=i-1
    elif min((pm[i]-rm[k]),(qm[j]-rm[k])) > 0:
        break
    else:
        if pm[i]>qm[j]:
            j=j-1
        else:
            i=i-1
    k=k+1

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

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=0
for i in range(x):
    if len(r)==0:
        _p=heapq.heappop(p)
        ans-=_p
        continue
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<=_r:
        ans-=_p
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(p,_p)

q.extend(r)
heapq.heapify(q)
for i in range(y):
    _q=heapq.heappop(q)
    ans-=_q
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=0
for i in range(x):
    if len(r)==0:
        _p=heapq.heappop(p)
        ans-=_p
        continue
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<_r:
        ans-=_p
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(p,_p)

q.extend(r)
heapq.heapify(q)
for i in range(y):
    _q=heapq.heappop(q)
    ans-=_q
print(ans)

Submission status: Wrong Answer

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

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

t=p[0:x] + q[0:y] + r
t.sort()
print(sum(t[0:(x+y)]))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
red = [int(x) for x in input().split()]
green = [int(x) for x in input().split()]
red.sort(reverse=True)
green.sort(reverse=True)
candidates = [int(x) for x in input().split()] + red[x:] + green[:y]
candidates.sort(reverse=True)
print(sum(candidates[:x+y]))

Submission status: Wrong Answer

Solution code:
import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans=sorted(ans)
i = 0
result = 0
for A in ans:
    if A < r[i]:
        result += r[i]
        if i < len(r) - 1:
            i += 1
        continue
    result += A
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()))
p.sort(reverse=True)
q.sort(reverse=True)
p.sort(reverse=True)

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

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

Submission status: Wrong Answer

Solution code:
# Problem E - Red and Green Apples

# input
X, Y, A, B, C = map(int, input().split())
red_list = list(map(int, input().split())) # red apple
green_list = list(map(int, input().split())) # green apple
transparent_list = list(map(int, input().split())) # transparent apple

# initialization
red_list = sorted(red_list, reverse=True)
green_list = sorted(green_list, reverse=True)
transparent_list = sorted(transparent_list, reverse=True)
ans_list = []

# count
while X>0 or Y>0:
    red = -1
    green = -1
    toumei = -1
    if C>=0:
        toumei = transparent_list[0]
    max_v = 0

    if X>0:
        red = red_list[0]

    if Y>0:
        green = green_list[0]

    # max value check
    if red>=green and red>=toumei:
        max_v = red_list.pop(0)
        X -= 1
    elif green>=red and green>=toumei:
        max_v = green_list.pop(0)
        Y -= 1
    else:
        # min value check
        if X>0 and Y>0:
            if red<=green:
                max_v = transparent_list.pop(0)
                X -= 1
                C -= 1
                red_list.pop(0)
            else:
                max_v = transparent_list.pop(0)
                Y -= 1
                C -= 1
                green_list.pop(0)
        elif X>0:
            max_v = transparent_list.pop(0)
            X -= 1
            C -= 1
            red_list.pop(0)
        else:
            max_v = transparent_list.pop(0)
            Y -= 1
            C -= 1
            green_list.pop(0)

    # list insert
    ans_list.append(max_v)

# output
ans = sum(ans_list)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans=sorted(ans)
#print(ans)
i = 0
result = 0
for A in ans:
    if A < r[i]:
        result += r[i]
        if i < c - 1:
            i += 1
        continue
    result += A
print(result)

Submission status: Wrong Answer

Solution code:
import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans=sorted(ans,reverse=True)
i = 0
result = 0
for A in ans:
    if A < r[i]:
        result += r[i]
        if i < c - 1:
            i += 1
        continue
    result += A
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()))

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

a = p[:X]
b = q[:Y]
ans = 0
ridx = 0

for i in range(X):
    if ridx == C:
        break
    if a[i] >= r[ridx]:
        pass
    else:
        a[i] = r[ridx]
        ridx += 1
        

for i in range(Y):
    if ridx == C:
        break
    if b[i] >= r[ridx]:
        pass
    else:
        b[i] = r[ridx]
        ridx += 1

print(sum(a)+sum(b))

Submission status: Wrong Answer

Solution code:
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())))
ans=sum(a[0:X])+sum(b[0:Y])
m_a=a[X-1]
m_b=b[Y-1]
while len(c)!=0:
  t=c.pop(0)
  if t<=m_a and t<=m_b:
    pass
  elif t>m_a and t<=m_b:
    ans+=(t-m_a)
    m_a=t
  elif t<=m_a and t>m_b:
    ans+=(t-m_b)
    m_b=t
  else:
    if t-m_a>=t-m_b:
      ans+=(t-m_a)
      m_a=t
    else:
      ans+=(t-m_b)
      m_b=t
print(ans)

Submission status: Wrong Answer

Solution code:
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)
ans=sum(a[0:X])+sum(b[0:Y])
m_a=a[X-1]
m_b=b[Y-1]
while len(c)!=0:
  t=c.pop(0)
  if t<=m_a and t<=m_b:
    break
  elif t>m_a and t<=m_b:
    ans+=(t-m_a)
    m_a=t
  elif t<=m_a and t>m_b:
    ans+=(t-m_b)
    m_b=t
  else:
    if t-m_a>=t-m_b:
      ans+=(t-m_a)
      m_a=t
    else:
      ans+=(t-m_b)
      m_b=t
print(ans)

Submission status: Wrong Answer

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]

value = 0

for indx in range(X+Y):
    if (pList[0] > qList[0]) and (pList[0] > rList[0]):
        value += pList[0]
        pList.pop(0)

        if len(pList) == 0:
            pList.append(-1)

    elif (qList[0] > pList[0]) and (qList[0] > rList[0]):
        value += qList[0]
        qList.pop(0)

        if len(qList) == 0:
            qList.append(-1)

    # else:
    #     value += rList[0]
    #     rList.pop(0)

    #     if len(rList) == 0:
    #         rList.append(-1)


print(value)

Submission status: Wrong Answer

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

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

x, y, a, b, c = map(int, input().split())
p = rl()
q = rl()
r = rl()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
res = 0
i = j = k = 0
cp = cq = 0
while cp < x or cq < y:
    if cp < x:
        if k < a and r[k] > p[i]:
            res += r[k]
            k += 1
        else:
            res += p[i]
            i += 1
        cp += 1
    if cq < y:
        if k < b and r[k] > q[j]:
            res += r[k]
            k += 1
        else:
            res += q[j]
            j += 1
        cq += 1
print(res)

Submission status: Wrong Answer

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()
qList.sort()
rList.sort()

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

value = 0

for indx in range(X+Y):
    if (pList[len(pList)-1] > qList[len(qList)-1]) and (pList[len(pList)-1] > rList[len(rList)-1]):
        value += pList[len(pList)-1]
        pList.pop(len(pList)-1)

        if len(pList) == 0:
            pList.append(-1)

    elif (qList[len(qList)-1] > pList[len(pList)-1]) and (qList[len(qList)-1] > rList[len(rList)-1]):
        value += qList[len(qList)-1]
        qList.pop(len(qList)-1)

        if len(qList) == 0:
            qList.append(-1)

    else:
        value += rList[len(rList)-1]
        rList.pop(len(rList)-1)

        if len(rList) == 0:
            rList.append(-1)


print(value)

Submission status: Wrong Answer

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]

value = 0

for indx in range(X+Y):
    if (pList[0] > qList[0]) and (pList[0] > rList[0]):
        value += pList[0]
        pList.pop(0)

        if len(pList) == 0:
            pList.append(-1)

    elif (qList[0] > pList[0]) and (qList[0] > rList[0]):
        value += qList[0]
        qList.pop(0)

        if len(qList) == 0:
            qList.append(-1)

    else:
        value += rList[0]
        rList.pop(0)

        if len(rList) == 0:
            rList.append(-1)


print(value)

Submission status: Wrong Answer

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]

value = 0

for indx in range(X+Y):
    if (pList[0] > qList[0]) and (pList[0] > rList[0]):
        value += pList[0]
        pList.pop(0)

        if len(pList) == 0:
            pList.append(-1)

    elif (qList[0] > pList[0]) and (qList[0] > rList[0]):
        value += qList[0]
        qList.pop(0)

        if len(qList) == 0:
            qList.append(-1)

    elif (rList[0] > pList[0]) and (rList[0] > qList[0]):
        value += rList[0]
        rList.pop(0)

        if len(rList) == 0:
            rList.append(-1)


print(value)

Submission status: Wrong Answer

Solution code:
input_1st = input()
input_2nd = input()
input_3rd = input()
input_4th = input()

split_input_1st = input_1st.split()
red_apple_list = sorted(list(map(int, input_2nd.split())), reverse=True)
green_apple_list = sorted(list(map(int, input_3rd.split())), reverse=True)
transparent_apple_list = sorted(list(map(int, input_4th.split())), reverse=True)

x = int(split_input_1st[0])
y = int(split_input_1st[1])
a = int(split_input_1st[2])
b = int(split_input_1st[3])
c = int(split_input_1st[4])

result = 0

repeat = x if x > y else y
less_repeat = (x if x < y else y) - 1
for i in range(repeat):
    # print('----\ni:', i)
    # print('x:', x)
    # print('y:', y)
    # print('repeat:', repeat)
    # print('less_repeat:', less_repeat)
    
    if i > x - 1:
        red_apple_list = []
    elif i > y - 1:
        green_apple_list = []
        
    apple_list = []
    if len(red_apple_list) == 0:
        red_apple_list.append(0)
    if len(green_apple_list) == 0:
        green_apple_list.append(0)
    if len(transparent_apple_list) == 0:
        transparent_apple_list.append(0)
    
    red_apple_happiness = red_apple_list[0]
    green_apple_happiness = green_apple_list[0]
    transparent_apple_happiness = transparent_apple_list[0]
    
    # print('red_apple_happiness:', red_apple_happiness)
    # print('green_apple_happiness:', green_apple_happiness)
    # print('transparent_apple_happiness:', transparent_apple_happiness)
    
    apple_list.append(red_apple_happiness)
    red_apple_list.remove(red_apple_happiness)
    
    apple_list.append(green_apple_happiness)
    green_apple_list.remove(green_apple_happiness)
    
    if red_apple_happiness < transparent_apple_happiness or green_apple_happiness < transparent_apple_happiness:
        apple_list.append(transparent_apple_happiness)
        transparent_apple_list.remove(transparent_apple_happiness)
    
    apple_list = sorted(apple_list, reverse=True)
    # print('apple_list:', apple_list)
    result += apple_list[0]
    # print('result-{0}-{1}: {2}'.format(i, 0, result))
    if i <= less_repeat:
        # print('i <= less_repeat:', i <= less_repeat)
        result += apple_list[1]
        # print('result-{0}-{1}: {2}'.format(i, 1, result))
    
print(result)