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: Time Limit Exceeded

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 = []
green = []

# for i in range(x):
#     red.append(p[i])
# for j in range(y):
#     green.append(q[j])

# print(p[:x])
# print(q[:y]
# print(red)
# print(green)

all = p[:x] + q[:y]
all.sort()

# for i in range(len(all)):
#     if min(r) > all[i]:
#         print(i)
#         break
# if i >= len(r):
#     ans = all[len(r) + 1:] + r
# else:
#     ans = all[i + 1:] + r[:i]

for mushoku in r:
    for i in range(len(all)):
        if mushoku > all[i]:
            all[i] = mushoku


print(sum(all))

Submission status: Time Limit Exceeded

Solution code:
x,y,a,b,c=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort(reverse=True)
A=A[a-x:]
B=B[b-y:]

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)

Submission status: Time Limit Exceeded

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

eat = []

# 食べる
p.sort(reverse=True)
if X > A:
    eat.extend(p)
else:
    eat.extend(p[:X])

q.sort(reverse=True)
if Y > B:
    eat.extend(q)
else:
    eat.extend(q[:Y])
loss = X+Y - len(eat)

# 足りない分を補充する
while loss > 0:
    r.sort(reverse=True)
    eat.append(r.pop(0))    
    loss -= 1

# rの方が大きいものがあれば入れ替える
eat.sort()
for i in range(len(eat)):
    r.sort(reverse=True)
    if len(r) != 0 and eat[i] < r[0]:
        eat[i] = r.pop(0)
    else:
        break

print(sum(eat))

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left

X, Y, A, B, C = [int(i) for i in input().split()]
P = sorted([int(i) for i in input().split()])[-X:]
Q = sorted([int(i) for i in input().split()])[-Y:]
R = sorted([int(i) for i in input().split()])[::-1]
i = 0
j = 0
k = 0
while(True):
    try:
        if P[j] > Q[k]:
            if Q[k] < R[i]:
                insort_left(Q, R[i])
                k += 1
                i += 1
                continue
        else:
            if P[j] < R[i]:
                insort_left(P, R[i])
                j += 1
                i += 1
                continue
        break
    except IndexError:
        break
print(sum(P[j:]) + sum(Q[k:]))

Submission status: Time Limit Exceeded

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

cr = 0
cg = 0
p = p[:x]
q = q[:y]
for i in range(c-1, -1, -1):
    x = p.pop()
    y = q.pop()
    z = min(x, y)
    if x < y:
        q.append(y)
        if r[i] > z:
            p.insert(0, r[i])
        else:
            p.append(x)
    else:
        p.append(x)
        if r[i] > z:
            q.insert(0, r[i])
        else:
            q.append(y)
print(sum(p) + sum(q))

Submission status: Time Limit Exceeded

Solution code:
a=input().split()
b=input().split()
c=input().split()
d=input().split()
er=int(a[0])
eg=int(a[1])
ar=int(a[2])
ag=int(a[3])
ac=int(a[4])
dr=[int(i) for i in b]
dg=[int(i) for i in c]
dc=[int(i) for i in d]
t=[]
answer=0
for i in dr:
	t.append(i)
for i in dg:
	t.append(i)
for i in dc:
	t.append(i)
while eg!=0 or er!=0:
	temp=max(t)
	t.remove(temp)
	if temp in dr and er!=0:
		answer+=temp
		er-=1
	elif temp in dg and eg!=0:
		answer+=temp
		eg-=1
	elif temp in dc and er!=0:
		answer+=temp
		er-=1
	elif temp in dc and eg!=0:
		answer+=temp
		eg-=1
print(answer,end="")

Submission status: Time Limit Exceeded

Solution code:
def a():
    S = input()

    if S[3] == S[2] and S[4] == S[5]:
        print("Yes")
    else:
        print("No")


def b():
    X = int(input())
    y_500 = (X // 500) * 1000
    y_5 = ((X - (y_500 / 2)) // 5) * 5
    print(int(y_500 + y_5))


def c():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    max_A_d = -1
    for i in range(len(A)):
        A_d = 0
        if i == 0:
            A_d = K - (A[-1] - A[0])
        else:
            A_d = (A[i] - A[i - 1])
        if max_A_d < A_d:
            max_A_d = A_d
    d = K - max_A_d
    print(d)


def d():
    N, X, Y = map(int, input().split())
    print()


def e():
    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-X,q-Y
    X_e = p[0:X]
    Y_e = q[0:Y]
    X_e.sort()
    Y_e.sort()
    while True:
        if not r:
            break
        if X_e[0] > r[0] and Y_e[0] > r[0]:
            break

        if X_e[0] < Y_e[0]:
            X_e.pop(0)
            X_e.append(r.pop(0))
        else:
            Y_e.pop(0)
            Y_e.append(r.pop(0))
    print(sum(X_e) + sum(Y_e))


e()

Submission status: Time Limit Exceeded

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)

sum=0
if len(p)<x:
    num= x-len(p)
    sum+=sum(r[:num])
    r=r[num:]
    x-=num
if len(q)<y:
    num= y-len(q)
    sum+=sum(r[:num])
    r=r[num:]
    y-=num

for i in range((x)):
    if len(r)>0:
        if p[0]>r[0]:
            sum+=p[0]
            p=p[1:]
        else:
            sum+=r[0]
            r=r[1:]
    else:
        sum += p[0]
        p=p[1:]
for i in range((y)):
    if len(r)>0:
        if q[0]>r[0]:
            sum+=q[0]
            q=q[1:]
        else:
            sum+=r[0]
            r=r[1:]
    else:
        sum += q[0]
        q = q[1:]

print(sum)

Submission status: Time Limit Exceeded

Solution code:
a=input().split(" ")
X,Y,A,B,C=[int(i) for i in a]
p=[int(i) for i in input().split(" ")]
q=[int(i) for i in input().split(" ")]
r=[int(i) for i in input().split(" ")]
soma=0
while X>0 or Y>0:
    if max(r,default=0)>max(p,default=0) and max(r,default=0)>max(q,default=0):
        if max(p,default=0)>max(q,default=0) and X>0:
            X-=1
            soma+=max(r,default=0)
            del r[r.index(max(r,default=0))]
        elif Y>0:
            Y-=1
            soma+=max(r,default=0)
            del r[r.index(max(r,default=0))]
    else:
        if max(p,default=0)>max(q,default=0) and X>0:
            X-=1
            soma+=max(p,default=0)
            del p[p.index(max(p,default=0))]
        elif Y>0:
            Y-=1
            soma+=max(q,default=0)
            del q[q.index(max(q,default=0))]
        else:
            X-=1
            soma+=max(p,default=0)
            del p[p.index(max(p,default=0))]
print(soma)

Submission status: Time Limit Exceeded

Solution code:
x,y,a,b,c=map(int,input().split()) #x,yだけ見る。
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
s=sorted(p+q+r, reverse=True)
cntr,cntg,ans=0,0,0
for i in range(a+b+c):
    if cntr<x and (s[i] in set(p) or s[i] in set(r)):
        ans+=s[i]
        cntr+=1
    elif cntg<y and (s[i] in set(q) or s[i] in set(r)):
        ans+=s[i]
        cntg+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
X, Y, A, B, C = map(int, input().split(' '))

red = list(map(int, input().split(' ')))
green = list(map(int, input().split(' ')))
none_a = list(map(int, input().split(' ')))

none_new = np.array(none_a)
red1 = red + none_a
eat_red_1 = sorted(red1, reverse = True)[:X]

for eaten in eat_red_1:
  if none_a.count(eaten) > 0:
  	none_a.remove(eaten)
green1 = green + none_a
eat_green_1 = sorted(green1, reverse = True)[:Y]

result1 = sum(eat_red_1) + sum(eat_green_1)

none_new = list(none_new)
green_2 = green + none_new
eat_green_2 = sorted(green_2, reverse = True)[:Y]
for eaten in eat_green_2:
  if none_new.count(eaten) > 0:
  	none_new.remove(eaten)
red_2  = red + none_new
eat_red_2 = sorted(red_2, reverse = True)[:X]

result2 = sum(eat_red_2) + sum(eat_green_2)

print(max(result1, result2))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  x, y, a, b, c = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0,
  
  lx = []
  while True:
    if sum([ca, cb, cc]) == x+y:
      break
      
    if len(la) > 0 and ca < x:
      a = la[0]
    else:
      a = -1
      
    if len(lb) > 0 and cb < y:
      b = lb[0]
    else:
      b = -1
      
    if len(lc) > 0:
      c = lc[0]
    else:
      c = -1
      
    if len(la) > 0 and ca < x and a >= b and a >= c:
      lx.append(a)
      la.pop(0)
      ca += 1
      continue
      
    if len(lb) > 0 and cb < y and b >= a and b >= c:
      lx.append(b)
      lb.pop(0)
      cb += 1
      continue
      
    if len(lc) > 0 and c >= b and c >= a:
      lx.append(c)
      lc.pop(0)
      cc += 1
  print(sum(lx))

if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

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

a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
red=0
green=0
sum=0
d=0
for i in range(X+Y):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
  if(red>X):
    break
  elif(green>Y):
    break
    
if(red<=X and green<=Y):
  print(d)
elif(red>X):
  b=q[:]
  b.extend(r)
  b.sort()
  b.reverse()
  for i in range(max(X,Y)):
    if(i<X):
      sum+=p[i]
    if(i<Y):
      sum+=b[i]
  print(sum)
elif(green>Y):
  b=p[:]
  b.extend(r)
  b.sort()
  b.reverse()
  for i in range(max(X,Y)):
    if(i<X):
      sum+=b[i]
    if(i<Y):
      sum+=q[i]
  print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
x,y,a,b,c = map(int,input().split())

pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
import itertools
pl_ac = [0] + list(itertools.accumulate(pl))
ql_ac = [0] + list(itertools.accumulate(ql))
rl_ac = [0] + list(itertools.accumulate(rl))

dada = max(ql[-1], pl[-1], rl[-1])

import bisect
ans = 0
#　赤色をi個食べるとすると無職x-i
for i in range(x+1):
    tmp = 0
    if i > a or x - i > c or b + c - (x - i) < y:
        continue
    #あか
    tmp += pl_ac[-1] - pl_ac[-1-i]
    # #無職
    # tmp += rl_ac[-1] - ql_ac[-1-(x-i)]
    #残りの無職
    if x-i == 0:
        rl_c = rl[:]
    else:
        rl_c = rl[:-(x-i)]
    # ub以上のりんご何個ある？
    ub = dada + 1

    lb = -1
    while True:
        if ub == lb:
            target = ub
            break
        target = (ub + lb) // 2 + 1
        idx = bisect.bisect_left(ql, target)
        idx2 = bisect.bisect_left(rl_c, target)
        if (b - idx) + (c - (x - i) - idx2) >= y:
            lb = target
        else:
            ub = target - 1
    idx = bisect.bisect_left(ql, target)
    idx2 = bisect.bisect_left(rl_c, target)
    tmp += ql_ac[-1] - ql_ac[idx]
    tmp += rl_ac[-1] - rl_ac[idx2]
    gg = (b - idx) + (c - (x - i) - idx2) - y
    if gg > 0:
        tmp -= target * gg
    ans = max(tmp, ans)

print(ans)

Submission status: Time Limit Exceeded

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

p = [-i for i in p]
q = [-i for i in q]
r = [-i for i in r]


result = [0]
for i in range(min(x+y+1, c+1)):
    hq = p+q+r[:i]
    heapq.heapify(hq)
    for j in range(x+y):
        result[-1] -= heapq.heappop(hq)
    result.append(0)
print(max(result))

Submission status: Time Limit Exceeded

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)

N=[]

for i in range(X):
    N.append(p[i])
for j in range(Y):
    N.append(q[j])

while  min(N)<max(r) :
    N.pop(N.index(min(N)))
    N.append(max(r))

print(sum(N))

Submission status: Time Limit Exceeded

Solution code:
x, y, a, b, c = map(int, input().split())
 
red = sorted(list(map(int, input().split())), reverse=True)
gre = sorted(list(map(int, input().split())), reverse=True)
non = sorted(list(map(int, input().split())), reverse=True)
 
eat = []
 
for i in range(x):
    eat.append(red.pop(0))
 
for i in range(y):
    eat.append(gre.pop(0))
 
eat.sort()
 
for i in range(len(non)):
    n = non.pop(0)
    if eat[i] < n:
        eat[i] = n
    else:
        break
 
print(sum(eat))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
xyabc = [int(i) for i in input().split()]
p = np.array(sorted([int(i) for i in input().split()])[::-1])
q = np.array(sorted([int(i) for i in input().split()])[::-1])
r = np.array(sorted([int(i) for i in input().split()])[::-1])

pp = 0
qp = 0
rp = 0
ns = 0
res = 0
while(True):
  if (pp == len(p)):
    this_p = 0
  else:
    if (pp < xyabc[0]):
      this_p = p[pp]
    else:
      this_p = 0
      
  if (qp == len(q)):
    this_q = 0
  else:
    if (qp < xyabc[1]):
      this_q = q[qp]
    else:
      this_q = 0
      
  if (rp == len(r)):
    this_r = 0
  else:
    this_r = r[rp]
      
  this_max = np.max([this_p,this_q,this_r])
  this_max_i = np.argmax([this_p,this_q,this_r])
  if (this_max_i) == 0:
    pp += 1
  if (this_max_i) == 1:
    qp += 1
  if (this_max_i) == 2:
    rp += 1
  
  ns += 1
  res += this_max
  if (ns == xyabc[0]+xyabc[1]):
    print(res)
    break

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left

X, Y, A, B, C = [int(i) for i in input().split()]
P = sorted([int(i) for i in input().split()])[-X:]
Q = sorted([int(i) for i in input().split()])[-Y:]
R = sorted([int(i) for i in input().split()])[::-1]
i = 0
j = 0
k = 0
tmp = P if P[0] < Q[0] else Q
while(True):
    try:
        if P[j] > Q[k]:
            if Q[k] < R[i]:
                insort_left(Q, R[i])
                k += 1
                i += 1
                continue
        else:
            if P[j] < R[i]:
                insort_left(P, R[i])
                j += 1
                i += 1
                continue
        break
    except IndexError:
        break
print(sum(P[j:]) + sum(Q[k:]))

Submission status: Time Limit Exceeded

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

i=0
j=0
k=0
lea=len(A)
leb=len(B)
while(True):
    if len(C)<1:
        break
    if i<lea and j<leb:
        if A[i]>B[j]:
            if B[j]<C[0]:
                B[j]=C.pop(0)
                
                j+=1
            else:
                break
        else:
            if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
            else:
                break
    elif i<lea and j>=leb:
        if A[i]<C[0]:
                A[i]=C.pop(0)
                i+=1
        else:
            break
    elif i>=lea and j<leb:
        if B[j]<C[0]:
                B[j]=C.pop(0)
                j+=1
        else:
            break
    else:
        break
sum=0


for s in range(len(A)):
    sum+=A[s]
for t in range(len(B)):
    sum+=B[t]
print(sum)

Submission status: Time Limit Exceeded

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

PR = sorted(P + R, reverse = True)
QR = sorted(Q + R, reverse = True)

ans = 0
for i in range(X):
  ans += PR[i]
  if PR[i] in R:
    if PR[i] in QR:
      QR.remove(PR[i])
#print(ans)
for i in range(Y):
  ans += QR[i]
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[0] <= int(arrayR[i]):
        arrayAns[0] = int(arrayR[i])
        arrayAns.sort()
    else:
        break
print(sum(arrayAns))

Submission status: Time Limit Exceeded

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

p = sorted(list(map(int,input().split())))[-X:]
q = sorted(list(map(int,input().split())))[-Y:]
r = sorted(list(map(int,input().split())), reverse=True)

for i in r:
    p_min = p[0]
    q_min = q[0]

    if p_min > i and q_min > i:
        break

    p_min_diff = i - p_min
    q_min_diff = i - q_min

    if p_min_diff >= q_min_diff and p_min_diff > 0:
        del p[0]
        p.append(i)
    elif q_min_diff >= p_min_diff and q_min_diff > 0:
        del q[0]
        q.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
first = list(map(int,input().split()))
x = first[0]
y = first[1]
a = first[2]
b = first[3]
c= first[4]

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

p.sort()
q.sort()
r.sort()

eat = []

for i in range(x):
    eat.append(p[a-i-1])
for i in range(y):
    eat.append(q[b-i-1])

eat.sort()

while True:
    if eat[0] < r[c-1]:
        eat[0] = r[c-1]
        r[c-1] = 0
        eat.sort()
        r.sort()
    else:
        break

s = 0
for i in range(len(eat)):
    s = s+eat[i]


print(s)

Submission status: Time Limit Exceeded

Solution code:
#200329E
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)
R = sorted(r)
Red = p + r
Red = sorted(Red)
Deli =[]

for i in range(X):
    Deli.append(Red[len(Red)-1])
    if Red[len(Red)-1] == P[len(P)-1]:
        Red[len(Red)-1] = 0
        #print(Red)
        Red = sorted(Red)
        P[len(P)-1]= 0
        P = sorted(P)
    else:
        Red[len(Red)-1] = 0
        Red = sorted(Red)
        R[len(R)-1]= 0
        R = sorted(R)

Green = q + R
Green = sorted(Green)
for i in range(Y):
    Deli.append(Green[len(Green)-1])
    Green[len(Green)-1] = 0
    Green = sorted(Green)
    
#print(Deli)
print(int(sum(Deli)))

Submission status: Time Limit Exceeded

Solution code:
x, y, a, b, c = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse=True)
Q = sorted(list(map(int, input().split())), reverse=True)
R = sorted(list(map(int, input().split())), reverse=True)
P_cs, Q_cs, R_cs = {}, {}, {}
P_cs[0] = P[0]
Q_cs[0] = Q[0]
R_cs[0] = R[0]
P_cs[-1] = 0
Q_cs[-1] = 0
R_cs[-1] = 0

for i in range(a-1):
  P_cs[i+1] = P_cs[i] + P[i+1]
for i in range(b-1):
  Q_cs[i+1] = Q_cs[i] + Q[i+1]
for i in range(c-1):
  R_cs[i+1] = R_cs[i] + R[i+1]

#print(P_cs)
#print(Q_cs)
#print(R_cs)

max_total = 0
for p in range(x+1):
  for q in range(y+1):
    r = x + y - p - q
    if r <= c:
      total = P_cs[p-1] + Q_cs[q-1] + R_cs[r-1]
      #print(p, q, r, total)
      max_total = max(max_total, total)
print(max_total)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
ans.sort()

for i in range(c):
    if r[i] > ans[0]:
        ans[0] = r[i]
        ans.sort()
        r[i] = 0

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

x, y, a, b, c = [int(x) for x in stdin.readline().rstrip().split()]

p = [int(x) for x in stdin.readline().rstrip().split()]
q = [int(x) for x in stdin.readline().rstrip().split()]
r = [int(x) for x in stdin.readline().rstrip().split()]

#print(p)
#print(q)
#print(r)

ps = sorted(p, reverse=True)
qs = sorted(q, reverse=True)
#rs = sorted(p, reverse=True)

#print(ps[0:x])
#print(qs[0:y])

#pss = ps[0:x]
#pss.extend(qs[0:y])
#print(pss)

he = 0

'''
for i in range(x+y):
    for j in range(len(r)):
        if pss[i] < r[j]:
            pss[i] = r.pop(j)
            #print("pop")
            #print(r)
            break
    #print(he)
    he += pss[i]
'''

for i in range(x):
    for j in range(len(r)):
        if ps[i] < r[j]:
            ps[i] = r.pop(j)
            #print("pop")
            #print(r)
            break
    #print(he)
    he += ps[i]

for i in range(y):
    for j in range(len(r)):
        if qs[i] < r[j]:
            qs[i] = r.pop(j)
            #print("pop")
            #print(r)
            break
    #print(he)
    he += qs[i]

print(he)

Submission status: Time Limit Exceeded

Solution code:
from copy import copy

X, Y, A, B, C = [int(n) for n in input().split(' ')]
p = [int(n) for n in input().split(' ')]
q = [int(n) for n in input().split(' ')]
r = [int(n) for n in input().split(' ')]

p.sort()
q.sort()

ans = 0
for flag in range(1<<len(r)):
    P = copy(p[-X:])
    Q = copy(q[-Y:])
    for i in range(len(r)):
        if flag & 1<<i:
            P += [r[i]]
        else:
            Q += [r[i]]
    P.sort()
    Q.sort()
    sums = sum(P[-X:]) + sum(Q[-Y:])
    if sums > ans:
        ans = sums

print(ans)

Submission status: Time Limit Exceeded

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)

alist = []
ans = 0

for i in range(X):
    alist.append(p[i])
    
for j in range(Y):
    alist.append(q[j])
    
alist.sort(reverse=True)
ans = sum(alist)
    
for k in range(C):
    ans = max(ans,sum(r[:k+1])+sum(alist[:len(alist)-k-1]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x,y,a,b,c = map(int, input().split())
result=sorted(list(map(int, input().split())), reverse=True)[:x]
result+=sorted(list(map(int, input().split())), reverse=True)[:y]
r=sorted(list(map(int, input().split())), reverse=True)
s = sum(result)
for el in r:
    t = el - min(result)
    if t>0:
        s += t
print(s)

Submission status: Time Limit Exceeded

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)

N=[]

for i in range(X):
    N.append(p[i])
for j in range(Y):
    N.append(q[j])

while  min(N)<max(r) and len(r)!=0:
    N.pop(N.index(min(N)))
    N.append(max(r))

print(sum(N))

Submission status: Time Limit Exceeded

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

ans = []
for i in range(x):
    ans.append(p[i])
for i in range(y):
    ans.append(q[i])
ans.sort()

for i in range(c):
    if r[i] > ans[0]:
        ans[0] = r[i]
        ans.sort()
        r[i] = 0
    ans.sort()

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
X, Y, A, B, C = (int(i) for i in input().split())
p = [[int(x), "A"] for x in stdin.readline().rstrip().split()]
q = [[int(x), "B"]  for x in stdin.readline().rstrip().split()]
r = [[int(x), "C"] for x in stdin.readline().rstrip().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]
apples = p+q+r

apples = sorted(apples, reverse=True)
ans = 0
pend = 0

while (X > 0 or Y > 0) and X+Y > pend:
    if apples[0][1] == "C":
        pend += 1
        ans += apples[0][0]
        apples.pop(0)
    elif apples[0][1] == "A":
        if X > 0:
            ans += apples[0][0]
            apples.pop(0)
            X -= 1
        else:
            apples.pop(0)
    elif apples[0][1] == "B":
        if Y>0:
            ans += apples[0][0]
            apples.pop(0)
            Y -= 1
        else:
            apples.pop(0)
    #print(ans)
    #print("XY", X, Y, pend)
#print("XY", X, Y, pend)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[0] <= int(arrayR[i]):
        arrayAns[0] = int(arrayR[i])
        arrayAns.sort()
print(sum(arrayAns))

Submission status: Time Limit Exceeded

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(reverse=True)
x=p[(A-X):]
y=q[(B-Y):]
s=sum(x)+sum(y)
sub=0

for i in range(len(r)):
    if x[0]>y[0]:
        t=y.pop(0)
        if t<r[0]:
            y.append(r[0])
            sub=sub+r.pop(0)-t
        else:
            break
    else:
        t=x.pop(0)
        if t<r[0]:
            x.append(r[0])
            sub=sub+r.pop(0)-t
        else:
            break

print(s+sub)

Submission status: Time Limit Exceeded

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()))
C_copy = C.copy()
for i in range(5):
    A.append(0)
    B.append(0)
    C_copy.append(0)
ux_1 = 0
uy_1 = 0
for i in range(X):
    ux_1 += max(max(A),max(C_copy))
    if max(A) >= max(C_copy):
        A.pop(A.index(max(A)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
for i in range(Y):
    uy_1 += max(max(B),max(C_copy))
    if max(B) >= max(C_copy):
        B.pop(B.index(max(B)))
    else:
        C_copy.pop(C_copy.index(max(C_copy)))
print(ux_1+uy_1)

Submission status: Time Limit Exceeded

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

d = 0
x = 0
y = 0

while x < X and y < Y:
    a = max(p)
    b = max(q)
    c = max(r)
    if a >= c:
        d += a
        x += 1
        p.remove(a)
    elif b >= c:
        d += b
        y += 1
        q.remove(b)
    elif c > a >= b:
        d += c
        y += 1
        r.remove(c)
    elif c > b > a:
        d += c
        x += 1
        r.remove(c)

while x < X:
    p.extend(r)
    d += max(p)
    x += 1
    p.remove(max(p))
while y < Y:
    q.extend(r)
    d += max(q)
    y += 1
    q.remove(max(q))
print(d)

Submission status: Time Limit Exceeded

Solution code:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
s = p + q + r
S = sorted(s, reverse = True)
i = 0
j = 0
ans = 0
a = 0
b = 0
c = 0
while i < (X + Y):
  if S[j] in r:
    c += 1
    r.remove(S[j])
    ans += S[j]
    i += 1
  elif S[j] in p and a < X:
    a += 1
    p.remove(S[j])
    ans += S[j]
    i += 1
  elif S[j] in q and b < Y:
    b += 1
    q.remove(S[j])
    ans += S[j]
    i += 1
  j += 1
print(ans)

Submission status: Time Limit Exceeded

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()
P.reverse()
Q.reverse()
R.reverse()
R.append(0)
red = P[0:x]
green = Q[0:y]
change = min(red[x-1], green[y-1])
while change < max(R):
  if red[x-1] < R[0]:
    red.remove(red[x-1])
    red.append(R[0])
  else:
    green.remove(green[y-1])
    green.append(R[0])
  
  R.remove(R[0])
  red.sort()
  green.sort()
  R.sort()
  red.reverse()
  green.reverse()
  R.reverse()
  change = min(red[x-1], green[y-1])
  
print(sum(red) + sum(green))