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:
import sys
from io import StringIO
import unittest
import copy

# 検索用タグ、バージョンによる相違点(pypy)

def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    # pypy3(2.4.0)ではlist.copy()が未実装。copy をインポートする必要がある。
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    def_red_cnt = len(def_red)
    def_grren_cnt = len(def_grren)

    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            # 透明のリンゴを緑に着色して、置き換える。
            def_grren[grncnt] = r[i]

            if grncnt is not -def_grren_cnt:
                grncnt - 1

        else:
            # 透明のリンゴを赤に着色して、置き換える。
            def_red[redcnt] = r[i]

            if redcnt is not -def_red_cnt:
                redcnt - 1


    print(sum(def_red) + sum(def_grren))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)
#     def test_自作成_1(self):
#         input = """1 1 1 1 1
# 10
# 20
# 90"""
#         output = """110"""
#         self.assertIO(input, output)
    # このパターンで「list index out of range」が発生。
#     def test_自作成_2(self):
#         input = """1 1 1 1 2
# 10
# 20
# 90 110"""
#         output = """200"""
#         self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import copy

# 検索用タグ、バージョンによる相違点(pypy)

def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    # pypy3(2.4.0)ではlist.copy()が未実装。copy をインポートする必要がある。
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            # 先頭のリンゴに到達していない場合は、添え字を更新
            if not def_grren[0] is def_grren[grncnt]:
                grncnt - 1
            # 透明のリンゴを緑に着色して、置き換える。
            def_grren[grncnt] = r[i]
        else:
            # 先頭のリンゴに到達していない場合は、添え字を更新
            if not def_red[0] is def_red[redcnt]:
                redcnt -= 1
            # 透明のリンゴを赤に着色して、置き換える。
            def_red[redcnt] = r[i]

    print(sum(def_red) + sum(def_grren))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
#     def test_入力例_1(self):
#         input = """1 2 2 2 1
# 2 4
# 5 1
# 3"""
#         output = """12"""
#         self.assertIO(input, output)
#     def test_入力例_2(self):
#         input = """2 2 2 2 2
# 8 6
# 9 1
# 2 1"""
#         output = """25"""
#         self.assertIO(input, output)
#     def test_入力例_3(self):
#         input = """2 2 4 4 4
# 11 12 13 14
# 21 22 23 24
# 1 2 3 4"""
#         output = """74"""
#         self.assertIO(input, output)
#     def test_自作成_1(self):
#         input = """1 1 1 1 1
# 10
# 20
# 90"""
#         output = """110"""
#         self.assertIO(input, output)
    # このパターンで「list index out of range」が発生。
    def test_自作成_2(self):
        input = """1 1 1 1 2
10
20
90 110"""
        output = """200"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import copy
def resolve():
    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(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            def_grren[grncnt] = r[i]
            grncnt -= 1
        else:
            def_red[redcnt] = r[i]
            redcnt -= 1

    print(sum(def_red) + sum(def_grren))





class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()
    # resolve()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 15:06:19 2020

@author: Administrator
"""
def gmax(x,y):
    if x>y:
        return x
    else:
        return y

def getmax(x,y,z):
    t = gmax(x,y)
    t = gmax(t,z)
    return t
    
X,Y,A,B,C = map(int,input().split())
Red= list(map(int,input().split()))
Green = list(map(int,input().split()))
cl = list(map(int,input().split()))
#Red.sort()
#Green.sort()
#cl.sort()
all_list = []
tot = 0
for i in Red:
    all_list.append((i,'R'))
for i in Green:
    all_list.append((i,'G'))
for i in cl:
    all_list.append((i,'C'))
all_list.sort()
#print(all_list)
while(X>0 or Y>0):
    t = all_list.pop()
    if t[1] == 'R':
        if(X):
            X-=1
            tot+=t[0]
    elif t[1] == 'G':
        if(Y):
            Y-=1
            tot+=t[0]
    else:
        if X:
            X-=1
            tot+=t[0]
        if Y:
            Y-=1
            tot+=t[0]
    
print(tot)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 25 15:06:19 2020

@author: Administrator
"""
def gmax(x,y):
    if x>y:
        return x
    else:
        return y

def getmax(x,y,z):
    t = gmax(x,y)
    t = gmax(t,z)
    return t
    
X,Y,A,B,C = map(int,input().split())
Red= list(map(int,input().split()))
Green = list(map(int,input().split()))
cl = list(map(int,input().split()))
#Red.sort()
#Green.sort()
#cl.sort()
all_list = []
tot = 0
for i in Red:
    all_list.append((i,'R'))
for i in Green:
    all_list.append((i,'G'))
for i in cl:
    all_list.append((i,'C'))
all_list.sort()
#print(all_list)
while(X>0 or Y>0):
    t = all_list.pop()
    if t[1] == 'R':
        if(X):
            X-=1
            tot+=t[0]
    elif t[1] == 'G':
        if(Y):
            Y-=1
            tot+=t[0]
    else:
        if X>0:
            X-=1
            tot+=t[0]
        else:
            Y-=1
            tot+=t[0]
    
print(tot)

Submission status: Wrong Answer

Solution code:
from collections import Counter

X,Y,A,B,C=map(int,input().split())
#3logN
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
p_list=p[-X:]
q_list=q[-Y:]
#計算量N
for i in r:
    if i>q_list[0] and q_list[0]<=p_list[0]:
        q_list[0]=i
    elif i>p_list[0] and p_list[0]<q_list[0]:
        p_list[0]=i
print(sum(p_list)+sum(q_list))
#pからX個
#qからY個
#を選んで最大化
#このときrをX,Yに入れ替えても良い
#問題は何個入れ替えるか
#選んだ最大値の中で最小の値を比べ、より小さいほうを入れ替える

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)
p = sorted(p)

p = p[(len(p)-x):]
q = q[(len(q)-y):]
r=r+p
r=r+q
r = sorted(r)
print(sum(r[(len(r)-x-y):]))

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

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

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

pi, qi, ri = X-1, Y-1, 0
for _ in range(C+10):
  if P[pi] < R[ri] and P[pi] <= Q[qi]:
    ans += R[ri] - P[pi]
    pi, ri = pi-1, ri+1
  elif Q[qi] < R[ri] and P[pi] >= Q[qi]:
    ans += R[ri] - Q[qi]
    qi, ri = qi-1, ri+1
  if pi < 0 or qi < 0 or ri >= C:
    break
print(ans)

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

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

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

pi, qi, ri = X-1, Y-1, 0
for _ in range(C):
  if P[pi] < R[ri] and P[pi] <= Q[qi]:
    ans += R[ri] - P[pi]
    pi, ri = pi-1, ri+1
  elif Q[qi] < R[ri] and P[pi] >= Q[qi]:
    ans += R[ri] - Q[qi]
    qi, ri = qi-1, ri+1
  if pi < 0 or qi < 0 or ri >= C:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

x,y,ak,bk,ck = 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()

c = deque(c)
ab = a[:x]+b[:y]
ab.reverse()
j=0
for i in range(x+y):
    if ab[i] > c[-1]:
        break

    while c:
        if c[0] > ab[i]:
            ab[i] = c[0]
            c.popleft()
            break
        else:
            c.popleft()
    
    if not c:
        break
        
ans = sum(ab)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,ak,bk,ck = 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()

ab = a[:x]+b[:y]
ab.reverse()
j=0
for i in range(x+y):
    if ab[i] >= max(c):
        break
    while j <= ck-1:
        if c[j] > ab[i]:
            ab[i] = c[j]
            break
        j+=1

ans = sum(ab)
print(ans)

Submission status: Wrong Answer

Solution code:
#141dの応用
from collections import deque

X,Y,A,B,C = map(int, input().split())
p_list = [int(e) for e in input().split()]
q_list = [int(e) for e in input().split()]
r_list = [int(e) for e in input().split()]

p_list.sort(reverse=True)
q_list.sort(reverse=True)
r_list.sort(reverse=False)

#リストから高い方のみ取り出し
red_apples = p_list[0:min(A,X)]
green_apples = q_list[0:min(B,Y)]

colorless_apples = r_list

#print("R:",red_apples)
#print("G:",green_apples)
#print("*:",colorless_apples)
#print("########################")

#不足分をまず食べておく
if len(red_apples) < X:
    shortage = X - len(red_apples)
    red_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]
if len(green_apples) < Y:
    shortage = Y - len(green_apples)
    green_apples += colorless_apples[0:shortage]
    del colorless_apples[0:shortage]

#print("R:",red_apples)
#print("G:",green_apples)
#print("*:",colorless_apples)
#print("##########################")

eat_apples = red_apples + green_apples
eat_apples.sort(reverse=True)

#print("E:",eat_apples)
#print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")

lowest_apple = eat_apples.pop(-1)

replaced_deque = deque() #左高 右低

#replaced_deque | eat_apples | colorless_apples
#| 1 1 2 5 7 8 12 35 58 98 | 1 3 5 7 9
#3 | 1 2 5 7 8 12 35 58 98 | 3 5 7 9
#3 3 | 2 5 7 8 12 35 58 98 | 5 7 9
#3 3 5 | 5 7 8 12 35 58 98 | 7 9
#3 3 5 | 5 7 8 12 35 58 98 | 7 9
#3 5 7 | 5 7 8 12 35 58 98 | 9
#5 7 9 | 5 7 8 12 35 58 98 |

#リンゴを低い方から、残った無色に入れ替えた方がよければ入れ替えていく。入れ替える際はより低い方を選択する
for i in range(len(colorless_apples)):

    #print("eat_apples    :" ,eat_apples)
    #print("replaced_deque:" ,replaced_deque)
    #print("lowest        :" ,lowest_apple)
    #print("candidate     :" ,colorless_apples[i])
    #print("##########################")

    if colorless_apples[i] > lowest_apple:
        replaced_deque.appendleft(colorless_apples[i])

        if len(eat_apples) > 0:
            if replaced_deque[-1] < eat_apples[-1]:
                lowest_apple = replaced_deque.pop()
            else:
                lowest_apple = eat_apples.pop(-1)
        else:
            lowest_apple = replaced_deque.pop()
    else:
        break

print(sum(eat_apples) + sum(replaced_deque) + lowest_apple)

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

R = 0
G = 0
ans = 0

while R < x or G < y:
    if R < x and len(p) > 0 and len(r) > 0:
        s = p.pop()
        t = r.pop()
        if s >= t:
            ans += s
            r.append(t)
        else:
            ans += t
            p.append(s)
        R += 1
    if R < x and len(p) > 0 and len(r) == 0:
        s = p.pop()
        ans += s
        R += 1
    if R < x and len(p) == 0 and len(r) > 0:
        t = r.pop()
        ans += t
        R += 1
    if G < y and len(q) > 0 and len(r) > 0:
        s = q.pop()
        t = r.pop()
        if s >= t:
            ans += s
            r.append(t)
        else:
            ans += t
            q.append(s)
        G += 1
    if G < y and len(q) > 0 and len(r) == 0:
        s = q.pop()
        ans += s
        G += 1
    if G < y and len(q) == 0 and len(r) > 0:
        t = r.pop()
        ans += t
        G += 1
print(ans)

Submission status: Wrong Answer

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

print(sum(r[:x+y]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

X,Y,A,B,C = inputIL()
p = inputIL()+[0]*X
q = inputIL()+[0]*Y
r = inputIL()

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

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

a = p+q+r

a.sort()

print(sum(a[:X+Y]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while Z < C:
  if min(p[X - 1], q[Y - 1]) < r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
    continue
  break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while Z < C:
  if min(p[X - 1], q[Y - 1], r[Z]) < r[Z]:
    if p[X - 1] < q[Y - 1]:
      X -= 1
      Z += 1
    else:
      Y -= 1
      Z += 1
    continue
  break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while Z < C:
  if p[X - 1] < r[Z]:
    X -= 1
    Z += 1
  elif q[Y - 1] < r[Z]:
    Y -= 1
    Z += 1
  else:
    break
 
print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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()))
 
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
 
Z = 0
while Z < C:
  if p[X - 1] < r[Z]:
    X -= 1
    Z += 1
  elif q[Y - 1] < r[Z]:
    Y -= 1
    Z += 1

print(sum(p[:X]) + sum(q[:Y]) + sum(r[:Z]))

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)

ans=sum(P[:X]+Q[:Y])
r,g,f=X-1,Y-1,0
while r>=0 and g>=0 and f<C and (R[f]>P[r] or R[f]>Q[g]):
    if P[r]<Q[g]:
        ans=ans-P[r]+R[f]
        r-=1
        f+=1
    else:
        ans=ans-Q[g]+R[f]
        g-=1
        f+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for _r in r:
    p.append([_r, True])
    q.append([_r, True])


p = deque(sorted(p, key=lambda x: x[0], reverse=True))
q = deque(sorted(q, key=lambda x: x[0], reverse=True))

r_memo = {}

for _r in r:
    if not _r in r_memo:
        r_memo[_r] = 1
    else:
        r_memo[_r] += 1

sum = 0

while x > 0 or y > 0:
    if x == 0 or (y != 0 and q[0] > p[0]):
        top_num, no_color = q.popleft()
        y -= 1
    elif y == 0 or (x != 0 and q[0] <= p[0]):
        top_num, no_color = p.popleft()
        x -= 1

    if no_color:
        if r_memo[top_num] != 0:
            sum += top_num
            r_memo[top_num] -= 1
        else:
            continue
    else:
        sum += top_num


print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

for _r in r:
    p.append([_r, True])
    q.append([_r, True])


p = deque(sorted(p, key=lambda x: x[0], reverse=True))
q = deque(sorted(q, key=lambda x: x[0], reverse=True))

r_memo = {}

for _r in r:
    if not _r in r_memo:
        r_memo[_r] = 1
    else:
        r_memo[_r] += 1

sum = 0

if x < y:
    while y != 0:
        top_num, no_color = p.popleft()

        if no_color:
            if r_memo[top_num] != 0:
                sum += top_num
                r_memo[top_num] -= 1
            else:
                continue
        else:
            sum += top_num

        y -= 1

    while x != 0:
        top_num, no_color = q.popleft()

        if no_color:
            if r_memo[top_num] != 0:
                sum += top_num
                r_memo[top_num] -= 1
            else:
                continue
        else:
            sum += top_num

        x -= 1
else:
    while x != 0:
        top_num, no_color = q.popleft()

        if no_color:
            if r_memo[top_num] != 0:
                sum += top_num
                r_memo[top_num] -= 1
            else:
                continue
        else:
            sum += top_num

        x -= 1

    while y != 0:
        top_num, no_color = p.popleft()

        if no_color:
            if r_memo[top_num] != 0:
                sum += top_num
                r_memo[top_num] -= 1
            else:
                continue
        else:
            sum += top_num

        y -= 1

print(sum)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y, a, b, c = map(int, input().split())
    pqr = []
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    for i in range(a):
        pqr.append([p[i], 1])
    for i in range(b):
        pqr.append([q[i], 2])
    for i in range(c):
        pqr.append([r[i], 0])
    pqr.sort(reverse=True)

    ans = 0
    c_x = 0
    c_y = 0
    for v, k in pqr:
        if k == 1 and c_x < x:
            ans += v
            c_x += 1
        elif k == 2 and c_y < y:
            ans += v
            c_y += 1
        elif k == 0:
            if c_x < x:
                ans += v
                c_x += 1
            elif c_y < y:
                ans += v
                c_y += 1
        if c_x == x and c_y == y:
            print(ans)
            exit()


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y, a, b, c = map(int, input().split())
    pqr = []
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    for i in range(a):
        pqr.append([p[i], 0])
    for i in range(b):
        pqr.append([q[i], 1])
    for i in range(c):
        pqr.append([r[i], 2])
    pqr.sort(reverse=True)

    ans = 0
    c_x = 0
    c_y = 0
    for v, k in pqr:
        if c_x == x and c_y == y:
            print(ans)
            exit()
        if k == 0 and c_x < x:
            ans += v
            c_x += 1
        elif k == 1 and c_y < y:
            ans += v
            c_y += 1
        elif k == 2:
            if c_x < x:
                ans += v
                c_x += 1
            elif c_y < y:
                ans += v
                c_y += 1


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, y, a, b, c = map(int, input().split())
    pqr = []
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    for i in range(a):
        pqr.append([p[i], 0])
    for i in range(b):
        pqr.append([q[i], 1])
    for i in range(c):
        pqr.append([r[i], 2])
    pqr.sort(reverse=True)

    ans = 0
    c_x = 0
    c_y = 0
    for v, k in pqr:
        if k == 0 and c_x < x:
            ans += v
            c_x += 1
        elif k == 1 and c_y < y:
            ans += v
            c_y += 1
        elif k == 2:
            if c_x < x:
                ans += v
                c_x += 1
            elif c_y < y:
                ans += v
                c_y += 1
        if c_x == x and c_y == y:
            break

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

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


def solve(X: int, Y: int, A: int, B: int, C: int, p: "List[int]", q: "List[int]", r: "List[int]"):

    a=deque(sorted(p)[-X:])
    b=deque(sorted(q)[-Y:])
    c=deque(sorted(r))


    # print("a : {}".format(a))
    # print("b : {}".format(b))
    # print("c : {}".format(c))

    a_min = a.popleft()
    b_min = b.popleft()

    a_temp = a_min
    b_temp = b_min
    ans = 0
    
    while(len(c)>0):
        c_temp = c.pop()
        is_cand_a = (a_min < c_temp) & (a_temp !=0)
        is_cand_b = (b_min < c_temp) & (b_temp !=0)
        
        if is_cand_a & is_cand_b:
            if a_temp < b_temp:
                if len(a)>0:
                    a_temp = a.popleft()
                else:
                    a_temp = 0
            else:
                if len(b)>0:
                    b_temp = b.popleft()
                else:
                    b_temp = 0
        elif is_cand_a:
            if len(a)>0:
                a_temp = a.popleft()
            else:
                a_temp = 0
        elif is_cand_b:
            if len(b)>0:
                b_temp = b.popleft()
            else:
                b_temp = 0
        else:
            break

        if is_cand_a | is_cand_b:
            # print("ans:{} c_temp: {}".format(ans, c_temp))
            ans += c_temp

    ans += sum(a)+sum(b)+a_temp+b_temp
    print(ans)



    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    X, Y, A, B, C = (int(_) for _ in input().split())
    p = sorted([int(_) for _ in input().split()])[::-1]
    q = sorted([int(_) for _ in input().split()])[::-1]
    r = sorted([int(_) for _ in input().split()])[::-1]
    i = j = k = 0
    output = 0
    for _ in range(X):
        if k >= C:
            output += p[i]
            i += 1
        else:
            if p[i] >= r[k]:
                output += p[i]
                i += 1
            else:
                output += r[k]
                k += 1
    for _ in range(Y):
        if k >= C:
            output += q[j]
            j += 1
        else:
            if q[j] >= r[k]:
                output += q[j]
                j += 1
            else:
                output += r[k]
                k += 1
    print(output)
    return

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

all_apples = []
for i in range(max(X,Y)):
  if(i<X):
    all_apples.append([P[-(i+1)],'r'])
  if(i<Y):
    all_apples.append([Q[-(i+1)],'g'])
  if(i<C):
    all_apples.append([R[i],'any'])

all_apples.sort()

ans = 0
for i in range(X+Y):
 ans += all_apples[-(i+1)][0]
print(ans)