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:
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):
    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:', i)
        # print('x:', x)
        # print('y:', y)
        # print('i <= less_repeat:', i <= less_repeat)
        result += apple_list[1]
        print("result-{0}-{1}: {2}".format(i, 1, result))
    
print(result)

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):
    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:', i)
        # print('x:', x)
        # print('y:', y)
        # print('i <= less_repeat:', i <= less_repeat)
        result += apple_list[1]
        print("result-{0}-{1}: {2}".format(i, 1, result))
    
print(result)

Submission status: Wrong Answer

Solution code:
i=lambda:map(int,input().split())
s=sorted
x,y,*_=i()
print(sum(s(s(i())+s(i())[-y:]+s(i()))[-x-y:]))

Submission status: Wrong Answer

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

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

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

ans = sum((max_of_red+max_of_green+list_of_colorless)[:x+y])
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
*P, = map(int, input().split())
*Q, = map(int, input().split())
*R, = map(int, input().split())
P, Q = sorted(P, reverse=True), sorted(Q, reverse=True)
P, Q = P[:A], Q[:B]
ans = sum(sorted(P + Q + R, reverse=True)[:A + B])
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
*P, = map(int, input().split())
*Q, = map(int, input().split())
*R, = map(int, input().split())
P, Q, R = sorted(P), sorted(Q), sorted(R)
ans = 0
A -= 1; B -= 1; C -= 1
while X > 0 or Y > 0:
    a, b, c = P[A] if A >= 0 and X > 0 else 0, Q[B] if B >= 0 and Y > 0 else 0, R[C] if C >= 0 else 0
    if a >= max(b, c):
        ans += a; A -= 1
        X -= 1;
    elif b >= max(a, c):
        ans += b; B -= 1
        Y -= 1;
    else:
        ans += c; C -= 1
        if Y == 0: X -= 1
        elif X == 0: Y -= 1
        elif X > Y: X -= 1
        else: Y -= 1
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()
p = p[x-a:]
q = q[y-b:]

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

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]*(A+1)
P[1] = p[0]
for i in range(2,A+1):
    P[i] = P[i-1] + p[i-1]

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

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

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

    res.append(hp)
#print(res)
print(max(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())))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

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

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

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

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

    res.append(hp)
#print(res)
print(max(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())))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))#aこ
q=list(map(int,input().split()))#bko
r=list(map(int,input().split()))#cko
ans=0
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ac=x-1
bc=y-1
for i in range(c):
    #print("DFGH")
    if p[ac]<q[bc] and p[ac]<r[i]:
        p[ac]=r[i]
        ac-=1
    
    elif p[ac] >= q[bc] and q[bc]<r[i]:
        q[bc]=r[i]
        bc-=1
for i in range(x):
    ans+=p[i]    
for i in range(y):
    ans+=q[i]
print(ans)

Submission status: Wrong Answer

Solution code:
#from typing import MutableSequence

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)
  #print(p)
  #print(q)

  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
    
    #print(i)
    #print(p)
    #print(q)
      
  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:
#from typing import MutableSequence

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)
  print(p)
  print(q)

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

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

P = sorted(P)
Q = sorted(Q)
R = sorted(R)

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

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()],reverse = True)
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
q.extend(r)
q = sorted(q,reverse = True)

ans = sum(p[:x]) + sum(q[:y])

print(ans)

Submission status: Wrong Answer

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

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()
ps = [(-1*p[i], 'A') for i in range(a)]
qs = [(-1*q[i], 'B') for i in range(b)]
rs = [(-1*r[i], 'C') for i in range(c)]
que = ps + qs + rs
heapq.heapify(que)

countx = 0
county = 0
res = []
none = []

while countx != x or county !=y:
    temp = heapq.heappop(que)
    if temp[1] == 'A':
        if countx != x:
            countx += 1
            res.append(temp[0]*-1)
    if temp[1] == 'B':
        if county != y:
            county += 1
            res.append(temp[0]*-1)
    if temp[1] == 'C':
        none.append(temp[0]*-1)

while len(none)>0:
    tempa = res[x+y-1]
    tempb = none.pop(0)
    if tempa>=tempb:
        break
    bisect.insort_left(res, tempb)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
d = deque(r)
aka = x-1
midori = y-1
while True:
  siraberu = d.popleft()
  if min(p[aka],q[midori]) <= siraberu:
    if p[aka] <= q[midori]:
      p[aka] = siraberu
      aka = aka - 1
    else:
      q[midori] = siraberu
      midori = midori - 1
  if aka == -1 or midori == -1:
    break
  else:
    break
pd = deque(p)
qd = deque(q)
ans = 0
for i in range(x):
  ans = ans + pd.popleft()
for i in range(y):
  ans = ans + qd.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque

X,Y,A,B,C=map(int, sys.stdin.readline().split())
P=map(int, sys.stdin.readline().split())
Q=map(int, sys.stdin.readline().split())
R=map(int, sys.stdin.readline().split())
K=[X,Y]

S=[]
for p in P: S.append((p,0))
for q in Q: S.append((q,1))
for r in R: S.append((r,2))
S.sort(reverse=True)

ans=0
for value,kind in S:
    if kind in (0,1):   #0:赤 1:緑
        if K[kind]>0:
            ans+=value
            K[kind]-=1
    elif kind==2:       #2:無色
        if K[1]==0 and 0<K[0]:
            ans+=value
            K[0]-=1
        elif K[0]==0 and 0<K[1]:
            ans+=value
            K[1]-=1
        elif K[0]==0 and K[1]==0:
            pass
        elif K[1]<=K[0]:  #残りの数の多い方を減らす。赤の方が多いなら赤を減らす
            ans+=value
            K[0]-=1
        else:           #緑の方が多いなら緑を減らす
            ans+=value
            K[1]-=1

print ans

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()
ps = [(-1*p[i], 'A') for i in range(a)]
qs = [(-1*q[i], 'B') for i in range(b)]
rs = [(-1*r[i], 'C') for i in range(c)]
que = ps + qs + rs
heapq.heapify(que)

countx = 0
county = 0
res = []
none = []

while countx != x or county !=y:
    temp = heapq.heappop(que)
    if temp[1] == 'A':
        if countx != x:
            countx += 1
            res.append(temp[0]*-1)
    if temp[1] == 'B':
        if county != y:
            county += 1
            res.append(temp[0]*-1)
    if temp[1] == 'C':
        none.append(temp[0]*-1)

print(max(sum(res[:len(res)-len(none)]) + sum(none), sum(res[:len(res)-len(none)+1]) + sum(none[:len(none)-1])))

Submission status: Wrong Answer

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

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()
ps = [(-1*p[i], 'A') for i in range(a)]
qs = [(-1*q[i], 'B') for i in range(b)]
rs = [(-1*r[i], 'C') for i in range(c)]
que = ps + qs + rs
heapq.heapify(que)

countx = 0
county = 0
res = []
none = []

while countx != x or county !=y:
    temp = heapq.heappop(que)
    if temp[1] == 'A':
        if countx != x:
            countx += 1
            res.append(temp[0]*-1)
    if temp[1] == 'B':
        if county != y:
            county += 1
            res.append(temp[0]*-1)
    if temp[1] == 'C':
        none.append(temp[0]*-1)

print(sum(res[:len(res)-len(none)]) + sum(none))

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)
ate = p[0:X] +q[0:Y]
# print(ate)
for i in range(len(r)):
    if r[i] > ate[-1]:
        ate[-1] = r[i]
        ate.sort(reverse=True)
    else:
        break
print(sum(ate))

Submission status: Wrong Answer

Solution code:
#from typing import MutableSequence

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:
import sys
X, Y, A, B, C = sys.stdin.readline().split()
X = int(X)
Y = int(Y)
C = int(C)
scoreA = list(map(int, sys.stdin.readline().split()))
scoreB = list(map(int, sys.stdin.readline().split()))
scoreC = list(map(int, sys.stdin.readline().split()))
scoreA.sort(reverse=True)
scoreB.sort(reverse=True)
scoreC.sort(reverse=True)
scoreA = scoreA[:X-1]
scoreB = scoreB[:Y-1]
scoreAll = scoreA + scoreB + scoreC
scoreAll.sort(reverse=True)
print(sum(scoreAll[:X+Y-1]))

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)
ate = p[0:X] +q[0:Y]
# print(ate)
for x in r:
    if x > ate[-1]:
        ate[-1] = x
        ate.sort(reverse=True)
print(sum(ate))

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)
ate = p[0:X] +q[0:Y]
# print(ate)
for x in r:
    if x > ate[-1]:
        ate[-1] = x
        ate.sort()
print(sum(ate))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

p_l = np.array(list(map(int, input().split())))
q_l = np.array(list(map(int, input().split())))
r_l = np.array(list(map(int, input().split())))

p_l = np.sort(p_l)[::-1]
q_l = np.sort(q_l)[::-1]
r_l = np.sort(r_l)[::-1]

p_X = p_l[:X]
q_Y = q_l[:Y]

ans = np.sum(p_X) + np.sum(q_Y)

p_idx = 1
q_idx = 1
r_idx = 0

minus = 0
plus = 0

while True:
    p_cand = 100000000000
    q_cand = 100000000000
    r_cand = 0
    if p_idx <= p_X.shape[0]:
        p_cand = p_X[-p_idx]
    if q_idx <= q_Y.shape[0]:
        q_cand = q_Y[-q_idx]
    if r_idx >= r_l.shape[0]:
        break
    r_cand = r_l[r_idx]
    r_idx += 1

    if p_cand > q_cand:
        minus_cand = minus + q_cand
        q_idx += 1
    else:
        minus_cand = minus + p_cand
        p_idx += 1

    plus_cand = plus + r_cand

    if plus_cand > minus_cand:
        ans_cand = ans + plus_cand - minus_cand
        if ans_cand > ans:
            ans = ans_cand
            minus = minus_cand
            plus = plus_cand
        else:
            break
    else:
        break

print(int(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(' ')))

def fix(*arr):
    for a in arr:
        a.sort()
        a.reverse()
fix(p,q,r)

summ=0

m1= p[:min(a,x)]+r[:(min(x,len(r)))]
m1.sort()
m1.reverse()
summ+=sum(m1[:x])
m1=m1[x:]

m2=m1[:min(len(m1),y)]+q[:min(y,len(q))]
m2.sort()
m2.reverse()
summ+=sum(m2[:y])

print(summ)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

p_l = np.array(list(map(int, input().split())))
q_l = np.array(list(map(int, input().split())))
r_l = np.array(list(map(int, input().split())))

p_l = np.sort(p_l)[::-1]
q_l = np.sort(q_l)[::-1]
r_l = np.sort(r_l)[::-1]

p_X = p_l[:X]
q_Y = q_l[:Y]

ans = np.sum(p_X) + np.sum(q_Y)

p_idx = 1
q_idx = 1
r_idx = 0

minus = 0
plus = 0

while True:
    p_cand = 100000000000
    q_cand = 100000000000
    r_cand = 0
    if p_idx <= p_X.shape[0]:
        p_cand = p_X[-p_idx]
    if q_idx <= q_Y.shape[0]:
        q_cand = q_Y[-q_idx]
    if r_idx >= r_l.shape[0]:
        break
    r_cand = r_l[r_idx]
    r_idx += 1

    if p_cand > q_cand:
        minus_cand = minus + q_cand
        q_idx += 1
    else:
        minus_cand = minus + p_cand
        p_idx += 1

    plus_cand = plus + r_cand

    if plus_cand > minus_cand:
        minus = minus_cand
        plus = plus_cand
    else:
        break

print(int(ans - minus + plus))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
print(sum(sorted(sorted(list(map(int,input().split())))[:-x-1:-1] + list(map(int,input().split()))[:-y-1:-1] + list(map(int,input().split())))[:-x-y-1:-1]))

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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

    print(p_ind, q_ind, r_ind)
    if p_ind == -1 and q_ind == -1:
        break

    if q_ind == -1 or p[p_ind] < q[q_ind]:
        worst = p[p_ind]
        apple = "p"
    else:
        worst = q[q_ind]
        apple = "q"
    
    if worst <= r[r_ind]:
        r_ind += 1
        if apple == "p":
            p_ind -= 1
        else:
            q_ind -= 1
            
        if r_ind == C:
            break
    else:
        break

eat_p = p[:p_ind+1]
eat_q = q[:q_ind+1]
eat_r = r[:r_ind]

if p_ind == -1:
    eat_p = []
if q_ind == -1:
    eat_q = []

print(sum(eat_p) + sum(eat_q) + sum(eat_r))

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = list(map(int, input().split(" ")))
p_list = sorted(list(map(int, input().split(" "))))
q_list = sorted(list(map(int, input().split(" "))))
c_list = sorted(list(map(int, input().split(" "))))
pq_sum = 0
while(X > 0 or Y > 0):
    if X > 0:
        if C > 0:
            if p_list[-1] > c_list[-1]:
                pq_sum += p_list[-1]
                p_list.pop(-1)
                X -= 1
            else:
                if Y > 0:
                    if p_list[-1] < q_list[-1]:
                        pq_sum += c_list[-1]
                        c_list.pop(-1)
                        C -= 1
                        X -= 1
                else:
                    pq_sum += c_list[-1]
                    c_list.pop(-1)
                    C -= 1
                    X -= 1
        else:
            pq_sum += p_list[-1]
            p_list.pop(-1)
            X -= 1
    if Y > 0:
        if C > 0:
            if q_list[-1] > c_list[-1]:
                pq_sum += q_list[-1]
                q_list.pop(-1)
                Y -= 1
            else:
                if X > 0:
                    if q_list[-1] < p_list[-1]:
                        pq_sum += c_list[-1]
                        c_list.pop(-1)
                        C -= 1
                        Y -= 1
                else:
                    pq_sum += c_list[-1]
                    c_list.pop(-1)
                    C -= 1
                    Y -= 1
        else:
            pq_sum += q_list[-1]
            q_list.pop(-1)
            Y -= 1

print(pq_sum)

Submission status: Wrong Answer

Solution code:
#from typing import MutableSequence

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+1):
    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:
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_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:

    if p[p_ind] < q[q_ind]:
        worst = p[p_ind]
        apple = "p"
    else:
        worst = q[q_ind]
        apple = "q"
    
    if worst <= r[r_ind]:
        r_ind += 1
        if apple == "p":
            p_ind -= 1
        else:
            q_ind -= 1
            
        if r_ind == C:
            break
    else:
        break

eat_p = p[:p_ind+1]
eat_q = q[:q_ind+1]
eat_r = r[:r_ind]

print(sum(eat_p) + sum(eat_q) + sum(eat_r))

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)

red=0
green=0
no=0

while True:
    if (red>=a and green>=b) or no>=c:
        break
    if red<a and green<b:
        if max(p[red],q[green],r[no])==p[red]:
            red+=1
        elif max(p[red],q[green],r[no])==q[green]:
            green+=1
        else:
            if p[red]>q[green]:
                q[green]=r[no]
                green+=1
            else:
                p[red]=r[no]
                red+=1
            no+=1
    elif green>=b:
        if max(p[red],r[no])==p[red]:
            red+=1
        else:
            p[red]=r[no]
            red+=1
            no+=1
    elif red>=a:
        if max(q[green],r[no])==q[green]:
            green+=1
        else:
            q[green]=r[no]
            green+=1
            no+=1

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