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:
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();

let [X, Y, A, B, C] = reader.readInts();

let p: number[] = reader.readInts()
let q: number[] = reader.readInts()
let r: number[] = reader.readInts()

let decreasingOrder = (a: number, b: number) => b-a;
let increasingOrder = (a: number, b: number) => a-b;

p.sort(decreasingOrder)
q.sort(decreasingOrder)
r.sort(increasingOrder)

while (p.length > X)
    p.pop();

while (q.length > Y)
    q.pop();

let pq: number[] = [];
let i = 0, j = 0;

// Merge arrays
for(; i < X; i++) {
    while (j < Y && q[j] >= p[i]) {
        pq.push(q[j++]);
    }
    pq.push(p[i]);
}

while (j < Y) {
    pq.push(q[j++]);
}

i = pq.length-1;

while (i >= 0 && r.length > 0) {
    if (pq[i] >= r[r.length-1]) {
        r.pop();
    } else {
        pq[i] = r.pop();
    }
}

console.log(pq.reduce((prev, current) => prev+current, 0));

Submission status: Runtime Error

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

red_list=[int(i) for i in input().split()]
green_list=[int(i) for i in input().split()]
non_col_list=[int(i) for i in input().split()]

red_list.sort()
green_list.sort()
non_col_list.sort()

eat_red=[]
eat_green=[]
for i in range(x):
    eat_red.append(red_list.pop())
for i in range(y):
    eat_green.append(green_list.pop())


# eat_redにX個の赤いリンゴの美味しさ(降順)
# eat_greenにY個の緑のリンゴの美味しさ(降順)
# non_col_listにC個の無色のリンゴの美味しさ(昇順)


ans=0

def irekae(eat_list,non_col_list):
    if non_col_list==[]:
        return False
    global ans
    taishou=eat_list.pop()
    non_col=non_col_list.pop()
    if taishou<non_col:
        ans+=non_col
        return True
    else:
        eat_list.append(taishou)
        return False

while True:
    if eat_red[-1]<eat_green[-1]:
        if not irekae(eat_red,non_col_list):
            break

    else:
        if not irekae(eat_green,non_col_list):
            break

print(ans+sum(eat_green)+sum(eat_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(reverse=True)
p=p[:x]
q=q[:y]
ans=p+q
ans.sort(reverse=True)
ans=[0]+ans
nowi=x+y
r=[0]+r
nowr=0
while nowr<=c+1 and nowi>0 and r[nowr+1]>ans[nowi]:
  nowi+=-1
  nowr+=1
ans_=0
for i in range(nowi+1):
  ans_+=ans[i]
for j in range(nowr+1):
  ans_+=r[j]
print(ans_)

Submission status: Runtime Error

Solution code:
from collections import deque
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=deque(sorted(list(map(int,input().split())),reverse=True))
p=deque(p[:x])
q=deque(q[:y])
ans=sum(p)+sum(q)

while p[-1]<r[0] or q[-1]<r[0]:
  if p[-1]<q[-1]:
    ans+=r[0]-p[-1]
    r.popleft()
    p.pop()
  else:
    ans+=r[0]-q[-1]
    r.popleft()
    q.pop()
  if p==[] or q==[] or r==[]:
    break
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.sort()
q.sort()
list.sort(r, reverse=True)

p = p[(A-X):]
q = q[(B-Y):]

i_p = 0
i_q = 0
for i_r in range(C):
    if p[i_p] <= q[i_q]:
        if p[i_p] < r[i_r]:
            p[i_p] = r[i_r]
            i_p += 1
    else:
        if q[i_q] < r[i_r]:
            q[i_q] = r[i_r]
            i_q += 1

    if i_p >= len(p) and i_q >= len(Q):
        break

res = 0

for i in range(len(p)):
    res += p[i]

for i in range(len(q)):
    res += q[i]

print(res)

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)

p = deque(p)
q = deque(q)
r = deque(r)

ans = 0
for _ in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()
for _ in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)

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.sort()
B.sort()
C.sort(
ans = 0

for i in range(X):
    if A[-1] >= C[-1]:
        ans += A[-1]
        A.pop()
    else:
        ans += C[-1]
        C.pop()

for i in range(Y):
    if B[-1] >= C[-1]:
        ans += B[-1]
        B.pop()
    else:
        ans += C[-1]
        C.pop()
        
print(ans)

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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = 0

for i in range(X):
    if A[0] >= C[0]:
        ans += A[0]
        A.pop(0)
    else:
        ans += C[0]
        C.pop(0)

for i in range(Y):
    if B[0] >= C[0]:
        ans += B[0]
        B.pop(0)
    else:
        ans += C[0]
        C.pop(0)
        
print(ans)

Submission status: Runtime Error

Solution code:
2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Submission status: Runtime Error

Solution code:
2 2 2 2 2
8 6
9 1
2 1

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)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    red_worst = red[-red_no_eat - 1] if red_no_eat <= X else 10 ** 10
    green_worst = green[-green_no_eat - 1] if green_no_eat <= Y else 10 ** 10
    if no > red_worst or no > green_worst:
        if red_worst < green_worst:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

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)

red = p[:X]
green = q[:Y]

red_no_eat = 0
green_no_eat = 0
for no in r:
    if no > red[-red_no_eat - 1] or no > green[-green_no_eat - 1]:
        if red[-red_no_eat - 1] < green[-green_no_eat-1]:
            red_no_eat += 1
        else:
            green_no_eat += 1
print(sum(p[:X-red_no_eat]) + sum(q[:Y-green_no_eat]) + sum(r[:red_no_eat+green_no_eat]))

Submission status: Runtime Error

Solution code:
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + r)[-x-y:]))

Submission status: Runtime Error

Solution code:
import heapq
X, Y, A, B, C = map(int, input().split())
Av = list(map(int, input().split()))
Bv = list(map(int, input().split()))
Cv = list(map(int, input().split()))
heapq.heapify(Av)
heapq.heapify(Bv)
heapq.heapify(Cv)
for i in range(A-X):
    heapq.heappop(Av)
for i in range(B-Y):
    heapq.heappop(Bv)
if C > X+Y:
    for i in range(C-(X+Y)):
        heapq.heappop(Cv)
    NotTake = X+Y
else:
    NotTake = C
C = NotTake
for _ in range(NotTake):
    Amin = heapq.heappop(Av)
    Bmin = heapq.heappop(Bv)
    Cmin = heapq.heappop(Cv)
    if X > 0 and Amin == min(Amin, Bmin, Cmin):
        heapq.heappush(Bv, Bmin)
        heapq.heappush(Cv, Cmin)
        X -= 1
    elif Y > 0 and Bmin == min(Bmin, Cmin):
        heapq.heappush(Av, Amin)
        heapq.heappush(Cv, Cmin)
        Y -= 1
    elif C > 0:
        heapq.heappush(Av, Amin)
        heapq.heappush(Bv, Bmin)
        C -= 1
    else:
        break
print(sum(Av)+sum(Bv)+sum(Cv))

Submission status: Runtime Error

Solution code:
X,Y,A,B,C = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

r.append(0)
for i in range(X,A):
    p[i] = 0
for i in range(Y,B):
    q[i] = 0

a = 0
b = 0
c = 0
cnt = 0

for i in range(X+Y):
    if (not a == X) and p[a] >= q[b] and p[a] >= r[c]:
        cnt += p[a]
        a += 1
    elif (not b == Y) and q[b] >= r[c]:
        cnt += q[b]
        b += 1
    else:
        cnt += r[c]
        c += 1
print(cnt)

Submission status: Runtime Error

Solution code:

X, Y, A, B, C = map(int, input().split())
P = sorted(map(int, input().split()))
Q = sorted(map(int, input().split()))
R = sorted(map(int, input().split()))

ans = 0
for _ in range(X):
    if P[-1] > R[-1]:
        ans += P.pop()
    else:
        ans += R.pop()

for _ in range(Y):
    if Q[-1] > R[-1]:
        ans += Q.pop()
    else:
        ans += R.pop()

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    elif eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while True:
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    if eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C or (eat_p[i] > r[k] and eat_q[j] > r[k]):
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
i, j, k = -1, -1, 0
while eat_p[i] < r[k] or eat_q[j] < r[k]:
    if eat_p[i] < eat_q[j]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    else:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if k == C:
        break
    if i == -A:
        i = 0
    if j == -B:
        j = 0

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()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or (ri>=x and gi<y):
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = blank
      ri += 1
print(sum(red)+sum(green))

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()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or (ri>=x and gi<y):
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = r[bi]
      ri += 1
print(sum(red)+sum(green))

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()
red = p[-x:]
green = q[-y:]
ri, gi = 0, 0
for blank in r:
  if (red[ri]>green[gi] and gi<y) or ri>=x:
    if blank>green[gi]:
      green[gi] = blank
      gi += 1
  elif ri<x:
    if blank>red[ri]:
      red[ri] = r[bi]
      ri += 1
print(sum(red)+sum(green))

Submission status: Runtime Error

Solution code:
x,y,a,b,c = map(int, input().split())
li_p = list(map(int, input().split()))
li_q = list(map(int, input().split()))
li_r = list(map(int, input().split()))
li_p.sort(reverse=True)
li_q.sort(reverse=True)
li_r.sort(reverse=True)
p,q = [],[]
for i in range(x):
  r.append(li_p[i])
for i in range(y):
  r.append(li_q[i])
for i in range(c):
  r.append(li_r[i])
r.sort(reverse=True)
print(sum(r[:x+y]))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

n = 0
np = 0
nq = 0
ans = 0
while n < x + y:
    cs = []
    if p and np < x:
        cs.append(p[-1])
    if q and nq < y:
        cs.append(q[-1])
    if r:
        cs.append(r[-1])
    m = max(cs)
    if m == r[-1]:
        ans += r.pop()
    elif m == p[-1]:
        ans += p.pop()
        np += 1
    else:
        ans += q.pop()
        nq += 1
    n += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
	
X, Y, A, B, C = MAP()
p = deque(sorted(LIST(), reverse=True))
q = deque(sorted(LIST(), reverse=True))
r = deque(sorted(LIST(), reverse=True))

x = 0
y = 0
z = 0
ans = 0
while x+y+z < X+Y:
	compare = (p[0], q[0], r[0])

	if p[0] == max(compare):
		x += 1
		ans += p.popleft()
		if x == X:
			p = [0]
	elif q[0] == max(compare):
		y += 1
		ans += q.popleft()
		if y == Y:
			q = [0]
	else:
		z += 1
		ans += r.popleft()

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()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(u)
        if t[1] == 'r':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(v)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)

Submission status: Runtime Error

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

a_list=list(map(int,input().split()))
a_list=sorted(a_list)
b_list=list(map(int,input().split()))
b_list=sorted(b_list)
a_list=a_list[-x:]
b_list=b_list[-y:]
c_list=list(map(int,input().split()))
for i in range(c):
    c_list[i]=-c_list[i]
import heapq
heapq.heapify(a_list)
heapq.heapify(b_list)
heapq.heapify(c_list)

flag=True
while flag and c_list:
    x=heapq.heappop(c_list)
    x=x*(-1)
    #ｃ_listの中でのもっとも大きい値
    min_a=heapq.heappop(a_list)
    min_b=heapq.heappop(b_list)
    if min(min_a,min_b)>=x:
        flag=False
        heapq.heappush(a_list,min_a)
        heapq.heappush(b_list,min_b)
    else:
        if min_a>=min_b:
            heapq.heappush(a_list,min_a)
            heapq.heappush(b_list,x)
         
        elif min_a<min_b:
            heapq.heappush(b_list,min_b)
            heapq.heappush(a_list,x)

sum_a=sum(list(a_list))
sum_b=sum(list(b_list))

print(sum_a+sum_b)

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(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
l = p[:X]+q[:Y]
l.sort()
s = sum(l)
ans = s

for i in range(C):
    ans = max(ans, s-l[i]+r[i])

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    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)

    ans = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(X):
        if p[i] < r[k] and k < C:
            ans += r[k]
            k += 1
        else:
            ans += p[i]
            i += 1
            

    for l in range(Y):
        if q[j] < r[k] and k < C:
            ans += r[k]
            k += 1
        else:
            ans += q[j]
            j += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    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)

    ans = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(X):
        if p[i] >= r[k] or k == C:
            ans += p[i]
            i += 1
        else:
            ans += r[k]
            k += 1

    for l in range(Y):
        if q[j] >= r[k] or k == C:
            ans += q[j]
            j += 1
        else:
            ans += r[k]
            k += 1
    print(ans)

if __name__ == "__main__":
    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)

ans = p[:x] + q[:y]

for i in range(x + y):
  if ans[i] < r[0]:
    ans[i] = r[0]
    r.pop(0)

print(sum(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()))
sm=0
p.sort()
q.sort()
r.sort(reverse=True)

p=p[(a-x):]
q=q[(b-y):]

p_idx=0
q_idx=0
plen=len(p)
qlen=len(q)
for i in range(c):
    #処理が終わる時
    if p[p_idx]>r[i] and q[q_idx]>r[i]:
        break
    #全部入れ替わる
    if p_idx==plen and q_idx==qlen:
        break
    if q_idx==qlen:
        if p[p_idx]>r[i]:
            break
        else:
            p[p_idx]=r[i]
            p_idx+=1
    if p_idx==plen:
        if q[q_idx]>r[i]:
            break
        else:
            q[q_idx]=r[i]
            q_idx+=1
    if p[p_idx]<=q[q_idx]:
        p[p_idx]=r[i]
        p_idx+=1
    if q[q_idx]<=p[p_idx]:
        q[q_idx]=r[i]
        q_idx+=1

ans=sum(p)+sum(q)
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()))
sm=0
p.sort()
q.sort()
r.sort(reverse=True)

p=p[(a-x):]
q=q[(b-y):]

p_idx=0
q_idx=0
plen=len(p)
qlen=len(q)
for i in range(c):
    #処理が終わる時
    if p[p_idx]>r[i] and q[q_idx]>r[i]:
        break
    #全部入れ替わる
    if p_idx==plen and q_idx==qlen:
        break
    #どちらかが全部入れ替わる
    #それ以外
    if p[p_idx]<=q[q_idx] or q_idx==qlen:
        if p[p_idx]>r[i]:
            break
        else:
            p[p_idx]=r[i]
            p_idx+=1
    if q[q_idx]<=p[p_idx] or p_idx==plen:
        if q[q_idx]>r[i]:
            break
        else:
            q[q_idx]=r[i]
            q_idx+=1

ans=sum(p)+sum(q)
print(ans)

Submission status: Runtime Error

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i == 0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == C-1:
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

Submission status: Runtime Error

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
XY = X+Y
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == max(C-1,XY-1):
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

Submission status: Runtime Error

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQ = sorted(P+Q,reverse = True)
total = sum(PQ)
for i in range(C):
    if R[i] < PQ[-(i+1)]:
      if i ==0:
        ans = total
      else:
        ans = total + sum(R[:i]) - sum(PQ[-i:])
      break
    if i == C-1:
      ans = total + sum(R[:i+1]) - sum(PQ[-(i+1):])
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
#inp = input
fin = open("case_21.txt")
inp = fin.readline

X, Y, A, B, C = map(int, inp().split())

#red = np.array(list(map(int, inp().split())), np.int32)
#green = np.array(list(map(int, inp().split())), np.int32)
#white = np.array(list(map(int, inp().split())), np.int32)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0
countw = 0
while X > countr and Y > countg and (X+Y > countr+countg+countw):
    if red[idr] >= green[idg]:
        if idw >= C or red[idr] >= white[idw]:
            #eat red
            total += red[idr]
            idr += 1
            countr += 1
        elif idw < C:
            #eat white
            total += white[idw]
            idw += 1
            countw += 1
    else:
        if idw >= C or green[idg] >= white[idw]:
        # eat green
            total += green[idg]
            idg += 1
            countg += 1
        else:
            #eat white
            total += white[idw]
            idw += 1
            countw += 1

#eat remain
if Y <= countg:
    while X > countr+countw:
        # compare red 1st
        if idw < C and red[idr] < white[idw]:
            # eat white
            total += white[idw]
            idw += 1
        else:
            # eat red
            total += red[idr]
            idr += 1
        countr += 1

if X <= countr:
    while Y > countg+countw:
        # compare green 1st
        if idw < C and green[idg] < white[idw]:
            # eat white
            total += white[idw]
            idw += 1
        else:
            # eat green
            total += green[idg]
            idg += 1
        countg += 1

print(int(total))

Submission status: Runtime Error

Solution code:
import numpy as np
#inp = input
fin = open("case_21.txt")
inp = fin.readline

X, Y, A, B, C = map(int, inp().split())

#red = np.array(list(map(int, inp().split())), np.int32)
#green = np.array(list(map(int, inp().split())), np.int32)
#white = np.array(list(map(int, inp().split())), np.int32)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
fin.close()

#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()

idr = 0
idg = 0
idw = 0

total = 0.0
countr = 0
countg = 0

while X > countr and Y > countg:
    if red[idr] >= green[idg] and red[idr] >= white[idw]:
        #eat red
        total += red[idr]
        idr += 1
        countr += 1
    elif green[idg] > red[idr] and green[idg] >= white[idw]:
        # eat green
        total += green[idg]
        idg += 1
        countg += 1
    else:
        if red[idr] >= green[idg]:
            #compare green 1st
            if idw < C and green[idg] < white[idw]:
                #eat white
                total += white[idw]
                idw += 1
            else:
                #eat green
                total += green[idg]
                idg += 1
            countg += 1

        else:
            #compare red 1st
            if idw < C and red[idr] < white[idw]:
                #eat white
                total += white[idw]
                idw += 1
            else:
                #eat red
                total += red[idr]
                idr += 1

            countr += 1

#eat remain
while X > countr:
    # compare red 1st
    if idw < C and red[idr] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat red
        total += red[idr]
        idr += 1
    countr += 1

while Y > countg:
    # compare green 1st
    if idw < C and green[idg] < white[idw]:
        # eat white
        total += white[idw]
        idw += 1
    else:
        # eat green
        total += green[idg]
        idg += 1
    countg += 1

print(int(total))