Problem: 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.

Submission attempts (in order):
from sys import stdin
input = 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()))
red = sorted(p)
green = sorted(q)
no = sorted(r)
red.reverse()
green.reverse()
no.reverse()

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r])
if c_g != Y:
  ans += sum(green[0:Y-c_g])
print(ans)

from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)

from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
new = p + q + r
new = sorted(new, reverse = True)
print(sum(new[0:X+Y]))

from sys import stdin
input = stdin.readline
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)
  
  
    
  
  
  
  
  
  
  

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()) for _ in range(X))
q = list(map(int, input().split()) for _ in range(Y))
r = list(map(int, input().split()))
new = p + q + r
new = sorted(new, reverse = True)
print(sum(new[0:X+Y]))


from sys import stdin
input = 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()))
red = sorted(p, reverse = True)
green = sorted(q, reverse = True)
no = sorted(r, reverse = True)

c_r = 0
c_g = 0
c_n = 0
ans = 0

while (c_r < X) and (c_g < Y) and (c_n < C):
  tmp = min(red[X-c_r-1],green[Y-c_g-1])
  if tmp > no[c_n]:
    break
  else:
    ans += no[c_n]
    c_n += 1
    if red[X-c_r] > green[Y-c_g]:
      c_g += 1
    else:
      c_r += 1

if c_r == X:
  while (c_n < C) and (c_g < Y):
    if green[c_g] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_g += 1
      c_n += 1
elif c_g == Y:
  while (c_n < C) and (c_r < X):
    if red[c_r] > no[c_n] :
      break
    else:
      ans += no[c_n]
      c_r += 1
      c_n += 1

if c_r != X:
  ans += sum(red[0:X-c_r-1])
if c_g != Y:
  ans += sum(green[0:Y-c_g-1])
print(ans)


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()
p.reverse()
q.sort()
q.reverse()
new = p[0:X] + q[0:Y] + r
new.sort()
new.reverse()
print(sum(new[0:X+Y]))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted