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:
X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

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

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        break
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        break

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

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

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

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

for _ in range(y):
    if len(r) == 0:
        ans += q.pop()
    else:
        if q[-1] < r[-1]:
            ans += r.pop()
        else:
            ans += q.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
p = [int(i) for i in input().split()]
q = [int(j) for j in input().split()]
r = [int(k) for k in input().split()]

p_1 = p+r
q_1 = q+r
p.sort(reverse = True)
q.sort(reverse = True)
p_1.sort(reverse = True)
q_1.sort(reverse = True)

cou_p = sum(p_1[:x]) + sum(q[:y])
cou_q = sum(p[:x])+sum(q_1[:y])
if cou_p > cou_q:
    print(cou_p)
else:
    print(cou_q)

Submission status: Wrong Answer

Solution code:
import heapq

X, Y, A, B, C = map(int ,input().split(' '))
p = list(map(int ,input().split(' ')))
q = list(map(int ,input().split(' ')))
R = set(map(int ,input().split(' ')))

eat = sorted(p, reverse=True)[:X]
heapq.heapify(eat)
[heapq.heappush(eat, i) for i in sorted(q, reverse=True)[:Y]]

first = min(eat)
for r in R:
  if r > first:
    eat.remove(min(eat))
    eat.append(r)
    first = heapq.heappop(eat)
  
print(sum(eat))

Submission status: Wrong Answer

Solution code:
import bisect

x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]

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

x_list = p[:x]
y_list = q[:y]

while (min(x_list[-1], y_list[-1]) < r[0]):
    if x_list[-1] > y_list[-1]:
        y_list.pop()
        bisect.insort(y_list, r[0])
        r.pop(0)
    else:
        x_list.pop()
        bisect.insort(x_list, r[0])
        r.pop(0)
    if len(r) == 0:
        break

print(sum(x_list) + sum(y_list))

Submission status: Wrong Answer

Solution code:
from collections import deque

x, y, a, b, c = map(int, input().split())
p = [int(_) for _ in input().split()]
q = [int(_) for _ in input().split()]
r = [int(_) for _ in input().split()]

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

x_list = p[:x]
y_list = q[:y]

while (min(x_list[-1], y_list[-1]) < r[0]):
    if x_list[-1] > y_list[-1]:
        y_list.pop()
        y_list.append(r[0])
        r.pop(0)
    else:
        x_list.pop()
        x_list.append(r[0])
        r.pop(0)
    if len(r) == 0:
        break

print(sum(x_list) + sum(y_list))

Submission status: Wrong Answer

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

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

x_list = p[:x]
y_list = q[:y]

while (min(x_list[-1], y_list[-1]) < r[0]):
    if x_list[-1] > y_list[-1]:
        y_list.pop()
        y_list.append(r[0])
        r.pop() 
    else:
        x_list.pop()
        x_list.append(r[0])
        r.pop()
    if len(r) == 0:
        break

print(sum(x_list) + sum(y_list))

Submission status: Wrong Answer

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

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

ans = 0
for i in range(x + y - 1):
    ans += p[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import chain

def readlines(*abc):
    for n in abc:
        yield list(map(int, input().split()))[:n]

def main():
    x, y, a, b, c = map(int, input().split())
    apples = sorted(chain(*readlines(a,b,c)), reverse=True)
    print(sum(apples[:x+y]))


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import chain

def readlines():
    for label in range(3):
        yield [(-int(i), label) for i in input().split()]

def main():
    x, y, a, b, c = map(int, input().split())
    apples = sorted(chain(*readlines()))

    for t, i in apples:
        if x < 1 and y < 1:
            break

        if i == 0 and x > 0:
            x -= 1
            yield t
        elif i == 1 and y > 0:
            y -= 1
            yield t
        elif i == 2:
            if x > 0 and x >= y:
                x -= 1
                yield t
            elif y > 0:
                y -= 1
                yield t



print(-sum(main()))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import heapq
from itertools import chain

def readlines():
    for label in range(3):
        yield [(-int(i), label) for i in input().split()]

def main():
    x, y, a, b, c = map(int, input().split())
    lines = list(chain(*readlines()))
    heapq.heapify(lines)

    while x > 0 or y > 0:
        t, i = heapq.heappop(lines)

        if i == 2:
            if x > 0 and x >= y:
                x -= 1
                yield t
            elif y > 0:
                y -= 1
                yield t
        elif i == 0:
            if x > 0:
                x -= 1
                yield t
        else:
            if y > 0:
                y -= 1
                yield t


print(-sum(main()))

Submission status: Wrong Answer

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

umami = [[0]*2 for i in range(a+b+c)];
um = [0]*(x+y+c);

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];

for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

#p.sort();
#p.reverse();
#q.sort();
#q.reverse();
#r.sort();
#r.reverse();
#for i in range(x) :
#    um[i] = p[i];
#for i in range(y) :
#    um[i+x] = q[i];
#for i in range(c) :
#    um[i+x+y] = r[i];

#um.sort();
#um.reverse();

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr <= 0 :
        j += 1;
    if umami[j][0] == 1 and numg <= 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
        j += 1;

#ans = 0;
#for i in range(x+y) :
#    ans += um[i];

print(ans);

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import heapq
from itertools import chain

def readlines():
    for label in range(3):
        yield [(-int(i), -label) for i in input().split()]

def main():
    x, y, a, b, c = map(int, input().split())
    lines = list(chain(*readlines()))
    heapq.heapify(lines)

    while x > 0 or y > 0:
        t, i = heapq.heappop(lines)

        if i == -2:
            if x > 0 and x > y:
                x -= 1
                yield t
            elif y > 0 and y > x:
                y -= 1
                yield t
        elif i == 0:
            if x > 0:
                x -= 1
                yield t
        else:
            if y > 0:
                y -= 1
                yield t


print(-sum(main()))

Submission status: Wrong Answer

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

umami = [[0]*2 for i in range(a+b+c)];
um = [0]*(x+y+c);

for i in range(a) :
    umami[i][0] = 2;
    umami[i][1] = p[i];

for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 0;
    umami[a+b+i][1] = r[i];

#p.sort();
#p.reverse();
#q.sort();
#q.reverse();
#r.sort();
#r.reverse();
#for i in range(x) :
#    um[i] = p[i];
#for i in range(y) :
#    um[i+x] = q[i];
#for i in range(c) :
#    um[i+x+y] = r[i];

#um.sort();
#um.reverse();

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 2 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 2 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
        j += 1;

#ans = 0;
#for i in range(x+y) :
#    ans += um[i];

print(ans);

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import heapq
from itertools import chain

def readlines():
    for label in range(3):
        yield [(-int(i), label) for i in input().split()]

def main():
    x, y, a, b, c = map(int, input().split())
    lines = list(chain(*readlines()))
    heapq.heapify(lines)

    while x > 0 or y > 0:
        t, i = heapq.heappop(lines)

        if i == 2:
            if x > 0 and x > y:
                x -= 1
                yield t
            elif y > 0 and y > x:
                y -= 1
                yield t
        elif i == 0:
            if x > 0:
                x -= 1
                yield t
        else:
            if y > 0:
                y -= 1
                yield t


print(-sum(main()))

Submission status: Wrong Answer

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

umami = [[0]*2 for i in range(a+b+c)];

for i in range(a) :
    umami[i][0] = 0;
    umami[i][1] = p[i];
for i in range(b) :
    umami[a+i][0] = 1;
    umami[a+i][1] = q[i];
for i in range(c) :
    umami[a+b+i][0] = 2;
    umami[a+b+i][1] = r[i];

umami.sort(key=lambda x:x[1]);
umami.reverse();
i = 0;
j = 0;
numr = x;
numg = y;
ans = 0;

while i < x+y :
    if umami[j][0] == 0 and numr == 0 :
        j += 1;
    if umami[j][0] == 1 and numg == 0 :
        j += 1;
    else :
        if umami[j][0] == 0 :
            numr -= 1;
        if umami[j][0] == 1 :
            numg -= 1;
        ans += umami[j][1];
        i += 1;
        j += 1;

print(ans);

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


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)

    P_sum = sum(P[:X])
    Q_sum = sum(Q[:Y])

    ans = P_sum + Q_sum
    P_cnt = X - 1
    Q_cnt = Y - 1
    for r in R:
        if P_cnt >= 0 and Q_cnt >= 0:
            if Q[Q_cnt] < P[P_cnt] and Q[Q_cnt] < r:
                ans += r - Q[Q_cnt]
                Q_cnt -= 1
            elif P[P_cnt] < Q[Q_cnt] and P[P_cnt] < r:
                ans += r - P[P_cnt]
                P_cnt -= 1
            else:
                break
        elif P_cnt >= 0:
            if P[P_cnt] < r:
                ans += r - P[P_cnt]
                P_cnt -= 1
            else:
                break
        elif Q_cnt >= 0:
            if Q[Q_cnt] < r:
                ans += r - Q[Q_cnt]
                Q_cnt -= 1
            else:
                break
        else:
            break

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np

x, y, r ,b, n = input().split()
score_r = input().split()
score_b = input().split()
score_n = input().split()

score_r = score_r[-int(x):]
score_b = score_b[-int(y):]

scores = score_r + score_b + score_n
scores = [int(score)for score in scores]
scores.sort()

print(np.array(scores[-(int(x)+int(y)):]).sum())

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int,input().split())
r = sorted([i for i in map(int,input().split())],reverse = True)
r = r[0:x]
g = sorted([i for i in map(int,input().split())],reverse = True)
g = g[0:y]
n = sorted([i for i in map(int,input().split())],reverse = True)
n = n[0:x]
#print(r,g,n)
com = sorted(r + g + n,reverse = True)
print(sum(com[0:x + y]))

Submission status: Wrong Answer

Solution code:
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = sorted(list(map(int, input().split())), reverse=True)[:na]
ab_list[na:] = sorted(list(map(int, input().split())), reverse=True)[:nb]
c_list = sorted(list(map(int, input().split())), reverse=True)[:min(na + nb, c)]

ab_list.sort()

c_max = c_list[0]
ab_index = 0
for index in range(len(ab_list)):
    if c_max <= ab_list[index]:
        ab_index = index
        break

if ab_index <= len(c_list):
    ab_list[:ab_index] = sorted(ab_list[:ab_index] + c_list[:ab_index], reverse=True)[:ab_index]
else:
    ab_index = len(c_list)
    ab_list[:ab_index] = sorted(ab_list[:ab_index] + c_list[:ab_index], reverse=True)[:ab_index]
print(sum(ab_list))

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())))
for i in range(min(X,Y)):
  if p[A-X+i] >= q[B-Y+i]:
    if r[-1] > q[B-Y+i]:
      del q[B-Y+i]
      q.insert(B-Y+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > p[A-X+i]:
        del p[A-X+i]
        p.insert(A-X+i,r[-1])
        del r[-1]
        r.insert(0,0)
  else:
    if r[-1] > p[A-X+i]:
      del p[A-X+i]
      p.insert(A-X+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > q[B-Y+i]:
        del q[B-Y+i]
        q.insert(B-Y+i,r[-1])
        del r[-1]
        r.insert(0,0)
if X>Y:
  for j in range(X-Y):
    if p[A-X+Y+j] < r[-1]:
      del p[A-X+Y+j]
      p.insert(A-X+Y+j,r[-1])
      del r[-1]
      r.insert(0,0)
if X<Y:
  for j in range(Y-X):
    if q[B-Y+X+j] < r[-1]:
      del q[B-Y+X+j]
      q.insert(B-Y+X+j,r[-1])
      del r[-1]
      r.insert(0,0)
P=sorted(p)
Q=sorted(q)
sc=0
for k in range(X):
  sc+=P[A-X+k]
for l in range(Y):
  sc+=Q[B-Y+l]
print(sc)

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())))
for i in range(min(X,Y)):
  if p[A-X+i] > q[B-Y+i]:
    if r[-1] >= q[B-Y+i]:
      del q[B-Y+i]
      q.insert(B-Y+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > p[A-X+i]:
        del p[A-X+i]
        p.insert(A-X+i,r[-1])
        del r[-1]
        r.insert(0,0)
  else:
    if r[-1] > p[A-X+i]:
      del p[A-X+i]
      p.insert(A-X+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > q[B-Y+i]:
        del q[B-Y+i]
        q.insert(B-Y+i,r[-1])
        del r[-1]
        r.insert(0,0)
if X>Y:
  for j in range(X-Y):
    if p[A-X+Y+j] < r[-1]:
      del p[A-X+Y+j]
      p.insert(A-X+Y+j,r[-1])
      del r[-1]
      r.insert(0,0)
if X<Y:
  for j in range(Y-X):
    if q[B-Y+X+j] < r[-1]:
      del q[B-Y+X+j]
      q.insert(B-Y+X+j,r[-1])
      del r[-1]
      r.insert(0,0)
P=sorted(p)
Q=sorted(q)
sc=0
for k in range(X):
  sc+=P[A-X+k]
for l in range(Y):
  sc+=Q[B-Y+l]
print(sc)

Submission status: Wrong Answer

Solution code:
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = sorted(list(map(int, input().split())), reverse=True)[:na]
ab_list[na:] = sorted(list(map(int, input().split())), reverse=True)[:nb]
c_list = sorted(list(map(int, input().split())), reverse=True)[:min(na + nb, c)]

ab_list.sort()

c_max = c_list[0]
ab_index = 0
for index in range(len(ab_list)):
    if c_max <= ab_list[index]:
        ab_index = index
        break

ab_list[:ab_index] = sorted(ab_list[:ab_index] + c_list[:ab_index], reverse=True)[:ab_index]

print(sum(ab_list))

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())))
for i in range(min(X,Y)):
  if p[A-X+i] > q[B-Y+i]:
    if r[-1] >= q[B-Y+i]:
      del q[B-Y+i]
      q.insert(B-Y+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > p[A-X+i]:
        del p[A-X+i]
        p.insert(A-X+i,r[-1])
        del r[-1]
        r.insert(0,0)
  if p[A-X+i] < q[B-Y+i]:
    if r[-1] > p[A-X+i]:
      del p[A-X+i]
      p.insert(A-X+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > q[B-Y+i]:
        del q[B-Y+i]
        q.insert(B-Y+i,r[-1])
        del r[-1]
        r.insert(0,0)
if X>Y:
  for j in range(X-Y):
    if p[A-X+Y+j] < r[-1]:
      del p[A-X+Y+j]
      p.insert(A-X+Y+j,r[-1])
      del r[-1]
      r.insert(0,0)
if X<Y:
  for j in range(Y-X):
    if q[B-Y+X+j] < r[-1]:
      del q[B-Y+X+j]
      q.insert(B-Y+X+j,r[-1])
      del r[-1]
      r.insert(0,0)
P=sorted(p)
Q=sorted(q)
sc=0
for k in range(X):
  sc+=P[A-X+k]
for l in range(Y):
  sc+=Q[B-Y+l]
print(sc)

Submission status: Wrong Answer

Solution code:
na, nb, a, b, c = map(int, input().split())
ab_list = [0 for i in range(na + nb)]
ab_list[:na] = sorted(list(map(int, input().split())), reverse=True)[:na]
ab_list[na:] = sorted(list(map(int, input().split())), reverse=True)[:nb]
c_list = sorted(list(map(int, input().split())), reverse=True)[:min(na + nb, c)]

ab_list.sort()

c_max = c_list[-1]
ab_index = 0
for index in range(len(ab_list)):
    if c_max <= ab_list[index]:
        ab_index = index
        break

ab_list[:ab_index] = sorted(ab_list[:ab_index] + c_list[-ab_index:])[:ab_index]

print(sum(ab_list))

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())))
for i in range(min(X,Y)):
  if p[A-X+i] > q[B-Y+i]:
    if r[-1] > q[B-Y+i]:
      del q[B-Y+i]
      q.insert(B-Y+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > p[A-X+i]:
        del p[A-X+i]
        p.insert(A-X+i,r[-1])
        del r[-1]
        r.insert(0,0)
  if p[A-X+i] < q[B-Y+i]:
    if r[-1] > p[A-X+i]:
      del p[A-X+i]
      p.insert(A-X+i,r[-1])
      del r[-1]
      r.insert(0,0)
      if r[-1] > q[B-Y+i]:
        del q[B-Y+i]
        q.insert(B-Y+i,r[-1])
        del r[-1]
        r.insert(0,0)
if X>Y:
  for j in range(X-Y):
    if p[A-X+Y+j] < r[-1]:
      del p[A-X+Y+j]
      p.insert(A-X+Y+j,r[-1])
      del r[-1]
      r.insert(0,0)
if X<Y:
  for j in range(Y-X):
    if q[B-Y+X+j] < r[-1]:
      del q[B-Y+X+j]
      q.insert(B-Y+X+j,r[-1])
      del r[-1]
      r.insert(0,0)
P=sorted(p)
Q=sorted(q)
sc=0
for k in range(X):
  sc+=P[A-X+k]
for l in range(Y):
  sc+=Q[B-Y+l]
print(sc)

Submission status: Wrong Answer

Solution code:
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))
an.sort(reverse=True)
bn.sort(reverse=True)
cn.sort(reverse=True)
count=0
while(True) :
  if x>0 and y>0 :
    if an[0]>=bn[0] and bn[0]>=cn[0] or an[0]>=cn[0] and cn[0]>=bn[0] :
      x-=1
      count+=an[0]
      an.pop(0)
    elif bn[0]>=an[0]and an[0]>=cn[0] or bn[0]>=cn[0] and cn[0]>=an[0] :
      y-=1
      count+=bn[0]
      bn.pop(0)
    elif cn[0]>=an[0]and an[0]>=bn[0] :
      y-=1
      count+=cn[0]
      cn.pop(0)
    elif cn[0]>=bn[0]and bn[0]>=an[0] :
      x-=1
      count+=cn[0]
      cn.pop(0)
  elif x==0 and y>0 :
    if bn[0]>=cn[0] :
      count+=bn[0]
      bn.pop(0)
      y-=1
    else :
      count+=cn[0]
      cn.pop(0)
      y-=1
  elif x>0 and y==0 :
    if an[0]>=cn[0] :
      count+=an[0]
      an.pop(0)
      x-=1
    else :
      count+=cn[0]
      cn.pop(0)
      x-=1
      
  else :
    break
    
print (count)

Submission status: Wrong Answer

Solution code:
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
d=a-x+b-y
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))
an.sort(reverse=True)
bn.sort(reverse=True)
cn.sort(reverse=True)
count=0
while(True) :
  if x>0 and y>0 :
    if an[0]>=bn[0] and bn[0]>=cn[0] or an[0]>=cn[0] and cn[0]>=bn[0] :
      x-=1
      count+=an[0]
      an.pop(0)
    elif bn[0]>=an[0]and an[0]>=cn[0] or bn[0]>=cn[0] and cn[0]>=an[0] :
      y-=1
      count+=bn[0]
      bn.pop(0)
    elif cn[0]>=an[0]and an[0]>=bn[0] :
      y-=1
      count+=cn[0]
      cn.pop(0)
    elif cn[0]>=bn[0]and bn[0]>=an[0] :
      x-=1
      count+=cn[0]
      cn.pop(0)
  elif x==0 and y>0 :
    if bn[0]>=cn[0] :
      count+=bn[0]
      bn.pop(0)
      y-=1
    else :
      count+=cn[0]
      cn.pop(0)
      y-=1
  elif x>0 and y==0 :
    if an[0]>=cn[0] :
      count+=an[0]
      an.pop(0)
      x-=1
    else :
      count+=cn[0]
      cn.pop(0)
      x-=1
      
  else :
    break
    
print (count)

Submission status: Wrong Answer

Solution code:
xyabc=input().split()
x=int(xyabc[0])
y=int(xyabc[1])
a=int(xyabc[2])
b=int(xyabc[3])
c=int(xyabc[4])
list1=input().split()
list2=input().split()
list3=input().split()
d=a-x+b-y
an=[]
bn=[]
cn=[]
for num in list1 :
  an.append(int(num))
for num in list2 :
  bn.append(int(num))
for num in list3 :
  cn.append(int(num))
an.sort(reverse=True)
bn.sort(reverse=True)
cn.sort(reverse=True)
count=0
while(True) :
  print(x)
  print(y)
  if x>0 and y>0 :
    if an[0]>=bn[0] and bn[0]>=cn[0] or an[0]>=cn[0] and cn[0]>=bn[0] :
      x-=1
      count+=an[0]
      an.pop(0)
    elif bn[0]>=an[0]and an[0]>=cn[0] or bn[0]>=cn[0] and cn[0]>=an[0] :
      y-=1
      count+=bn[0]
      bn.pop(0)
    elif cn[0]>=an[0]and an[0]>=bn[0] :
      y-=1
      count+=cn[0]
      cn.pop(0)
    elif cn[0]>=bn[0]and bn[0]>=an[0] :
      x-=1
      count+=cn[0]
      cn.pop(0)
  elif x==0 and y>0 :
    if bn[0]>=cn[0] :
      count+=bn[0]
      bn.pop(0)
      y-=1
    else :
      count+=cn[0]
      cn.pop(0)
      y-=1
  elif x>0 and y==0 :
    if an[0]>=cn[0] :
      count+=an[0]
      an.pop(0)
      x-=1
    else :
      count+=cn[0]
      cn.pop(0)
      x-=1
      
  else :
    break
    
print (count)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input("").split())
X = list(map(int,input("").split()))
Y = list(map(int,input("").split()))
Z = list(map(int,input("").split()))
X.sort(reverse = True)
Y.sort(reverse = True)
Z.sort(reverse = True)
F = []


for i in range(x):
    F.append(X[i])
for i in range(y):
    F.append(Y[i])
F.sort(reverse = True)

for i in range(c):
    if F[-1] < Z[0]:
        F.pop(-1)
        F.append(Z[0])
        Z.pop(0)
sum = 0
for i in range(x+y):
    sum += F[i]

print(sum)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input("").split())
X = list(map(int,input("").split()))
Y = list(map(int,input("").split()))
Z = list(map(int,input("").split()))
sum = 0
for i in range(x):
    sum += max(X)
    X.pop(X.index(max(X)))

for i in range(y):
    sum += max(Y)
    Y.pop(Y.index(max(Y)))

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
lista = list(map(int,input().split()))
X = lista[0] ;Y = lista[1] ;A = lista[2] ;B = lista[3] ;C = lista[4]
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))
 
pa.sort()
pb.sort()
pc.sort()
acnt = 0
bcnt = 0
ccnt = 0
result = 0
 
for i in range(X+Y+1):
    if acnt == X:
        pa[A-1] = -1
    if bcnt == Y:
        pb[B-1] = -1
    if acnt+ccnt+bcnt == X+Y:
        print(result)
        sys.exit()
    if pa[A-1] >= pb[B-1] and pa[A-1] >= pc[C-1]:
        result += pa[A-1]
        A -= 1
        acnt += 1
        if A == 0:
            A = 1
            pa[0] = -1
    if pb[B-1] >= pa[A-1] and pb[B-1] >= pc[C-1]:
        result += pb[B-1]
        B -= 1
        bcnt += 1
        if B == 0:
            B = 1
            pb[0] = -1
    if pc[C-1] >= pb[B-1] and pc[C-1] >= pa[A-1]:
        result += pc[C-1]
        C -= 1
        ccnt += 1
        if C == 0:
            C = 1
            pc[0] = -1

Submission status: Wrong Answer

Solution code:
lista = list(map(int,input().split()))
X = lista[0] ;Y = lista[1] ;A = lista[2] ;B = lista[3] ;C = lista[4]
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))
 
pa.sort()
pb.sort()
pc.sort()
acnt = 0
bcnt = 0
ccnt = 0
result = 0
 
for i in range(X+Y):
    if acnt == X:
        pa[A-1] = -1
    if bcnt == Y:
        pb[B-1] = -1
    if pa[A-1] >= pb[B-1] and pa[A-1] >= pc[C-1]:
        result += pa[A-1]
        A -= 1
        acnt += 1
        if A == -1:
            A = 0
            pa[0] = -1
    if pb[B-1] >= pa[A-1] and pb[B-1] >= pc[C-1]:
        result += pb[B-1]
        B -= 1
        bcnt += 1
        if B == -1:
            B = 0
            pb[0] = -1
    if pc[C-1] >= pb[B-1] and pc[C-1] >= pa[A-1]:
        result += pc[C-1]
        C -= 1
        ccnt += 1
        if C == -1:
            C = 0
            pc[0] = -1
 
 
print(result)

Submission status: Wrong Answer

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    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()))
    i,j,k = 0,0,0
    p.sort(reverse=1)
    q.sort(reverse=1)
    r.sort(reverse=1)
    res = 0
    nokori = X+Y
    while nokori>0 and i<X and j<Y and k<c:
        if p[i] > q[j]:
            if p[i] >= r[k]:
                res += p[i]
                i += 1
            else:
                res += r[k]
                k += 1
        elif p[i] < q[i]:
            if q[j] >= r[k]:
                res += q[j]
                j += 1
            else:
                res += r[k]
                k += 1
        else:
            if p[i] >= r[k]:
                res += p[i]
                i += 1
            else:
                res += r[k]
                k += 1
        nokori -= 1
    if nokori == 0:
        print(res)
    else:
        if i==X:
            l = q[j:] + r[k:]
            l.sort(reverse=1)
            print(res + sum(l[:nokori]))
        elif j==Y:
            l = p[i:] + r[k:]
            l.sort(reverse=1)
            print(res + sum(l[:nokori]))
        else:
            l = p[i:] + q[j:]
            l.sort(reverse=1)
            print(res + sum(l[:nokori]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
lista = list(map(int,input().split()))
X = lista[0] ;Y = lista[1] ;A = lista[2] ;B = lista[3] ;C = lista[4]
pa = list(map(int,input().split()))
pb = list(map(int,input().split()))
pc = list(map(int,input().split()))

pa.sort()
pb.sort()
pc.sort()
acnt = 0
bcnt = 0
ccnt = 0
result = 0

for i in range(X+Y):
    if acnt == X:
        pa[A-1] = -1
    if bcnt == Y:
        pb[B-1] = -1
    if acnt+ccnt+bcnt == X+Y:
        print(result)
        sys.exit()
    if pa[A-1] >= pb[B-1] and pa[A-1] >= pc[C-1]:
        result += pa[A-1]
        A -= 1
        acnt += 1
        if A == -1:
            A = 0
            pa[0] = -1
    if pb[B-1] >= pa[A-1] and pb[B-1] >= pc[C-1]:
        result += pb[B-1]
        B -= 1
        bcnt += 1
        if B == -1:
            B = 0
            pb[0] = -1
    if pc[C-1] >= pb[B-1] and pc[C-1] >= pa[A-1]:
        result += pc[C-1]
        C -= 1
        ccnt += 1
        if C == -1:
            C = 0
            pc[0] = -1


print(result)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

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

pq = p+q
pq.sort(reverse=True)

heapq.heapify(r)
ans = 0
#print(r)

for i in range(x+y) :
    #print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]
    else :
        ans += pq[i]
    #print(pq[i], r)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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

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

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

pq = p+q
pq.sort(reverse=True)

heapq.heapify(r)
ans = 0

for i in range(x+y) :
    #print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]
    else :
        ans += pq[i]
print(ans)