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: Runtime Error

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

a_list = list(map(int, input().split()))
a_list.sort()
b_list = list(map(int, input().split()))
b_list.sort()
c_list = list(map(int, input().split()))
c_list.sort()

a_index = a-x
b_index = b-y
for c_data in c_list:
    if a_index < a and a_list[a_index] < b_list[b_index]:
        if(a_list[a_index] < c_data):
            a_list[a_index] = c_data
            a_index += 1
    elif b_index < b:
        if(b_list[b_index] < c_data):
            b_list[b_index] = c_data
            b_index += 1
    else:
        break

count = 0
for i in range(a-1, a-x-1, -1):
    count += a_list[i]
for i in range(b-1, b-y-1, -1):
    count += b_list[i]
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque

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)
xlis = deque(p[len(p)-x:])
ylis = deque(q[len(q)-y:])
r = deque(r)
while True:
    xs = xlis.popleft()
    ys = ylis.popleft()
    rm = r.popleft()
    if rm < xs and rm < ys:
        xlis.append(xs)
        ylis.append(ys)
        break
    if xs < ys and xs < rm:
        xlis.append(rm)
        ylis.append(ys)
    elif ys < xs and ys < rm:
        ylis.append(rm)
        xlis.append(xs) 
print(sum(xlis)+sum(ylis))

Submission status: Runtime Error

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()))
Pl = 0
Ql = 0

P.sort(reverse = True)
Q.sort(reverse = True)
R.sort(reverse = True)

P = P[0:x]
Q = Q[0:y]

while P[-1 - Pl] < R[0] or Q[-1 - Ql] < R[0]:
    if Q[-1 - Ql] >= P[-1 - Pl]:
        P[-1 - Pl] = R.pop(0)
        #P.sort(reverse = True)
        Pl = Pl + 1
    else:
        Q[-1 - Ql] = R.pop(0)
        #Q.sort(reverse=True)
        Ql = Ql + 1

    if R == []:
        break

print(sum(P) + sum(Q))

Submission status: Runtime Error

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,y,a,b,c = mi()
p = li()
q = li()
r = li()

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


qp = True
qq = True
plef = a - x
qlef = b - y
ans = 0
rlen = len(r) -1
while True:
    if rlen <0:
        break
    if p[plef] >= q[qlef]:
        ima = q[qlef]
        tmp = "q"
    else:
        ima = p[plef]
        tmp = "p"
    if ima < r[rlen]:
        ans += r[rlen]
        rlen -= 1
        if tmp == "q":
            qlef += 1
        else:
            plef += 1
    
    else:
        break
    
for i in range(plef,a):
    ans += p[i]

for i in range(qlef,b):
    ans +=q[i]
print(ans)

Submission status: Runtime Error

Solution code:
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)

i = 0
j = 0
for c in C:
    if A[i] < c or B[j] < c:
        if A[i] < B[j]:
            i += 1
            ans += c - A[i]
        else:
            j += 1
            ans += c - B[j]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()


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()))
lst=[]
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort()

while len(P)>X:
    P.pop()
while len(Q)>Y:
    Q.pop()

flag=1
while flag:
    if not R:
        break

    flag=0
    if P and R:
        if P[-1]<Q[-1]:
            if P[-1]<R[-1]:
                P.pop()
                lst.append(R.pop())
                flag=1
        else:
            if Q[-1]<R[-1]:
                Q.pop()
                lst.append(R.pop())
                flag=1
    else:
        if P:
            if P[-1]<R[-1]:
                P.pop()
                lst.append(R.pop())
                flag=1
        elif R:
            if Q[-1]<R[-1]:
                Q.pop()
                lst.append(R.pop())
                flag=1
for i in range( X+Y-(len(P)+len(Q)+len(lst))):
    if R:
        lst.append(R.pop())
print(sum(P)+sum(Q)+sum(lst))

Submission status: Runtime Error

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

red.sort()
green.sort()
color.sort()


deli = 0


while x > 0 :
    if(color[-1] > red[-1]) :
        popped = color.pop()
        deli += popped 
    else :
        popped = red.pop()
        deli += popped 
    x -= 1


while y > 0 :
    if(color[-1] > green[-1]) :
        popped = color.pop()
        deli += popped 
    else :
        popped = green.pop()
        deli += popped 
    y -= 1

print(deli)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):
    p = sorted(p, reverse=True)
    q = sorted(q, reverse=True)
    d = sorted(p[:X] + q[:Y])
    i = 0
    for rr in r:
        if d[i] <= rr:
            d[i] = rr
            i += 1
    print(sum(d))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    q = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    r = [int(next(tokens)) for _ in range(C)]  # type: "List[int]"
    solve(X, Y, A, B, C, p, q, r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,y,a,b,c = mi()
p = li()
q = li()
r = li()

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

from collections import deque
pd = deque(p)
qd = deque(q)
rd = deque(r)

qp = True
qq = True
plef = a - x
qlef = b - y
ans = 0
while True:
    if len(rd) == 0:
        break
    if p[plef] >= q[qlef]:
        ima = q[qlef]
        tmp = "q"
    else:
        ima = p[plef]
        tmp = "p"
    if ima < rd[-1]:
        ans += rd[-1]
        rd.pop()
        if tmp == "q":
            qlef += 1
        else:
            plef += 1
    
    else:
        break
    
for i in range(plef,a):
    ans += p[i]

for i in range(qlef,b):
    ans +=q[i]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
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)

reds = deque(p)
greens = deque(q)
uncolor = deque(r)

# できるだけ値が大きいやつを使いたい
ans = 0
red_cnt = 0
green_cnt = 0
while True:
    # print(red_cnt, green_cnt, reds, greens, uncolor)
    if red_cnt == x and green_cnt == y:
        break
    if len(reds) == 0 or red_cnt == x:
        if greens[0] > uncolor[0]:
            eat = greens.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        green_cnt += 1
    elif len(greens) == 0 or green_cnt == y:
        if reds[0] > uncolor[0]:
            eat = reds.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        red_cnt += 1
    else:
        if red_cnt < x:
            if reds[0] > greens[0]:
                if reds[0] > uncolor[0]:
                    eat = reds.popleft()
                else:
                    eat = uncolor.popleft()
                ans += eat
                red_cnt += 1
            else:
                if greens[0] > uncolor[0]:
                    eat = greens.popleft()
                else:
                    eat = uncolor.popleft()
                ans += eat
                green_cnt += 1
        else:
            if greens[0] > uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            green_cnt += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
X, Y, A, B, C = sys.stdin.readline()
X = int(X)
Y = int(Y)
C = int(C)
scoreA = map(int, sys.stdin.readline().split())
scoreB = map(int, sys.stdin.readline().split())
scoreC = 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
total = sum(scoreAll)

Submission status: Runtime Error

Solution code:
import sys
input = sys.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()))
p.sort()
q.sort()
r.sort(reverse = True)
t = []
for _ in range(X): t.append(p.pop())
for _ in range(Y): t.append(q.pop())
t.sort()
for i in range(C):
  if t[i] < r[i]: t[i] = r[i]
print(sum(t))

Submission status: Runtime Error

Solution code:
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)

i = 0
j = 0
for c in C:
    if A[i] < c or B[j] < c:
        if A[i] < B[j]:
            i += 1
            ans += c - A[i]
        else:
            j += 1
            ans += c - B[i]

print(ans)

Submission status: Runtime Error

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()))
ans = 0
p.sort()
q.sort()
r.sort()
for i in range(X):
    if p[-1] >= r[-1]:
        ans += p[-1]
        del p[-1:]
        
    else:
        ans += r[-1]
        del r[-1:]
         
for i in range(Y):
    if q[-1] >= r[-1]:
        ans += q[-1]
        del q[-1:]
        
    else:
        ans += r[-1]
        del r[-1:]
                   

print(ans)

Submission status: Runtime Error

Solution code:
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()


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()))
lst=[]
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort()

while len(P)>X:
    P.pop()
while len(Q)>Y:
    Q.pop()

flag=1
while flag:
    if not R:
        break
    flag=0
    if P[-1]<Q[-1]:
        if P[-1]<R[-1]:
            P.pop()
            lst.append(R.pop())
            flag=1
    else:
        if Q[-1]<R[-1]:
            Q.pop()
            lst.append(R.pop())
            flag=1
print(sum(P)+sum(Q)+sum(lst))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
X, Y, A, B, C = map(int, input().split())
red_oishisa = list(map(int, input().split()))
green_oishisa = list(map(int, input().split()))
no_oishisa = list(map(int, input().split()))

red_oishisa = list(sorted(red_oishisa))[::-1]
green_oishisa = list(sorted(green_oishisa))[::-1]
no_oishisa = list(sorted(no_oishisa))[::-1]

eat_oishisas_red = red_oishisa[:X]
eat_oishisas_green = green_oishisa[:Y]

i=1
j=1
k=1
while(True):
    if i > A:
        break
    elif j > B:
        break
    elif k > C:
        break
    elif min([eat_oishisas_red[-i], eat_oishisas_green[-j]]) > no_oishisa[k-1]:
        break

    if eat_oishisas_red[-i] <= eat_oishisas_green[-j]:
        eat_oishisas_red[-i] = no_oishisa[k-1]
        i += 1
    else:
        eat_oishisas_green[-j] = no_oishisa[k-1]
        j += 1
    k += 1

print(sum(eat_oishisas_green) + sum(eat_oishisas_red))

Submission status: Runtime Error

Solution code:
from collections import deque
x, y, a, b, c = [int(i) for i in input().split()]
lp = sorted([int(i) for i in input().split()])
if len(lp) != x:
  del lp[:len(lp)-x]
lp = deque(lp)
lq = sorted([int(i) for i in input().split()])
if len(lq) != y:
  del lq[:len(lq)-y]
lq = deque(lq)
lr = sorted([int(i) for i in input().split()])
lr = deque(lr)


while True:
  if len(lr) == 0:
    break
  r_max = lr[len(lr)-1]
  p_min = lp[0]
  q_min = lq[0]
  if r_max <= p_min and r_max <= q_min:
    break
  elif r_max > q_min and p_min >= q_min:
    del lq[0]
    lq.append(lr.pop(-1))
  elif r_max > p_min and q_min >= p_min:
    del lp[0]
    lp.append(lr.pop(-1))


print(sum(lp) + sum(lq))

Submission status: Runtime Error

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)

anslist = p[:x] + q[:y]
anslist.sort()
for i, x in enumerate(r):
    if x > anslist[i]:
        anslist[i] = x

print(sum(anslist))

Submission status: Runtime Error

Solution code:
import numpy as np
X, Y, A, B, C = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = np.array(sorted(list(map(int, input().split())), reverse=True))

p_cut = np.array(p[A-X:])
q_cut = np.array(q[B-Y:])
pi = 0
qi = 0
for i in range(len(r)):
    if p_cut[pi] >= q_cut[qi] :
        if q_cut[qi] >= r[i]:
            break
        q_cut[qi] = r[i]
        qi += 1
    else:
        if p_cut[pi] >= r[i]:
            break
        p_cut[pi] = r[i]
        pi += 1
print(np.sum(p_cut) + np.sum(q_cut))

Submission status: Runtime Error

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

p=[]
q=[]
r=[]

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)
ans=0
for i in range(x):
    if(len(p)!=0 or len(r)!=0):
        t=max(p[0],r[0])
        ans+=t
        if t==p[0]:
            del p[0]
        elif t==r[0]:
            del r[0]
        
for i in range(y):
    if(len(q)!=0 or len(r)!=0):
        u=max(q[0],r[0])
        ans+=u
        if u==q[0]:
            del q[0]
        elif t==r[0]:
            del r[0]
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
P_=P[A-X:]
Q_=Q[B-Y:]
while P_[0]<R[-1] or Q_[0]<R[-1]:
    if P_[0]<Q_[0]:
        P_.pop(0)
        P_.append(R.pop(-1))
    else:
        Q_.pop(0)
        Q_.append(R.pop(-1))
print(sum(P_)+sum(Q_))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
X, Y, A, B, C = map(int, input().split())
red_oishisa = list(map(int, input().split()))
green_oishisa = list(map(int, input().split()))
no_oishisa = list(map(int, input().split()))

red_oishisa = list(sorted(red_oishisa))[::-1]
green_oishisa = list(sorted(green_oishisa))[::-1]
no_oishisa = list(sorted(no_oishisa))[::-1]

eat_oishisas_red = red_oishisa[:X]
eat_oishisas_green = green_oishisa[:Y]

i=1
j=1
k=1
while(True):
    if i > A:
        break
    elif j > B:
        break
    elif k > C:
        break
    elif min([eat_oishisas_red[-i], eat_oishisas_green[-j]]) >= no_oishisa[k-1]:
        break

    if eat_oishisas_red[-i] <= eat_oishisas_green[-j]:
        eat_oishisas_red[-i] = no_oishisa[k-1]
        i += 1
    else:
        eat_oishisas_green[-j] = no_oishisa[k-1]
        j += 1
    k += 1

print(sum(eat_oishisas_green) + sum(eat_oishisas_red))

Submission status: Runtime Error

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

p = p[:X]
q = q[:Y]
z = []

while len(r) != 0 and r[-1] > min(p[-1], q[-1]):
    k = r.pop()
    if p[-1] < q[-1]:
        del p[-1]
    else:
        del q[-1]
    z.append(k)   

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

Submission status: Runtime Error

Solution code:
#author : dokueki

import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    x, y, a, b, c = map(int, sys.stdin.readline().split())
    r = list(map(int, sys.stdin.readline().split()))
    g = list(map(int, sys.stdin.readline().split()))
    blind = list(map(int, sys.stdin.readline().split()))
    r.sort(reverse=True)
    g.sort(reverse=True)
    blind.sort(reverse=True)
    red_need = r[:x]
    green_need = g[:y]
    res = red_need + green_need
    res.sort()
    #print(res)
    for i in range(c):
        if blind[i] > res[i]:
            res[i] = blind[i]
    print(sum(res))


if __name__ == "__main__":
    # IOE()
    main()

Submission status: Runtime Error

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=sorted(p)
q=sorted(q)
r=sorted(r)
p=p[(a-x):]
q=q[(b-y):]
res=sum(p)+sum(q)
tp=0
tq=0
tr=c-1
while(p[tp]<r[tr] or q[tq]<r[tr]):
  if(p[tp]<q[tq]):
    res+=r[tr]-p[tp]
    tp+=1
  else:
    res+=r[tr]-q[tq]
    tq+=1
  tr-=1
print(res)

Submission status: Runtime Error

Solution code:
(x,y,a,b,c),*t=[map(int,t.split())for t in open(0)]
p,q,r=[[0]+sorted(t)[::-1]for t in t]
for i in range(a):p[i+1]+=p[i]
for i in range(b):q[i+1]+=q[i]
for i in range(c):r[i+1]+=r[i]
m=0
for i in range(x+1):
    # i:赤の個数
    # j:赤に変える無の個数
    # k:無の残り
    j=x-i
    k=c-j
    if i>a or j>c:continue
    # 赤の美味しさ総和
    t=p[i]+r[j]
    # 上手いこと緑の美味しさ総和を求める
    # sum(list(map(max,zip(r[j+1:],q)))[:y])
    # ↑みたいなことをしたい
    ok=0
    ng=k+1
    while ng-ok>1:
        mid=(ok+ng)//2
        if r[j+mid]-r[j]>=q[min(b,y)]-q[min(b,y-mid)]:
            ok=mid
        else:
            ng=mid
    t+=q[min(b,y-ok)]+r[j+ok]-r[j]
    if t>m:m=t
print(m)

Submission status: Runtime Error

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

ans = 0
for i in range(x):
    if p[-1] >= r[-1]:
        ans += p.pop()
    else:
        ans += r.pop()

for i in range(y):
    if q[-1] >= r[-1]:
        ans += q.pop()
    else:
        ans += r.pop()

print(ans)

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque
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_que = deque(p[:x])
green_que = deque(q[:y])
for i in range(c):
    if red_que[-1] < green_que[-1]:
        if red_que[-1] < r[i]:
            red_que.pop()
            bisect.insort_left(red_que, r[i])
        else:
            break
    else:
        if green_que[-1] < r[i]:
            green_que.pop()
            bisect.insort_left(green_que, r[i])
print(sum(green_que) + sum(red_que))

Submission status: Runtime Error

Solution code:
import heapq

x,y,a,b,c = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
w = list(map(int,input().split()))

r.sort(key = lambda x:-x)
g.sort(key = lambda x:-x)
w.sort(key = lambda x:-x)


rg = []
for i in range(x):
    rg.append(r[i])

for i in range(y):
    rg.append(g[i])

rg.sort(key = lambda x:-x)

ind = 0
ans = 0
for i in range(x+y):
    if w[ind] > rg[i]:
        ans += w[ind]
        ind += 1
    else:
        ans += rg[i]

print(ans)

Submission status: Runtime Error

Solution code:
def LI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))
# from heapq import heappop,heappush,heapify
import heapq
x,y,a,b,c = MI()
p = LI()
q = LI()
r = LI()

result = 0
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

for _ in range(x):
	if not r==[]:
		max_a = heapq.heappop(p)*(-1)
		max_c = heapq.heappop(r)*(-1)
		if max_a>=max_c:
			result += max_a
			a -= 1
			heapq.heappush(r,max_c*(-1))
		else:
			result += max_c
			c -= 1
			heapq.heappush(p,max_a*(-1))
	else:
		max_a = heapq.heappop(p)*(-1)
		result += max_a
		a -= 1

for _ in range(y):
	if not r==[]:
		max_b = heapq.heappop(q)*(-1)
		max_c = heapq.heappop(r)*(-1)
		if max_b>=max_c:
			result += max_b
			b -= 1
			heapq.heappush(r,max_c*(-1))
		else:
			result += max_c
			c -= 1
			heapq.heappush(q,max_b*(-1))
	else:
		max_b = heapq.heappop(q)*(-1)
		result += max_b
		b -= 1

print(result)

Submission status: Runtime Error

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=sorted(p)
q=sorted(q)
r=sorted(r)
p=p[(a-x):]
q=q[(b-y):]
res=sum(p)+sum(q)
tp=0
tq=0
tr=c-1
while(p[tp]<r[tr] or q[tq]<r[tr]):
  if(p[tp]<q[tq]):
    res+=r[tr]-p[tp]
    tp-=1
  else:
    res+=r[tr]-q[tq]
    tq-=1
  tr-=1
print(res)

Submission status: Runtime Error

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 = sorted(A)
B = sorted(B)
C = sorted(C)

t = 0
s = 0
A = A[-x:]
B = B[-y:]

for i in range(c):
    if A[t] < B[s] and A[t] < C[i]:
        A[t] = C[i]
        t += 1
    elif B[s] < A[t] and B[s] < C[i]:
        B[s] = C[i]
        s += 1

print(sum(A[-x:]) + sum(B[-y:]))

Submission status: Runtime Error

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


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

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ps = sum(P[:X])
qs = sum(Q[:Y])
r_cum = cumsum(R)

x = X - 1
y = Y - 1

ans = ps + qs
# 何個着色するか
for cnt in range(1, min(X + Y, C) + 1):
    if x >= 0 and y >= 0 and P[x] < Q[y] or y < 0:
        ps -= P[x]
        x -= 1
    elif x >= 0 and y >= 0 and P[x] > Q[y] or x < 0:
        qs -= Q[y]
        y -= 1
    else:
        assert False
    s = r_cum[cnt - 1] + ps + qs
    ans = max(ans, s)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
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()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pq = p[:x] + q[:y]
pq.sort()
pqsum = 0
rsum = 0
d = 0
for i in range(c):
    pqsum += pq[i]
    rsum += r[i]
    if rsum - pqsum > d:
        d = rsum - pqsum
print(sum(pq) + d)

Submission status: Runtime Error

Solution code:
#author : dokueki

import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    x, y, a, b, c = map(int, sys.stdin.readline().split())
    r = list(map(int, sys.stdin.readline().split()))
    g = list(map(int, sys.stdin.readline().split()))
    blind = list(map(int, sys.stdin.readline().split()))
    r.sort()
    g.sort()
    blind.sort(reverse=True)
    red_need = r[-x:a]
    green_need = g[-y:b]
    res = red_need + green_need
    res.sort()
    # print(res)
    for i in range(c):
        if blind[i] > res[i]:
            res[i] = blind[i]
    print(sum(res))


if __name__ == "__main__":
    #IOE()
    main()

Submission status: Runtime Error

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

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(C):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Submission status: Runtime Error

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

ps = -1
qs = -1
rs = -1

ans = 0
for i in range(x):
    if (p[ps] > r[rs]):
        ans += p[ps]
        ps -= 1
    else:
        ans += r[rs]
        rs -= 1

for i in range(y):
    if (q[qs] > r[rs]):
        ans += q[qs]
        qs -= 1
    else:
        ans += r[rs]
        rs -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

x, y, a, b, c = MAP()
p = LIST()
q = LIST()
r = LIST()
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pq = deepcopy(p[:x]) + deepcopy(q[:y])
pq.sort()
pqsum = 0
rsum = 0
d = 0
for i in range(c):
    pqsum += pq[i]
    rsum += r[i]
    if rsum - pqsum > d:
        d = rsum - pqsum
print(sum(pq) + d)

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int,input().split())
lia=list(map(int,input().split()))
lib=list(map(int,input().split()))
lic=list(map(int,input().split()))
lia.sort(reverse=True)
lib.sort(reverse=True)
lic.sort(reverse=True)
ans=lia[:x]+lib[:y]
ans.sort(reverse=True)
cnt=0
now=0
while cnt < a+b and now < c:
  if lic[now] > ans[cnt]:
    ans[cnt]=lic[now]
    now+=1
  cnt+=1
print(sum(ans))