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:
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    red = deque(sorted(map(int, input().split()), reverse=True))
    green = deque(sorted(map(int, input().split()), reverse=True))
    nocolor = deque(sorted(map(int, input().split()), reverse=True))

    INF = 10 ** 9 + 1
    times = A + B + C - (X + Y)
    for _ in range(times):
        red_num = len(red)
        green_num = len(green)
        nocolor_num = len(nocolor)

        if red_num and red_num + nocolor_num > X:
            r = red[-1]
        else:
            r = INF
        
        if green_num and green_num + nocolor_num > Y:
            g = green[-1]
        else:
            g = INF
        
        if nocolor_num:
            no = nocolor[-1]
        else:
            no = INF
        
        l = [no, r, g]
        idx = l.index(min(l))
        if idx == 0:
            nocolor.pop()
        if idx == 1:
            red.pop()
        if idx == 2:
            green.pop()

    print(sum(red) + sum(green) + sum(nocolor))
        
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    red = deque(sorted(map(int, input().split()), reverse=True))
    green = deque(sorted(map(int, input().split()), reverse=True))
    nocolor = deque(sorted(map(int, input().split()), reverse=True))

    INF = 10 ** 9 + 1
    times = A + B + C - (X + Y)
    for _ in range(times):
        red_num = len(red)
        green_num = len(green)
        nocolor_num = len(nocolor)
        if red_num and red_num + nocolor_num > X:
            r = red[-1]
        else:
            r = INF
        
        if green_num and green_num + nocolor_num > Y:
            g = green[-1]
        else:
            g = INF
        
        if nocolor_num:
            no = nocolor[-1]
        else:
            no = INF
        
        l = [r, g, no]
        idx = l.index(min(l))
        if idx == 0:
            red.pop()
        if idx == 1:
            green.pop()
        if idx == 2:
            nocolor.pop()

    print(sum(red) + sum(green) + sum(nocolor))
        
        

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)

p_ind = X-1
q_ind = Y-1
r_ind = 0

while 1:
    if r_ind == C:
        break

    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
    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]
            else:
                p[red]=r[no]
            no+=1
    elif green>=b:
        if max(p[red],r[no])==p[red]:
            red+=1
        else:
            p[red]=r[no]
            no+=1
    elif red>=a:
        if max(q[green],r[no])==q[green]:
            green+=1
        else:
            q[green]=r[no]
            no+=1

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

Submission status: Wrong Answer

Solution code:


def main():
    X,Y,A,B,C = [int(x) for x in input().split()]
    P = sorted([int(x) for x in input().split()])[-X:]
    Q = sorted([int(x) for x in input().split()])[-Y:]
    R = sorted([int(x) for x in input().split()])

    ip = 0
    iq = 0
    INF = 10**10
    ans = sum(P) + sum(Q)
    for r in R:
        p = INF if ip == X else P[ip]
        q = INF if iq == Y else Q[iq]
        if q <= p and q < r:
            ans = ans - q + r
        elif p <= q and p < r:
            ans = ans - p + r
    print(ans)


if __name__ == '__main__':
    main()

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]:
      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
    else:  
      if 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())
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)
v1=0
v2=0
def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    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
flag=1
ans=sum(a[0:X])+sum(b[0:Y])
while flag:
  t=c.pop(0)
  index1=bisect_right_reverse(a,t)
  index2=bisect_right_reverse(b,t)
  if index1>=X and index2>=Y:
    flag=0
    break
  else:
    if index2>=Y:
      poped=a[X-1]
      a.insert(index1,t)
      ans+=(t-poped)
    else:
      poped=b[Y-1]
      b.insert(index2,t)
      ans+=(t-poped)
    if len(c)==0:
      flag=0      
print(ans)

Submission status: Wrong Answer

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

s = []
p.sort()
q.sort()
r.sort()
r = [0 for i in range(x+y)] + r


while x>0 and y>0:
    if p[-1] >= q[-1] :
        if  p[-1]>= r[-1]:
            s.append(p.pop())
        else:
            s.append(r.pop()) 
        x -= 1
    else:
        if  q[-1]>= r[-1]:
            s.append(q.pop())
        else:
            s.append(r.pop()) 
        y -= 1
while x>0:
    if  p[-1]>= r[-1]:
        s.append(p.pop())
    else:
        s.append(r.pop()) 
    x -= 1
    
while y>0:
    if  q[-1]>= r[-1]:
        s.append(q.pop())
    else:
        s.append(r.pop()) 
    y -= 1    

        
print(sum(s))

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]:
      if q[Y-k-1] < p[X-j-1]:
        q[Y-k-1] = r[-i]
        j+=1
      else:
        p[X-j-1] = r[-i]
        k+=1
    else:  
      if 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:
#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]:
      if q[Y-k-1] < p[X-j-1]:
        q[Y-k-1] = r[i]
        j+=1
      else:
        p[X-j-1] = r[i]
        k+=1
    else:  
      if 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:
from collections import deque

x, y, a, b, c = map(int, input().split())
p = deque(sorted([int(i) for i in input().split()], reverse=True))
q = deque(sorted([int(i) for i in input().split()], reverse=True))
r = deque(sorted([int(i) for i in input().split()], reverse=True))
r.append(0)
ans = 0

while x > 0 and y > 0:
    if p[0] > q[0] and p[0] >= r[0]:
        ans += p.popleft()
        x -= 1
    elif p[0] > q[0] and p[0] < r[0]:
        ans += r.popleft()
        x -= 1
    elif q[0] > p[0] and q[0] >= r[0]:
        ans += q.popleft()
        y -= 1
    elif q[0] > p[0] and q[0] < r[0]:
        ans += r.popleft()
        y -= 1
    elif p[0] >= r[0]:
        ans += p.popleft() + q.popleft()
        x -= 1
        y -= 1
    else:
        ans += r.popleft()
        x -= 1
for i in range(x):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()
for i in range(y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl(), reverse = True)
y = sorted(inpl(), reverse = True)
z = sorted(inpl(), reverse = True)
apples = x + y + z
apples.sort(reverse = True)
print(sum(apples[:a+b]))

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)
  
  j=0
  k=0
  for i in range(C):
    if p[X-j-1] < r[i]:
      if q[Y-k-1] < p[X-j-1]:
        q[Y-k-1] = r[i]
        j+=1
      else:
        p[X-j-1] = r[i]
        k+=1
    else:  
      if 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:
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
for i in range(repeat):
    if i > x - 1:
        if green_apple_list[0] > transparent_apple_list[0]:
            result += green_apple_list[0]
            green_apple_list.remove(green_apple_list[0])
        else:
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
    elif i > y - 1:
        if red_apple_list[0] > transparent_apple_list[0]:
            result += red_apple_list[0]
            red_apple_list.remove(red_apple_list[0])
        else:
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
    else:
        if red_apple_list[0] > green_apple_list[0]:
            if green_apple_list[0] > transparent_apple_list[0]:
                result += red_apple_list[0]
                red_apple_list.remove(red_apple_list[0])
                result += green_apple_list[0]
                green_apple_list.remove(green_apple_list[0])
            elif red_apple_list[0] > transparent_apple_list[0]:
                result += red_apple_list[0]
                red_apple_list.remove(red_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
            else:
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
        else:
            if red_apple_list[0] > transparent_apple_list[0]:
                result += green_apple_list[0]
                green_apple_list.remove(green_apple_list[0])
                result += red_apple_list[0]
                red_apple_list.remove(red_apple_list[0])
            elif green_apple_list[0] > transparent_apple_list[0]:
                result += green_apple_list[0]
                green_apple_list.remove(green_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
            else:
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])

print(result)

Submission status: Wrong Answer

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

s = []
p.sort()
q.sort()
r.sort()
r = [0 for i in range(x+y)] + r


for i in range(x):
    if  p[-1]>= r[-1]:
        s.append(p.pop())
    else:
        s.append(r.pop())
    
for i in range(y):
    if  q[-1]>= r[-1]:
        s.append(q.pop())
    else:
        s.append(r.pop())
        
print(sum(s))

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)
v1=0
v2=0
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    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

def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    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
flag=1 
while flag:
  t=c.pop(0)
  index1=bisect_left_reverse(a,t)
  index2=bisect_left_reverse(b,t)
  if index1>=X and index2>=Y:
    ans=sum(a[0:X])+sum(b[0:Y])
    flag=0
    break
  else:
    if index2>=Y:
      a.insert(index1,t)
    else:
      b.insert(index2,t)
    if len(c)==0:
      ans=sum(a[0:X])+sum(b[0:Y])
      flag=0      
print(ans)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
CC = list(map(int, input().split()))
a = sorted(AA, reverse=True)
b = sorted(BB, reverse=True)
c = sorted(CC, reverse=True)

if X < A:
  del a[X:]

if Y < B:
  del b[Y:]
print(a)
print(b)

NEW = a + b + c
NEWnew = sorted(NEW, reverse=True)
del NEWnew[X+Y:]
K = sum(NEWnew)
print(K)

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()
q.sort()
r.sort()
r.reverse()
pp = p[a-x:]
qq = q[b-y:]
ll = pp+qq
ll.sort()
ans = sum(ll)
i = 0
for x in r:
    if ll[i] < x:
        ans += x-ll[i]
    else:
        break
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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a = a[:x]
b = b[:y]

a_index = -1
b_index = -1

a_sum = sum(a)
b_sum = sum(b)

a_target = a[a_index]
b_target = b[b_index]

for i in c:
  if a_target > i and b_target > i:
    # もうりんごの更新はされない
    break
    
  if a_target > b_target:
    b_index -= 1
    if b_index < -y:
      continue
      
    b_sum -= b_target
    b_target = b[b_index]
    b_sum += i
  else:
    a_index -= 1
    if a_index < -x:
      continue
      
    a_sum -= a_target
    a_target = a[a_index]
    a_sum += i
    
print(a_sum + b_sum)

Submission status: Wrong Answer

Solution code:
def merge(l):
    t = [-1]*len(l)
    if(len(l) == 2):
        if(l[0]<l[1]):
            t[1] = l[0]
            t[0] = l[1]
        else:
            t=l
    elif(len(l) > 2):
        x = merge(l[:len(l)//2])
        y = merge(l[len(l)//2:])
        p,q = 0,0
        for i in range(len(l)):
            if(p<len(x) and q<len(y)):
                if(x[p] > y[q]):
                    t[i] = x[p]
                    p += 1
                else:
                    t[i] = y[q]
                    q += 1
            elif(p == len(x)):
                t[i] = y[q]
                q += 1
            else:
                t[i] = x[p]
                p += 1
    else:
        t = l
    return t
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()))
a = [x,y,0]
P = merge(p)
Q = merge(q)
R = merge(r)
X = P[:x]
Y = Q[:y]
for i in range(x+y):
    if(a[2] == c):
        break
    else:
        if(X[a[0]-1] > Y[a[1]-1]):
            if(Y[a[1]-1] < R[a[2]]):
                a[1] -= 1
                a[2] += 1
            else:
                break
        else:
            if(X[a[0]-1] < R[a[2]]):
                a[0] -= 1
                a[2] += 1
            else:
                break
m = 0
for i in range(a[0]):
    m += P[i]
for i in range(a[1]):
    m += Q[i]
for i in range(a[2]):
    m += R[i]
print(m)

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()
q.sort()
r.sort()

xi = 0
yi = 0
ans = 0
for i in range(x+y):
    if xi < x:
        pi = p[-1]
    else:
        pi = 0
    if yi < y:
        qi = q[-1]
    else:
        qi = 0
    if len(r) > 0:
        ri = r[-1]
    else:
        ri = 0
    if pi > qi:
        if pi > ri:
            ans += p.pop()
        else:
            ans += r.pop()
        xi += 1
    else:
        if qi > ri:
            ans += q.pop()
        else:
            ans += r.pop()
        yi += 1

print(ans)

Submission status: Wrong Answer

Solution code:

X, Y, A, B, C = [int(s) for s in input().split()]
p_list = [int(s) for s in input().split()]
q_list = [int(s) for s in input().split()]
r_list = [int(s) for s in input().split()]

p_list = list(reversed(sorted(p_list)))
# print(p_list)
q_list = list(reversed(sorted(q_list)))
# print(q_list)
r_list = list(reversed(sorted(r_list)))
# print(r_list)

d_list = [p_list, q_list, r_list]
i_list = [0] * 3

temp_list = []
for i in range(3):
    temp_d = d_list[i][i_list[i]]
    temp_list.append(temp_d)

num_list = [X, Y]
limit_list = [A, B, C]

d = 0

while max(num_list) > 0:
    d_max = max(temp_list)
    d += d_max

    i = temp_list.index(d_max)
    # print(temp_list, i)

    if i == 0 or i == 1:
        num_list[i] -= 1
        if num_list[i] == 0:
            i_list[i] = limit_list[i]
    else:
        d_min = min(temp_list)
        i_ = temp_list.index(d_min)
        if num_list[i_] == 0:
            i_ = 1 - i_
        
        num_list[i_] -= 1
        if num_list[i_] == 0:
            temp_list[i_] = 0

    i_list[i] += 1
    temp_d = 0
    if i_list[i] < limit_list[i]:
        temp_d = d_list[i][i_list[i]]
    temp_list[i] = temp_d

print(d)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
CC = list(map(int, input().split()))
a = sorted(AA, reverse=True)
b = sorted(BB, reverse=True)
c = sorted(CC, reverse=True)

if X < A:
  del a[X:]
elif Y < B:
  del b[Y:]

NEW = a + b + c
NEWnew = sorted(NEW, reverse=True)
del NEWnew[X+Y:]
K = sum(NEWnew)
print(K)

Submission status: Wrong Answer

Solution code:
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0

    while countA < X and countB < Y and countC < C and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if r[k] == v:
            ans += r[k]
            countC += 1
            k += 1
        elif p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        elif q[j] == v:
            ans += q[j]
            countB += 1
            j += 1

    if countA + countB + countC == X+Y:
        return ans

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        return ans + sum(targ[:Y-countB-countC])

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        return ans + sum(targ[:X-countA-countC])

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    for k in range(countC+1):
        m = X-countA - k
        n = Y-countB - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            ans = max(ans, ans + pp[m] + qq[n])
    return ans


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

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
AA = list(map(int, input().split()))
BB = list(map(int, input().split()))
CC = list(map(int, input().split()))
a = sorted(AA, reverse=True)
b = sorted(BB, reverse=True)
c = sorted(CC, reverse=True)

if X < A:
  del a[X:]
elif Y < B:
  del b[Y:]
print(a)
print(b)

NEW = a + b + c
del NEW[X+Y:]
K = sum(NEW)
print(K)

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()))
lis=p[:x]+q[:y]+r
lis.sort(reverse=True)
ans=0
for i in range(x+y):
  ans+=lis[i]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list ,reverse=True)[:X+Y]
  print(sum(sum_list))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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()))
    pp = [(i, 'p') for i in p]
    qq = [(i, 'q') for i in q]
    rr = [(i, 'r') for i in r]
    ppqqrr = list(sorted((pp+qq+rr), key=lambda x:x[0], reverse=True))
    ans = 0
    XX = X
    YY = Y
    for d, c in ppqqrr:
        if XX<=0 and YY<=0:
            break
        if c=='p' and XX>0:
            ans += d
            XX -= 1
        elif c=='q' and YY>0:
            ans += d
            YY -= 1
        elif c=='r':
            if XX>0:
                ans += d
                XX -= 1
            elif YY>0:
                ans += d
                YY -= 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
print(nl)
x, y, a, b, c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
print(p)
print(q)
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(c):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))