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: Wrong Answer

Solution code:
from collections import deque
x,y,a,b,c = map(int,input().split())
P = deque(sorted(list(map(int,input().split())),reverse=True)[:x])
Q = deque(sorted(list(map(int,input().split())),reverse=True)[:y])
R = deque(sorted(list(map(int,input().split())),reverse=True))
p = P.pop()
q = Q.pop()
r = R.popleft()
ans = 0

while p < r or q < r:
    ans += r
    if len(R) != 0:   
        r = R.pop()
    else:
        r = 0
    if p < q:
        if len(P) != 0:   
            p = P.pop()
        else:
            p = 10**10
    else:
        if len(Q) != 0:   
            q = Q.pop()
        else:
            q = 10**10
            
ans += sum(P)+sum(Q)
if p != 10**10:
    ans += p
if q != 10**10:
    ans += q
print(ans)

Submission status: Wrong Answer

Solution code:
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()))

pp = sorted(pl,reverse=True)[:x-1]
qq = sorted(pl,reverse=True)[:y-1]
all = pp + qq + rl
print(sum(sorted(pl,reverse=True)[:x+y-1]))

Submission status: Wrong Answer

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)

a1 = x
b1 = y
for i in range(c):
  if (p[a1-1] >= r[i]) and (q[b1-1] >= r[i]):
    continue
  else:
    if p[a1-1] < q[b1-1]:
      p[a1-1] = r[i]
      if a1 > 0:
        a1 -= 1
    else:
      q[b1-1] = r[i]
      if b1 > 0:
        b1 -= 1
print(sum(p[:x])+sum(q[:y]))

Submission status: Wrong Answer

Solution code:
(x,y,a,b,c)=map(int,input().split())
a1=input().split()
a1=list(map(int,a1))
a2=sorted(a1)
b1=list(map(int,input().split()))
b2=sorted(b1)
print(b1)
c1=list(map(int,input().split()))
c2=sorted(c1)
k=0
o=0
p=0
for i in range(x-1,-1,-1):
    k=k+a2[i]
for j in range(y-1,-1,-1):
    o=o+b2[i]
for l in range(c-1,-1,-1):
    p=p+c2[i]
print(k+o+p)

Submission status: Wrong Answer

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,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)

ans = 0
ans += sum(p[:x])+sum(q[:y])
lp = (p[:x])
lq = (q[:y])
#print(lp)
#print(lq)
flag = 0
for i in range(x):
    if lp[i] < r[0]:
        del lp[:i]
        flag = 1
        break
if flag == 0:
  lp = []
  
flag = 0
for i in range(y):
    if lq[i] < r[0]:
        del lq[:i]
        flag = 1
        break
if flag == 0:
  lq = []
        
temp1 = 0
temp2 = 0
#print(lp)
#print(lq)
for i in range(1,10**9):
    #if lp[i] >= r[i] and lq[i] >= r[i]:
    #    break
    if i == max(x,y) or i == c+1 or (len(lq) < i and len(lp) < i):
      break
    elif i == y or len(lq) < i:
        print(i)
        temp2 = ans - lp[-i] + r[i-1]
    elif i == x or len(lp) < i:
        temp1 = ans - lq[-i] + r[i-1]
    else:
        temp1 = ans - lp[-i] + r[i-1]
        temp2 = ans - lq[-i] + r[i-1]
    ans = max(temp1,temp2,ans)
print(ans+1)

Submission status: Wrong Answer

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())))[::-1]

ans = sorted(p[A-X:] + q[B-Y:])
ans_sum = [ans[0]]
for i in range(1, X+Y):
    ans_sum.append(ans_sum[i-1] + ans[i])

r_sum = [r[0]]
for i in range(1, C):
    r_sum.append(r_sum[i-1] + r[i])

index = -1
for i in range(min(C, X+Y)):
    if r_sum[i] <= ans_sum[i]:
        index = i
        break

if index == 0:
    print(ans_sum[-1])
elif index == -1 and C >= X+Y:
    print(r_sum[X+Y-1])
else:
    if index == -1:
        index = C
    print(ans_sum[-1] + (r_sum[index-1] - ans_sum[index-1]))

Submission status: Wrong Answer

Solution code:
input_1st = input()
input_2nd = input()
input_3rd = input()
input_4th = input()

split_input_1st = input_1st.split()
split_input_2nd = input_2nd.split()
split_input_3rd = input_3rd.split()
split_input_4th = input_4th.split()

x = int(split_input_1st[0])
y = int(split_input_1st[1])
a = int(split_input_1st[2])
b = int(split_input_1st[3])
c = int(split_input_1st[4])

result = 0
if x > y:
    red_list = split_input_2nd + split_input_4th
    red_list = sorted(red_list, reverse=True)
    # print('red_list: ', red_list)
    for i in range(x):
        result += int(red_list[i])
        # print('red_list[i]: ', red_list[i])
    
    green_list = split_input_3rd
    green_list = sorted(green_list, reverse=True)
    # print('green_list', green_list)
    for i in range(y):
        result += int(green_list[i])
        # print('green_list[i]: ', green_list[i])
else:
    green_list = split_input_3rd + split_input_4th
    green_list = sorted(green_list, reverse=True)
    # print('green_list', green_list)
    for i in range(y):
        result += int(green_list[i])
        # print('green_list[i]: ', green_list[i])
    
    red_list = split_input_2nd
    red_list = sorted(red_list, reverse=True)
    # print('red_list: ', red_list)
    for i in range(x):
        result += int(red_list[i])
        # print('red_list[i]: ', red_list[i])
            
print(result)

Submission status: Wrong Answer

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

Reds = np.array(Reds)
Greens = np.array(Greens)
Ns = np.array(Ns)

Reds = np.sort(Reds)[::-1]
Greens = np.sort(Greens)[::-1]
Ns = np.sort(Ns)[::-1]

sum = 0
x_min_idx=X-1
y_min_idx=Y-1

for n in Ns:
    if Reds[x_min_idx] < Greens[y_min_idx] and x_min_idx>-1:
        if Reds[x_min_idx] < n:
            Reds[x_min_idx]=n
            x_min_idx += -1
    elif y_min_idx>-1:
        if Greens[y_min_idx] < n:
            Greens[y_min_idx]=n
            y_min_idx += -1

for i in range(X):
    sum += Reds[i]
for i in range(Y):
    sum += Greens[i]
print(sum)

Submission status: Wrong Answer

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)
p = p[:x]
q.sort(reverse=True)
q = q[:y]
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(greens) == 0:
        if len(uncolor) > 0:
            if reds[0] >= uncolor[0]:
                eat = reds.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = reds.popleft()
        ans += eat
        red_cnt += 1
        continue

    if len(reds) == 0:
        if len(uncolor) > 0:
            if greens[0] >= uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
        else:
            eat = greens.popleft()
        ans += eat
        green_cnt += 1
        continue

    if len(uncolor) == 0:
        for i in range(x - red_cnt):
            eat = reds.popleft()
            ans += eat
        for i in range(y - green_cnt):
            eat = greens.popleft()
            ans += eat
        red_cnt = x
        green_cnt = y
        continue

    if red_cnt < x and green_cnt < y:
        if reds[0] > greens[0] and reds[0] >= uncolor[0]:
            eat = reds.popleft()
            ans += eat
            red_cnt += 1
        elif reds[0] < greens[0] and greens[0] >= uncolor[0]:
            eat = greens.popleft()
            ans += eat
            green_cnt += 1
        elif 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
    elif red_cnt < x:
        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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

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

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

p_i = 0
q_i = 0
r_i = 0

ans1 = 0
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans1 += p[p_i]
        p_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans1 += q[q_i]
        q_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1


ans2 = 0
p_i = 0
q_i = 0
r_i = 0
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans2 += q[q_i]
        q_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans2 += p[p_i]
        p_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1

ans3 = 0
if X + Y <= C:
    ans3 = sum(r[:(X+Y)])

print(max(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
import collections
def main():

    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)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] >= p[i] and r[k] >= q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] > r[k]:
                countA += 1
                ans += p[i]
                i += 1
            elif q[j] > r[k]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]

    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])

    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y-(countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])

    return out


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

Submission status: Wrong Answer

Solution code:
from itertools import *

def merge(x,y):
  while 1:
    if x and y and x[0] >= y[0] or (not (x and y)) and x:
      yield x.pop(0)
    elif y:
      yield y.pop(0)
    else:
      return

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

S = sum(islice(merge(P,R), X))
S += sum(islice(merge(Q,R), Y))
print(S)

Submission status: Wrong Answer

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    k = 0
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
                k += 1
            elif Q[j-1] < P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
                k += 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
                k += 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
                k += 1
            else:
                break
        else:
            break
    return sum(P[:i] + Q[:j] + R[:k])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = list(map(int,input().split()))
p = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
q = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
r = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]

pi = 0
qi = 0
ri = 0
res = 0
while pi + qi + ri != X + Y:
  if ( qi == Y or p[pi] >= q[qi] ) and p[pi] >= r[ri]:
    # print("p")
    res += p[pi]
    pi += 1
  elif ( pi == X or q[qi] >= p[pi] ) and q[qi] >= r[ri]:
    # print("q")
    res += q[qi]
    qi += 1
  elif  ( qi == X or r[ri] >= q[qi]) and (pi == Y or r[ri] >= p[pi]):
    #print("r")
    res += r[ri]
    ri += 1
  # print(pi + qi + ri != X + Y)
print(res)

Submission status: Wrong Answer

Solution code:
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
la=1000000
ans=0
for i in range(x):
    if len(r)==0:
        _p=heapq.heappop(p)
        ans-=_p
        if i==x-1:
            la=-_p
        continue
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<=_r:
        ans-=_p
        heapq.heappush(r,_r)
        if i==x-1:
            la=-_p
    else:
        ans-=_r
        heapq.heappush(p,_p)

for i in range(y):
    if len(r)==0:
        _q=heapq.heappop(q)
        ans-=_q
        if i==y-1:
            la=min(la,-_q)
        continue
    _q,_r=heapq.heappop(q),heapq.heappop(r)
    if _q<=_r:
        ans-=_q
        heapq.heappush(r,_r)
        if i==y-1:
            la=min(la,-_q)
    else:
        ans-=_r
        heapq.heappush(q,_q)
if len(r)==c:
    print(ans-r[0]-la)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def input_multiple_number():
    return map(int, input().split())
def input_multiple_number_as_list():
    return list(map(int, input().split()))

xgiven,ygiven,agiven,bgiven,cgiven = input_multiple_number()

p_array = input_multiple_number_as_list()
q_array = input_multiple_number_as_list()
r_array = input_multiple_number_as_list()
INF = 99999999999999999
p_array.sort()
q_array.sort()
r_array.sort()

#ぐりいでぃい
i = xgiven
p_array = p_array[0:xgiven]
q_array = q_array[0:ygiven]
xxx_array = p_array+q_array+r_array

xxx_array.sort()
nnn_arrat = xxx_array[0:xgiven+ygiven]

value=0
for aaaaa in nnn_arrat:
	value += aaaaa

print(value)

Submission status: Wrong Answer

Solution code:
# E
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 = p[:x]
q = q[:y]
r = r
e = 0
for i in range(min(x, y, c)):
    if p[-1-i] > q[-1-i]:
        if q[-1-i] < r[e]:
            q[-1-i] = r[e]
            e += 1
        else:
            continue
    elif p[-1-i] <= q[-1-i]:
        if p[-1-i] < r[e]:
            p[-1-i] = r[e]
            e += 1
            
print(sum(p)+sum(q))

Submission status: Wrong Answer

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

red_apples = sorted([int(i) for i in input().split()])
green_apples = sorted([int(i) for i in input().split()])
no_apples = sorted([int(i) for i in input().split()])[::-1]
ans = sum(red_apples[::-1][:x]) + sum(green_apples[::-1][:y])

i = 0
j = 0
k = 0
# 赤と緑の小さいやつを無職のりんごの大きいもので置き換えればよさそう
for n in no_apples:
    # print(green_apples[j])
    if red_apples[i] < green_apples[j] and red_apples[i] < n:
        ans -= red_apples[i] + n
        i += 1
        # print('hoge')
    elif green_apples[j] < red_apples[i] and green_apples[j] < n:
        # print('ans', ans)
        ans = ans - green_apples[j] + n
        # print('fuga', j, green_apples[j], n, ans)
        j += 1
    # print(n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
readline = sys.stdin.readline
def main():
  x,y,a,b,c=map(int,readline().split())

  red=sorted(int(i) for i in readline().split())
  green=sorted(int(i) for i in readline().split())
  nc=sorted([int(i) for i in readline().split()], reverse=1)

  for i in nc:
    if len(red)>=x:
      tr=red[-x]
      if i>=tr:
        bisect.insort_left(red,i)
        continue
    else:
      bisect.insort_left(red,i)
      continue
    if len(green)>=y:
      tg=green[-y]
      if i>=tg:
        bisect.insort_left(green,i)
    else:
      bisect.insort_left(green,i)
  res=sum(red[-x:])+sum(green[-y:])
  print(res)

main()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

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

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

p_i = 0
q_i = 0
r_i = 0

ans1 = 0
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans1 += p[p_i]
        p_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1
    print(ans1)
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans1 += q[q_i]
        q_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1


ans2 = 0
p_i = 0
q_i = 0
r_i = 0
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans2 += q[q_i]
        q_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans2 += p[p_i]
        p_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1

ans3 = 0
if X + Y <= C:
    ans3 = sum(r[:(X+Y)])

print(max(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
# 2020/03/28
# AtCoder Beginner Contest 160 - E

# Input
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.append(-1000000000)
q.append(-1000000000)
r.append(-1000000000)

# Init
ans = 0

# Sort
p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()

fullx = x
fully = y

# Calc
pidx = qidx = ridx = 0
while fullx > 0 or fully > 0:

    # Case Painting
    if max(p[pidx], q[qidx]) < r[ridx]:
        ans = ans + r[ridx]
        ridx = ridx + 1
        if fullx <= 0:
            fully = fully - 1
        elif fully <= 0:
            fullx = fullx - 1
        else:
            if p[pidx] > q[qidx]:
                fullx = fullx - 1
            else:
                fully = fully - 1
    # No Painting
    else:
        if fullx <= 0:
            ans = ans + q[qidx]
            qidx = qidx + 1
            fully = fully - 1
        elif fully <= 0:
            ans = ans + p[pidx]
            pidx = pidx + 1
            fullx = fullx - 1
        else:
            if p[pidx] > q[qidx]:
                ans = ans + p[pidx]
                pidx = pidx + 1
                fullx = fullx - 1
            else:
                ans = ans + q[qidx]
                qidx = qidx + 1
                fully = fully - 1
    if pidx >= x:
        pidx = a
    if qidx >= y:
        qidx = b

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)[:X+Y]
  
  j = 0
  sum_list = sorted(aka_list + midori_list)
  for i in range(len(sum_list)):
    if sum_list[i] < mu_list[j]:
      sum_list[i] = mu_list[j]
      if j < C-1: 
        j += 1
  print(sum(sum_list))
  
main()

Submission status: Wrong Answer

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]

x_a.reverse()
x_b.reverse()

s = 0
v = 0
t = 0
while s < x and v < y and t < c:
    if x_a[s] < x_b[v]:
        #print('B')
        if x_a[s] < s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        else:
            break
    elif x_a[s] > x_b[v]:
        #print('A')
        if x_b[v] < s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        else:
            break
    else:
        if x_a[s] < s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        elif x_b[v] < s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        else:
            break
        

ans = sum(x_a) + sum(x_b)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C = map(int, input().split())
p = list(map(lambda x:int(x)*(-1), input().split()))
q = list(map(lambda x:int(x)*(-1), input().split()))
r = list(map(int, input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

tmp = []
for _ in range(X):
    tmp.append(heapq.heappop(p)*(-1))
for _ in range(Y):
    tmp.append(heapq.heappop(q)*(-1))
heapq.heapify(tmp)

ans = 0
for _ in range(X+Y):
    i = heapq.heappop(tmp)
    while True:
        if r:
            j = heapq.heappop(r)
            if j <= i:
                continue
            else:
                ans += j
                break
        else:
            ans += i
            break
print(ans)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = list(map(int,input().split()))
p = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
q = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]
r = sorted(list(map(int,input().split())),key=lambda x:-x) + [0]

pi = 0
qi = 0
ri = 0
res = 0
while pi + qi + ri != X + Y:
  if ( qi == Y or p[pi] >= q[qi] ) and p[pi] >= r[ri]:
    # print("p")
    res += p[pi]
    pi += 1
  elif ( pi == X or q[qi] >= p[pi] ) and q[qi] >= r[ri]:
    # print("q")
    res += q[qi]
    qi += 1
  elif  ( pi == X or r[ri] >= q[qi]) and (qi == Y or r[ri] >= p[pi]):
    #print("r")
    res += r[ri]
    ri += 1
  # print(pi + qi + ri != X + Y)
print(res)

Submission status: Wrong Answer

Solution code:
def solve(x):
    return q[y-x]+r[j+x]-r[j]
(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]
pi=p[:]
qi=q[:]
ri=r[:]
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=p[x]+q[y]
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]
    # 上手いこと緑の美味しさ総和を求める
    # 三分探索？
    # 整数の三分探索はにぶたんに帰着
    ok=0
    ng=k+1
    while ng-ok>1:
        # 無のうちmid個を緑に変換
        mid=(ok+ng)//2
        if solve(mid)-solve(mid-1)>0:ok=mid
        else:ng=mid
    t+=solve(ok)
    if t>m:m=t
print(m)

Submission status: Wrong Answer

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

red_apples = sorted([int(i) for i in input().split()])
green_apples = sorted([int(i) for i in input().split()])
no_apples = sorted([int(i) for i in input().split()])[::-1]
ans = sum(red_apples[::-1][:x]) + sum(green_apples[::-1][:y])

i = 0
j = 0
k = 0
# 赤と緑の小さいやつを無職のりんごの大きいもので置き換えればよさそう
for n in no_apples:
    # print(green_apples[j])
    if red_apples[i] < green_apples[j] and red_apples[i] < n:
        ans -= red_apples[i] + n
        i += 1
        # print('hoge')
    elif green_apples[j] < red_apples[i] and green_apples[j] < n:
        # print('ans', ans)
        ans = ans - green_apples[j] + n
        # print('fuga', j, green_apples[j], n, ans)
        j += 1
    else:
        break
    # print(n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x, y, a, b, c = map(int, input().split())
    al = sorted(list(map(int, input().split())), reverse=True)[:x]
    bl = sorted(list(map(int, input().split())), reverse=True)[:y]
    cl = sorted(list(map(int, input().split())), reverse=True)
    ans = 0
    xi, yi = 0, 0
    for i in cl:
        if al:
            ai = al[-1]
        else:
            ai = 0
        if bl:
            bi = bl[-1]
        else:
            bi = 0
        if ai < bi:
            if al:
                m = al.pop()
            else:
                m = 0
        else:
            if bi:
                m = bl.pop()
            else:
                m = 0
        if m < i:
            ans += i
        else:
            ans += m
            break
    ans += sum(al)+sum(bl)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C):
    if P < A:
        if (r[C-i-1] >= p[P]):
            if (q[Q] >= p[P]):
                P += 1
                R -= 1
        elif Q < B:
            if (r[C-i-1] > q[Q]):
                Q += 1
                R -= 1
            else:
                break
    elif Q < B:
        if (r[C-i-1] > q[Q]):
                Q += 1
                R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p += [0]
q = list(map(int, input().split()))
q += [0]
r = list(map(int, input().split()))
r += [0]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
n, m, l = 0, 0, 0
ans = 0
for i in range(x+y):
    if (p[n] >= r[l] or q[n] >= r[l]) and n < x and m < y:
        if p[n] >= q[m]:
            ans += p[n]
            n += 1
        else:
            ans += q[m]
            m += 1
    elif n == x:
        if q[m] >= r[l]:
            ans += q[m]
            m += 1
        else:
            ans += r[l]
            m += 1
            l += 1
    elif m == y:
        if p[n] >= r[l]:
            ans += p[n]
            n += 1
        else:
            ans += r[l]
            n += 1
            l += 1    
    else:
        if p[n] >= q[m]:
            ans += r[l]
            m += 1
            l += 1
        else:
            ans += r[l]
            n += 1
            l += 1
print(ans)