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:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x,y,a,b,c=MI()
rs=sorted(LI(),reverse=True)
gs=sorted(LI(),reverse=True)
ns=sorted(LI(),reverse=True)
rs=rs[0:x]
gs=gs[0:y]
#print(gs)
R=deque(rs)
G=deque(gs)
N=deque(ns)


u=R.popleft()
v=G.popleft()
w=N.popleft()
if x==1:
    s=u
else:
    s=R.pop()
if y==1:
    t=v
else:
    t=G.pop()
ans=0
while x>0 or y>0:
    if x==0:
        u=0
        s=inf
    if y==0:
        v=0
        t=inf
    if u>v and u>=w:
        #print(u)
        ans+=u
        x-=1
        if x==1:
            u=s
        elif x!=0:
            u=R.popleft()
        
    elif v>u and v>=w:
        #print(v)
        ans+=v
        y-=1
        if y==1:
            v=t
        elif y!=0:
            v=G.popleft()
        
    elif w>u and w>v:
        #print(w)
        ans+=w
        if s<=t:
            if x==1:
                s=u
                x-=1
            elif x!=0:
                s=R.pop()
                x-=1
        else:
            if y==1:
                t=v
                y-=1
            elif y!=0:
                t=G.pop()
                y-=1
print(ans)

Submission status: Runtime Error

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

p=[(0,i,n) for i,n in enumerate(p)]
q=[(1,i,n) for i,n in enumerate(q)]
r=[(2,i,n) for i,n in enumerate(r)]

p.extend(r)
p.sort(key=lambda x: x[2],reverse=True)

ans=0
for c,i,n in p:
    ans+=n
    if c==2:
        r.pop(i)
    x-=1
    if x==0:
        break

q.extend(r)
q.sort(key=lambda x: x[2],reverse=True)

for i in range(y):
    ans+=q[i][2]

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

p.sort()
q.sort()
r.sort(reverse=True)

ppick = p[-x:]
qpick = q[-y:]

pi = 0
qi = 0

for i in range(len(r)):
    if pi >= a:
        while True:
            if r[i] > qpick[qi] and qi <= b and i <= c:
                qpick[qi] = r[i]
                qi += 1
                i += 1
            else:
                break
    elif qi >= b:
        while True:
            if r[i] > ppick[pi] and pi <= a and i <= c:
                ppick[pi] = r[i]
                pi += 1
                i += 1
            else:
                break
    elif ppick[pi] > qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
        continue
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
        continue
    break

print(sum(ppick) + sum(qpick))

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(reverse=True)

ppick = p[-x:]
qpick = q[-y:]

pi = 0
qi = 0

for i in range(len(r)):
    if pi >= a:
        while True:
            if r[i] > qpick[qi] and qi <= b:
                qpick[qi] = r[i]
                qi += 1
                i += 1
            else:
                break
    elif qi >= b:
        while True:
            if r[i] > ppick[pi] and pi <= a:
                ppick[pi] = r[i]
                pi += 1
                i += 1
            else:
                break
    elif ppick[pi] > qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
        continue
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
        continue
    break

print(sum(ppick) + sum(qpick))

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(reverse=True)

ppick = p[-x:]
qpick = q[-y:]

pi = 0
qi = 0
for i in range(len(r)):
    if ppick[pi] > qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
    else:
        break

print(sum(ppick) + sum(qpick))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int, input().split(" "))
plist= list(map(int, input().split(" ")))
qlist= list(map(int, input().split(" ")))
rlist= list(map(int, input().split(" ")))

plist.extend(qlist)
plist.sort()

rlist.sort(reverse=True)

n = min(len(plist),len(rlist))
slist = plist[0:x+y-1]
ulist = plist[0:x+y-1]
slist[0] = rlist[0]
i = 1

while i < n and sum(slist)>sum(ulist):
  slist[i]=rlist[i]
  ulist[i-1]=rlist[i-1]
  i += 1

print(sum(slist))

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()))
colorless = list(map(int, input().split()))

red.sort(reverse = True)
green.sort(reverse = True)
colorless.sort(reverse = True)

ret = red[:x] + green[:y]
ret.sort()

for i in range(len(colorless)):
    if ret[i] < colorless[i]:
        ret[i] = colorless[i]

print(sum(ret))

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(3)]

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g, h = 0, 0
ans = 0
for i in range(x):
    if p[0][i] >= p[2][g]:
        ans += p[0][i]
    else:
        if p[1][h] < p[0][i]:
            ans += p[0][i]
            h += 1
        else:
            ans += p[2][g]
            g += 1
            p[2][g] = 0

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g = 0
for i in range(y):
    if p[1][i] >= p[2][g]:
        ans += p[1][i]
    else:
        if g >= c:
            ans += p[1][i]
        else:
            ans += p[2][g]
            g += 1
print(ans)

Submission status: Runtime Error

Solution code:
x, y, a, b, c = map(int,input().split())
p = [list(map(int,input().split())) for _ in range(3)]

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g, h = 0, 0
ans = 0
for i in range(x):
    if p[0][i] >= p[2][g]:
        ans += p[0][i]
    else:
        if p[1][h] < p[0][i]:
            ans += p[0][i]
            h += 1
        else:
            ans += p[2][g]
            g += 1
            p[2][g] = 0

for i, e in enumerate(p):
    p[i] = list(sorted(e,reverse=True))

g = 0
for i in range(y):
    print(p[1][i],p[2][g])
    if p[1][i] >= p[2][g]:
        ans += p[1][i]
    else:
        ans += p[2][g]
        g += 1
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans = p[:x] + q[:y] + r
print(sum(ans.sort(reverse=True)[:x + y]))

Submission status: Runtime Error

Solution code:
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

tot = sum(ps) + sum(qs)

while cs and (cs[-1] > ps[-1] or cs[-1] > qs[-1]):
    if ps and qs:
        if ps[-1] < qs[-1]:
            tot -= ps.pop()
            tot += cs.pop()
        else:
            tot -= qs.pop()
            tot += cs.pop()
    elif ps:
        tot -= ps.pop()
        tot += cs.pop()
    elif qs:
        tot -= qs.pop()
        tot += cs.pop()
    else:
        break
# print ps, qs

print tot

Submission status: Runtime Error

Solution code:
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

tot = sum(ps) + sum(qs)

while cs and (cs[-1] > ps[-1] or cs[-1] > qs[-1]):
    if ps and qs:
        if ps[-1] < qs[-1]:
            tot -= ps.pop()
            tot += cs.pop()
        else:
            tot -= qs.pop()
            tot += cs.pop()
    elif ps:
        tot -= ps.pop()
        tot += cs.pop()
    elif qs:
        tot -= qs.pop()
        tot += cs.pop()
    else:
        assert False
# print ps, qs

print tot

Submission status: Runtime Error

Solution code:
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x][::-1]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y][::-1]
cs = sorted(map(int, raw_input().split()), reverse=True)

tot = sum(ps) + sum(qs)

while cs and (cs[0] > ps[0] or cs[0] > qs[0]):
    if ps and qs:
        if ps[0] < qs[0]:
            tot -= ps.pop(0)
            tot += cs.pop(0)
        else:
            tot -= qs.pop(0)
            tot += cs.pop(0)
    elif ps:
        tot -= ps.pop(0)
        tot += cs.pop(0)
    elif qs:
        tot -= qs.pop(0)
        tot += cs.pop(0)
    else:
        assert False
# print ps, qs

print tot

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 = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
T = deque(sorted(P, reverse=True))
R = deque(sorted(R, reverse=True))

ans = 0
for i in range(x+y):
    if T[0] >= R[0] and len(T) > 0:
        ans += T.popleft()
    elif len(R) > 0:
        ans += R.popleft()
    else:
        ans += T.popleft()

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 = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
T = deque(sorted(P, reverse=True))
R = deque(sorted(R, reverse=True))

ans = 0
for i in range(x+y):
    if T[0] >= R[0] or len(R) == 0:
        ans += T.popleft()
    else:
        ans += R.popleft()

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

# x <= a
# y <= b

P = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
T = deque(sorted(P, reverse=True))
R = deque(sorted(R, reverse=True))

ans = 0
for i in range(x+y):
    if T[0] >= R[0]:
        ans += T.popleft()
    else:
        ans += R.popleft()

print(ans)

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y, A, B, C = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse= 1)
q.sort(reverse= 1)
r.sort(reverse= 1)

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:min((X + Y), len(r))]
    # print(p_selected, q_selected)

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
        if p_selected[p_cnt] > q_selected[q_cnt] and q_cnt < Y:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1
            else:
                return ans
        elif p_cnt < X:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans
                
    return ans

ans = solve()

print(ans)

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y, A, B, C = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse= 1)
q.sort(reverse= 1)
r.sort(reverse= 1)

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:min((X + Y), len(r))]
    # print(p_selected, q_selected)

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
        if p_selected[p_cnt] > q_selected[q_cnt] and q_cnt < Y:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1
            else:
                return ans
        else:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans
    return ans

ans = solve()

print(ans)

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y, A, B, C = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse= 1)
q.sort(reverse= 1)
r.sort(reverse= 1)

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:(X + Y)]
    # print(p_selected, q_selected)

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
        if p_selected[p_cnt] > q_selected[q_cnt] and q_cnt < Y:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1

            else:
                return ans
        else:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans
    return ans

ans = solve()

print(ans)

Submission status: Runtime Error

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())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

Submission status: Runtime Error

Solution code:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x-y:]
q=sorted(list(map(int,input().split())))[-x-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

Submission status: Runtime Error

Solution code:
s,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[-x-y:]
q=sorted(list(map(int,input().split())))[-x-y:]
r=sorted(list(map(int,input().split())))
for i in range(len(p)):
  r.append(p[i])
  r.append(q[i])
r=sorted(r)[-x-y:]
print(sum(r))

Submission status: Runtime Error

Solution code:
X,Y,A,B,C=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
kouho=p[:X]+q[:Y]
kouho.sort()
for i in range(C):
    kouho[i]=max(kouho[i],r[i])
print(sum(kouho))

Submission status: Runtime Error

Solution code:
x = int(input())
y = int(input())
A = int(input())
B = int(input())
C = int(input())
P = input()
Q = input()
R = input()
p = sorted(P.split(" "), reverse=True)
q = sorted(Q.split(" "), reverse=True)
r = sorted(R.split(" "), reverse=True)
temp = 0
temp1 = 0
#print(p,q,r)
if int(p[y-1]) > int(r[0]) :
    for i in range(x) :
        temp = temp + int(p[i])
else :
    for i in range(x-1) :
        temp = temp + int(p[i])
    temp = temp + int(r[0])

if int(q[y-1]) > int(r[0]) :
    for i in range(y) :
        temp1 = temp1 + int(q[i])
else :
    for i in range(y-1) :
        temp1 = temp1 + int(q[i])
    temp1 = temp1 + int(r[0])
print(temp + temp1)

Submission status: Runtime Error

Solution code:
x = int(input())
y = int(input())
A = int(input())
B = int(input())
C = int(input())
P = input()
Q = input()
R = input()
p = sorted(P.split(" "), reverse=True)
q = sorted(Q.split(" "), reverse=True)
r = sorted(R.split(" "), reverse=True)
temp = 0
temp1 = 0
#print(p,q,r)
if int(p[y-1]) > int(r[0]) :
    for i in range(x) :
        temp = temp + int(p[i])
else :
    for i in range(x-1) :
        temp = temp + int(p[i])
    temp1 = temp1 + int(r[0])

if int(q[y-1]) > int(r[0]) :
    for i in range(y) :
        temp1 = temp1 + int(q[i])
else :
    for i in range(y-1) :
        temp1 = temp1 + int(q[i])
    temp1 = temp1 + int(r[0])
print(temp + temp1)

Submission status: Runtime Error

Solution code:
x = int(input())
y = int(input())
A = int(input())
B = int(input())
C = int(input())
P = input()
Q = input()
R = input()
p = sorted(P.split(" "), reverse=True)
q = sorted(Q.split(" "), reverse=True)
r = sorted(R.split(" "), reverse=True)
temp = 0
temp1 = 0
#print(p,q,r)
for i in range(int(x)):
    temp = temp + int(p[i])
if int(q[y-1]) > int(r[0]) :
    for i in range(y) :
        temp1 = temp1 + int(q[i])
else :
    for i in range(y-1) :
        temp1 = temp1 + int(q[i])
    temp1 = temp1 + int(r[0])
print(temp + temp1)

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)

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

i = 0
while l[i] < r[i] and i < len(l) and i < len(r):
    l[i] = r[i]
    i += 1

print(sum(l))

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, insort_left
import sys
def main():
	readlines = 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)

	p = p[a-x:]
	q = q[b-y:]
	a = len(p)
	b = len(q)
	ans = sum(p) + sum(q)
	p_count = 0
	q_count = 0

	for i in range(c):
		if p[p_count] < r[i] and q[q_count] < r[i]:
			if p[p_count] < q[q_count] and p_count != a:
				ans -= p[p_count]
				ans += r[i]
				#insort_left(p,r[i])
				if p_count < a:
					p_count += 1
			elif p[p_count] > q[q_count] and q_count != b:
				ans -= q[q_count]
				ans += r[i]
				#insort_left(q,r[i])
				if q_count < b:
					q_count += 1
		elif p[p_count] < r[i] and p_count != a:
			ans -= p[p_count]
			ans += r[i]
			#insort_left(p,r[i])
			if p_count < a:
				p_count += 1
		elif q[q_count] < r[i] and q_count != b:
			ans -= q[q_count]
			ans += r[i]
			#insort_left(q,r[i])
			if q_count < b:
				q_count += 1
		else:
			break

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, insort_left
import sys
def main():
	readlines = 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)

	p = p[a-x:]
	q = q[b-y:]
	ans = sum(p) + sum(q)
	p_count = 0
	q_count = 0

	for i in range(c):
		if p[p_count] < r[i] and q[q_count] < r[i]:
			if p[p_count] < q[q_count]:
				ans -= p[p_count]
				ans += r[i]
				#insort_left(p,r[i])
				if p_count < a-1:
					p_count += 1
			else:
				ans -= q[q_count]
				ans += r[i]
				#insort_left(q,r[i])
				if q_count < b-1:
					q_count += 1
		elif p[p_count] < r[i]:
			ans -= p[p_count]
			ans += r[i]
			#insort_left(p,r[i])
			if p_count < a-1:
				p_count += 1
		elif q[q_count] < r[i]:
			ans -= q[q_count]
			ans += r[i]
			#insort_left(q,r[i])
			if q_count < b-1:
				q_count += 1
		else:
			break

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, insort_left
import sys
def main():
	readlines = 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)

	p = p[a-x:]
	q = q[b-y:]
	ans = sum(p) + sum(q)
	p_count = 0
	q_count = 0

	for i in range(c):
		if p[p_count] < r[i] and q[q_count] < r[i]:
			if p[p_count] < q[q_count]:
				ans -= p[p_count]
				ans += r[i]
				#insort_left(p,r[i])
				p_count += 1
			else:
				ans -= q[q_count]
				ans += r[i]
				#insort_left(q,r[i])
				q_count += 1
		elif p[p_count] < r[i]:
			ans -= p[p_count]
			ans += r[i]
			#insort_left(p,r[i])
			p_count += 1
		elif q[q_count] < r[i]:
			ans -= q[q_count]
			ans += r[i]
			#insort_left(q,r[i])
			q_count += 1
		else:
			break

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, insort_left
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()

p = deque(p[a-x:])
q = deque(q[b-y:])
ans = sum(p) + sum(q)

for i in range(c):
	if p[0] < r[i] and q[0] < r[i]:
		if p[0] < q[0]:
			ans -= p.popleft()
			ans += r[i]
			insort_left(p,r[i])
		else:
			ans -= q.popleft()
			ans += r[i]
			insort_left(q,r[i])
	elif p[0] < r[i] and q[0] >= r[i]:
		ans -= p.popleft()
		ans += r[i]
		insort_left(p,r[i])
	elif p[0] >= r[i] and q[0] < r[i]:
		ans -= q.popleft()
		ans += r[i]
		insort_left(q,r[i])

print(ans)

Submission status: Runtime Error

Solution code:
import collections
x,y,aa,bb,cc = map(int,raw_input().split(' '))

aas = map(int, raw_input().split(' '))
bbs = map(int, raw_input().split(' '))
ccs = map(int, raw_input().split(' '))

aas.sort(key = lambda x:-x)
bbs.sort(key = lambda x:-x)
ccs.sort(key = lambda x:-x)


q1 = collections.deque(aas)
q2 = collections.deque(bbs)
q3 = collections.deque(ccs)

rq1 = collections.deque()
rq2 = collections.deque()
while(q3 and q2 and q1 and len(rq1) < x and len(rq2) < y):
	if q3[0] > max(q1[0], q2[0]):
		if q2[0] >= q1[0]:
			rq1.append(q3.popleft())
		else:
			rq2.append(q3.popleft())
	else:
		if q2[0] >= q1[0]:
			rq2.append(q2.popleft())
		else:
			rq1.append(q1.popleft())

while(len(rq1) < x):
	if q3 and q3[0] > q1[0]:
		rq1.append(q3.popleft())
	else:
		rq1.append(q1.popleft())
while(len(rq2) < y):
	if q3 and q3[0] > q2[0]:
		rq1.append(q3.popleft())
	else:
		rq1.append(q2.popleft())

print sum(rq1) + sum(rq2)

Submission status: Runtime Error

Solution code:
problem_info = input().split()
eat_red = int(problem_info[0])
eat_green = int(problem_info[1])
red_num = int(problem_info[2])
green_num = int(problem_info[3])
non_num = int(problem_info[4])

red_eval = sorted([int(i) for i in input().split()],reverse=True)[:eat_red]
green_eval = sorted([int(i) for i in input().split()],reverse=True)[:eat_green]
non_eval = sorted([int(i) for i in input().split()])

min = min(green_eval) if min(red_eval) > min(green_eval) else min(red_eval)

if min < max(non_eval):
  for i in range(non_num):
    if min(red_eval) > min(green_eval):
      if min(green_eval) < max(non_eval):
        green_eval[-1] = max(non_eval)
        green_eval.sort(reverse=True)
    else:
      if min(red_eval) < max(non_eval):
        red_eval[-1] = max(non_eval)
        red_eval.sort(reverse=True)
    min = min(green_eval) if min(red_eval) > min(green_eval) else min(red_eval)
    if min > max(non_eval):
      break
print(sum(red_eval)+sum(green_eval))

Submission status: Runtime Error

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

p = sorted(list(map(int,input().split()))) #A
q = sorted(list(map(int,input().split()))) #B
r = sorted(list(map(int,input().split()))) #C

xlist = p[-X:] #X
ylist = q[-Y:] #Y


for i in range(min(X,Y)):
    if xlist[i] < ylist[i] and min(xlist) < max(r):
        xlist.remove(min(xlist))
        xlist.append(max(r))
        r.pop()
    elif ylist[i] < xlist[i] and min(ylist) < max(r):
        ylist.remove(min(xlist))
        ylist.append(max(r))
        r.pop()
    else:
        continue

print(sum(xlist)+sum(ylist))

Submission status: Runtime Error

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)

pnum, qnum, rnum = 0, 0, 0
ans = 0
for i in range(x+y):
    O = [0 for j in range(3)]
    if pnum >= x:
        O[0] = 0
    else:
        O[0] = P[pnum]
    
    if qnum >= y:
        O[1] = 0
    else:
        O[1] = Q[qnum]

    O[2] = R[rnum] 
    c = 0
    num = 0
    for j in range(3):
        if c <= O[j]:
            c = O[j]
            num = j
        else:
            pass
    
    if num == 0:
        pnum += 1
    elif num == 1:
        qnum += 1
    elif num == 2:
        rnum += 1
    else:
        pass
    ans += c
    
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()))

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

i = 0
j = 0
k = 0
ans = 0
while  i+j+k < X+Y:
    if i == X:
        for n in range(Y-(j+k)):
            if Q[j] > R[k]:
                ans += Q[j]
                j += 1
            else:
                ans += R[k]
                k += 1
    elif j == Y:
        for n in range(X-(i+k)):
            if P[i] > R[k]:
                ans += P[i]
                i += 1
            else:
                ans += R[k]
                k += 1
    else:
        if P[i] >= max(Q[j], R[k]):
            ans += P[i]
            i += 1
        elif Q[j] >= max(P[i], R[k]):
            ans += Q[j]
            j += 1
        else:
            ans += R[k]
            k += 1

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:12:42 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7



#N = int(input())
X, Y, A, B, C = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
n = list(map(int,input().split()))

r.sort()
g.sort()
n.sort()

x, y = A-X, B-Y
z = C-1
ans = 0
ans += sum(r[x:])
ans += sum(g[y:])
#print(x,y,z,r[x],g[y],n[z],ans)
while (n[z] > r[x] or n[z] > g[y]) and z >= 0:
    if r[x] < g[y]:
        ans += (n[z] - r[x])
        x += 1
        z -= 1
    else:
        ans += (n[z] - g[y])
        y += 1
        z -= 1
#    print(x,y,z,r[x],g[y],n[z],ans)
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import bisect
    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())),reverse=True)
    ans = 0
    if x<=a:
        p = p[a-x:a]
    if y<=b:
        q = q[b-y:b]
    while True:
        if len(r)==0:
            break
        if p[0]>q[0]:
            if q[0]<r[0]:
                bisect.insort_right(q,r.pop(0))
                q.pop(0)
            else:
                break
        else:
            if p[0]<r[0]:
                bisect.insort_right(p,r.pop(0))
                q.pop(0)
            else:
                break
    print(sum(p)+sum(q))
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int,input().split())
r=sorted(list(map(int,input().split())),reverse=True)
g=sorted(list(map(int,input().split())),reverse=True)
w=sorted(list(map(int,input().split())),reverse=True)
ans=0
for i in range(x):
    if r[0]>=w[0]:
        ans+=r[0]
        r=r[1:]
    else:
        ans+=w[0]
        w=w[1:]
for i in range(y):
    if g[0]>=w[0]:
        ans+=g[0]
        g=g[1:]
    else:
        ans+=w[0]
        w=w[1:]
print(ans)

Submission status: Runtime Error

Solution code:
X,Y,A,B,C = map(int,input().split())
pList = [int(x) for x in input().split()]
qList = [int(x) for x in input().split()]
rList = [int(x) for x in input().split()]

pList.sort(reverse=True)
qList.sort(reverse=True)
rList.sort(reverse=True)

stackX=[]
stackY=[]
stackR=[]

for i in range(X):
    stackX.append(pList[i])

for i in range(Y):
    stackY.append(qList[i])

for i in range(C):
    if len(stackX)==0:
        x = pow(10,9)
    else:
        x = stackX[-1]

    if len(stackY)==0:
        y = pow(10,9)
    else:
        y = stackY[-1]
    r = rList[i]

    if r < x and r < y:
        break
    elif x < y:
        stackX.pop()
        stackR.append(r)
    else:
        stackY.pop()
        stackR.append(r)
print(sum(stackX) + sum(stackY) + sum(stackR))