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())
xx=x
yy=y
p=sorted(list(map(int,input().split())))
q=sorted(list(map(int,input().split())))
r=sorted(list(map(int,input().split())))[::-1]
z=0
rr=r[0]
for i in range(a)[::-1]:
  if p[i]>=rr and x:
    z+=p[i]
    x-=1
for i in range(b)[::-1]:
  if q[i]>=rr and y:
    z+=q[i]
    y-=1
ta=0

rl=0
if x:
  p=p[:a-xx+x]
  p=p[::-1]
  pl=0
  for _ in range(x):
    if rl<c:
      if p[pl]<r[rl]:
        ta+=r[rl]
        rl+=1
      else:
        ta+=p[pl]
        pl+=1
if y:
  q=q[:b-yy+y]
  q=q[::-1]
  ql=0
  for _ in range(y):
    if rl<c:
      if q[ql]<r[rl]:
        ta+=r[rl]
        rl+=1
      else:
        ta+=q[ql]
        ql+=1
tb=0
rl=0
if y:
  ql=0
  for _ in range(y):
    if rl<c:
      if q[ql]<r[rl]:
        tb+=r[rl]
        rl+=1
      else:
        tb+=q[ql]
        ql+=1
if x:
  pl=0
  for _ in range(x):
    if rl<c:
      if p[pl]<r[rl]:
        tb+=r[rl]
        rl+=1
      else:
        tb+=p[pl]
        pl+=1
print(z+max(ta,tb))

Submission status: Wrong Answer

Solution code:
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 300010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
x,y,a,b,c = arrIN()
r = arrIN()
g = arrIN()
cl = arrIN()
hr = [-i for i in r]
hg = [-i for i in g]
hc = [-i for i in cl]
heapify(hr)
heapify(hg)
heapify(hc)
ans = 0
for i in range(x):
    f = 0
    if hr:
        a1 = heappop(hr)
        f+=1
    if hc:
        f+=1
        a2 = heappop(hc)

    if f==2:
        if abs(a1)>=abs(a2):
            ans+=abs(a1)
            heappush(hc,a2)
        else:
            ans+=abs(a2)
            heappush(hr,a1)
    else:
        ans+=abs(a1)

for i in range(y):
    f = 0
    if hg:
        a1 = heappop(hg)
        f+=1
    if hc:
        f+=1
        a2 = heappop(hc)

    if f==2:
        if abs(a1)>=abs(a2):
            ans+=abs(a1)
            heappush(hc,a2)
        else:
            ans+=abs(a2)
            heappush(hg,a1)
    else:
        ans+=abs(a1)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

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 = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(r)


base = p[0:X] + q[0:Y]
heapq.heapify(base)

for i in range(X+Y):
    R = -r[0]
    b = base[0]
    if R > b:
        heapq.heappop(base)
        heapq.heappush(base, R)
    else:
        break

print(sum(base))

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 = 0
red = 0
nc = 0
for _ in range(x):
    if nc >= c:
        ans += p[red]
        red += 1
    elif red >= a:
        ans += r[nc]
        nc += 1
    else:
        if p[red] >= r[nc]:
            ans += p[red]
            red += 1
        else:
            ans += p[nc]
            nc += 1

red = 0
for _ in range(y):
    if nc >= c:
        ans += q[red]
        red += 1
    elif red >= a:
        ans += r[nc]
        nc += 1
    else:
        if q[red] >= r[nc]:
            ans += q[red]
            red += 1
        else:
            ans += r[nc]
            nc += 1
        
print(ans)

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)
q.sort(reverse=True)
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]:
            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:
e_r, e_g, n_r, n_g, n_n = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
none = list(map(int, input().split()))
 
red.sort(reverse=True)
green.sort(reverse=True)
none.sort(reverse=True)

eat_r = red[0:e_r]
eat_g = green[0:e_g]

eat = eat_r + eat_g
eat.sort(reverse=True)

for i in range(len(eat)):
  if len(none) > 0 and eat[i] < none[0]:  
    eat[i] = none.pop(0)

print(sum(eat))

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)
for i in range(x+y):
	p.append(0)
	q.append(0)
	r.append(0)
i=j=k=0
ans=0
while x>0 or y>0:
	if p[i]>=q[j] and p[i]>=r[k] and x>0:
		ans+=p[i]
		x-=1
		i+=1
	elif q[j]>=r[k] and y>0:
		ans+=q[j]
		y-=1
		j+=1
	else:
		if y==0:
			x-=1
			if p[i]>r[k]:
				ans+=p[i]
				i+=1
			else:
				ans+=r[k]
				k+=1
		elif x==0:
			y-=1
			if q[j]>r[k]:
				ans+=q[j]
				j+=1
			else:
				ans+=r[k]
				k+=1
		else:
			if p[i]<=q[j]:
				x-=1
			else:
				y-=1
			ans+=r[k]
			k+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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 = sum(p[-X:]) + sum(q[-Y:])

for i in range(1, C+1):
    if p[0] <= q[0] <= r[-1]:
        ans += r.pop(-1)
        ans -= p.pop(0)
    elif q[0] <= p[0] <= r[-1]:
        ans += r.pop(-1)
        ans -= q.pop(0)
    elif q[0] <= r[-1]:
        ans += r.pop(-1)
        ans -= q.pop(0)
    elif p[0] <= r[-1]:
        ans += r.pop(-1)
        ans -= p.pop(0)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
(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=0
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
        # mid個を適用
        # 緑はy-mid個使用
        # わかんね（笑）
        if r[j+mid]-r[j]>=q[y]-q[y-mid]and ri[mid]>=qi[y-mid+1]:ok=mid
        else:ng=mid
    t+=q[min(b,y-ok)]+r[j+ok]-r[j]
    if t>m:m=t
print(m)

Submission status: Wrong Answer

Solution code:
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict
x,y,a,b,c = inputs()
p = inputs()+[0]*(x+y)
p.sort()
q = inputs()+[0]*(x+y)
q.sort()
r = inputs()+[0]*(x+y)
r.sort()
ans = 0
while 0<x or 0<y:
    red = p[-1]
    green = q[-1]
    if r:
        mu = r[-1]
        flag = 1
    if flag and p[-1]<r[-1] and q[-1]<r[-1]:
        if mu-green<mu-red and 0<x:
            a = r.pop()
            ans+=a
            x-=1
        else:
            if 0<y:
                a = r.pop()
                ans+=a
                y-=1
    elif flag and red<mu and 0<x:
        a = r.pop()
        ans+=a
        x-=1
    elif flag and green<mu and 0<y:
        a = r.pop()
        ans+=a
        y=-1
    else:
        if 0<x:
            a = p.pop()
            ans+=a
            x-=1
        if 0<y:
            b = q.pop()
            ans+=b
            y-=1
    #print(p,q,r,x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
#E

line = [int(x) for x in input().split()]
reds = [int(x) for x in input().split()]
greens = [int(x) for x in input().split()]
colorless = [int(x) for x in input().split()]

reds.sort(reverse = True)
greens.sort(reverse = True)
colorless.sort(reverse = True)

rI = line[0]-1
gI = line[1]-1

for i in range(0, line[4]):
    if rI == -1 and gI == -1:
        break
    elif rI == -1:
        if colorless[i] < greens[gI]:
            break
        else:
            greens[gI] = colorless[i]
            gI = gI - 1
    elif gI == -1:
        if colorless[i] < reds[gI]:
            break
        else:
            reds[rI] = colorless[i]
            rI = rI-1
    else:
        if colorless[i] < reds[rI] and colorless[i] < greens[gI]:
            break
        else:
            if reds[rI] <= greens[gI]:
                reds[rI] = colorless[i]
                rI = rI-1
            else:
                greens[gI] = colorless[i]
                gI = gI - 1

print(sum(reds[:line[0]] ) + sum(greens[:line[1]]))

Submission status: Wrong Answer

Solution code:
x, y, na, nb, nc = map(int, input().split()) 
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

a = a[:x]
b = b[:y]

ai = len(a) - 1
bi = len(b) - 1
for i in c:
    if i > a[ai]:
        a[ai] = i
        bi -= 1
    elif i > b[bi]:
        b[bi] = i
        bi -= 1
    else:
        break
print(sum(a)+sum(b))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X, Y, A, B, C = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    Q = [int(x) for x in input().split()]
    R = [int(x) for x in input().split()]

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

    xcnt = 0
    ycnt = 0
    rcnt = 0
    ans = 0
    for r in R:
        p = float("inf")
        if X - 1 - xcnt >= 0:
            p = P[X - 1 - xcnt]
        q = float("inf")
        if Y - 1 - ycnt >= 0:
            q = Q[Y - 1 - ycnt]
        if p >= r and q >= r:
            break

        if (r - p) > 0 and r - p > r - q:
            xcnt += 1
            rcnt += 1
            ans += r
        elif (r - q) > 0 and r - q > r - p:
            ycnt += 1
            rcnt += 1
            ans += r
    ans += sum(P[:X - xcnt])
    ans += sum(Q[:Y - ycnt])

    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()))
ans = 0

while X > 0 or Y > 0:
  if len(p) != 0:
    Pmax = max(p)
  else:
    Pmax = 0

  if len(q) != 0:
    Qmax = max(q)
  else:
    Qmax = 0

  if len(r) != 0:
    Rmax = max(r)
  else:
    Rmax = 0  

  if Pmax >= Qmax and Pmax >= Rmax :
    if X > 0:
      ans = ans + Pmax
      X = X-1
      p.remove(Pmax)
    else:
      p.remove(Pmax)

  elif Qmax >= Rmax  :
    if Y > 0:
      ans = ans + Qmax
      Y = Y-1
      q.remove(Qmax)
    else:
      q.remove(Qmax)

  else:
    if Pmax >= Qmax:
      if Y > 0:
        ans = ans + Rmax
        Y = Y-1
        r.remove(Rmax)
      else:
        r.remove(Rmax)
    else:
      if X > 0:
        ans = ans + Rmax
        X = X-1
        r.remove(Rmax)
      else:
        r.remove(Rmax)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

X, Y, A, B, C = map(int, input().split())
H = []
for p in map(int, input().split()):
  heappush(H, ((-p, 'r')))
for q in map(int, input().split()):
  heappush(H, ((-q, 'g')))
for r in map(int, input().split()):
  heappush(H, ((-r, '')))

count = X + Y
ans = 0
while count > 0:
  h = heappop(H)
  if h[1] == 'r' and X > 0:
    X -= 1
    count -= 1
    ans -= h[0]
  elif h[1] == 'g' and Y > 0:
    Y -= 1
    count -= 1
    ans -= h[0]
  else:
    count -= 1
    ans -= h[0]

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    x,y,a,b,c = map(int,input().split())
    red = list(map(int,input().split()))
    green = list(map(int,input().split()))
    colorless = list(map(int,input().split()))

    red.sort()
    green.sort()
    colorless.sort()

    total = 0
    while x > 0:
        if (not red) or (not colorless):
            break
        
        if red[-1] >= colorless[-1]:
            total += red.pop()
        else:
            total += colorless.pop()

        x -= 1

    while y > 0:
        if (not green) or (not colorless):
            break
        
        if green[-1] >= colorless[-1]:
            total += green.pop()
        else:
            total += colorless.pop()

        y -= 1

    while x > 0:
        if red:
            total += red.pop()
        else:
            break

        x -= 1

    while y > 0:
        if green:
            total += green.pop()
        else:
            break

        y -= 1

    print(total)

main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop


def main():
    X, Y, A, B, C = map(int, input().split())

    P = []
    Q = []
    R = []
    for v in input().split():
        heappush(P, -int(v))
    for v in input().split():
        heappush(Q, -int(v))
    for v in input().split():
        heappush(R, -int(v))

    score = 0
    cp = 0
    cq = 0
    cr = 0

    XY = X + Y

    while len(P) > 0 and len(Q) > 0 and len(R) > 0 and cp < X and cq < Y and cp + cq + cr < XY:
        p = -P[0]
        q = -Q[0]
        r = -R[0]
        if r > p and r > q:
            score -= heappop(R)
            cr += 1
        elif p > q:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(Q)
            cq += 1

    while len(P) > 0 and len(R) > 0 and cp < X and cp + cq + cr < XY:
        p = -P[0]
        r = -R[0]
        if p >= r:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(R)
            cr += 1

    while len(Q) > 0 and len(R) > 0 and cq < Y and cp + cq + cr < XY:
        q = -Q[0]
        r = -R[0]
        if q >= r:
            score -= heappop(Q)
            cq += 1
        else:
            score -= heappop(R)
            cr += 1

    while cp < X and cp + cq + cr < XY:
        if len(P) > 0:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(R)
            cr += 1

    while cq < Y and cp + cq + cr < XY:
        if len(Q) > 0:
            score -= heappop(Q)
            cq += 1
        else:
            score -= heappop(R)
            cr += 1

    print(score)


main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

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

hp = []
for e in p:
    heappush(hp, [-e, 0])
for e in q:
    heappush(hp, [-e, 1])
for e in r:
    heappush(hp, [-e, 2])

ans = 0
cnt = [0] * 3
sm = 0
mx = [c, x, y]
while hp:
    yum, col = heappop(hp)
    yum = -yum

    if cnt[col] >= mx[col]:
        continue

    ans += yum
    cnt[col] += 1
    sm += 1

    if sm == x + y:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main(): #startline-------------------------------------------
    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()
    xlist = []
    ylist = []
    for i in range(x):
        if len(r) != 0:
            if p[i] > r[-1]:
                xlist.append(p[i])
            else:
                rele = r.pop()
                xlist.append(rele)
        else:
            xlist.append(p[i])
    for i in range(y):
        if len(r) != 0:
            if q[i] > r[-1]:
                ylist.append(q[i])
            else:
                rele = r.pop()
                ylist.append(rele)
        else:
            ylist.append(q[i])
 
    print(sum(xlist)+sum(ylist))
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

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

INF = 1 << 30
p.append(-INF)
q.append(-INF)
r.append(-INF)

ans = 0
pi = 0
qi = 0
ri = 0

def func(c):
  global ans, pi, qi, ri, X, Y
  if c == 0:
    ans += p[pi]
    pi += 1
    X -= 1
  elif c == 1:
    ans += q[qi]
    qi += 1
    Y -= 1
  else:
    ans += r[ri]
    ri += 1
    if c == 2: X -= 1
    else: Y -= 1

while X > 0 or Y > 0:
  if p[pi] >= r[ri] and X > 0: func(0)
  elif q[qi] >= r[ri] and Y > 0: func(1)
  elif min(p[pi], p[pi]*X) >= min(q[qi], q[qi]*Y): func(2)
  else: func(3)

print(ans)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n] and n != min(eatRA,eatGA):
    n += 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C:
    break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
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()))
maze = [['',0] for i in range(a+b+c)]
for i in range(a):
    maze[i] = ["r",p[i]]
for i in range(b):
    maze[a + i] = ["g",q[i]]
for i in range(c):
    maze[a + b + i] = ["n",r[i]]

maze.sort(reverse=True,key = lambda x:x[1])

ans = 0
index = 0
for i in range(x):
    while index < (a+b+c):
        if maze[index][0] == "r" or maze[index][0] == "n":
            ans += maze[index][1]
            index += 1
            break
        index += 1
index = 0
for i in range(y):
    while index < (a+b+c):
        if maze[index][0] == "g" or maze[index][0] == "n":
            ans += maze[index][1]
            index += 1
            break
        index += 1

ans1 = 0
index = 0
for i in range(y):
    while index < (a+b+c):
        if maze[index][0] == "g" or maze[index][0] == "n":
            ans1 += maze[index][1]
            index += 1
            break
        index += 1
index = 0
for i in range(x):
    while index < (a+b+c):
        if maze[index][0] == "r" or maze[index][0] == "n":
            ans1 += maze[index][1]
            index += 1
            break
        index += 1

print(max(ans,ans1))

Submission status: Wrong Answer

Solution code:
(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=0
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
        # mid個を適用
        # 緑はy-mid個使用
        # r[j+mid]-r[j]とq[y]-q[y-mid]を比較(本当に？)
        # if r[j+mid]-r[j]>=q[min(b,y)]-q[min(b,y-mid)]:
            # ok=mid
        # else:
            # ng=mid
        if ri[mid]>=qi[y-mid+1]:ok=mid
        else:ng=mid
    t+=q[min(b,y-ok)]+r[j+ok]-r[j]
    if t>m:m=t
print(m)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
P=sorted([int(x) for x in input().split()])
Q=sorted([int(x) for x in input().split()])
R=[int(x) for x in input().split()]
saare=[]
for item in P:
	saare.append([item,'R'])
for item in Q:
	saare.append([item,'G'])
for item in R:
	saare.append([item,'C'])

saare.sort(reverse=True)
# print(saare)

p=A-X
q=B-Y

i=0

ans=0

while X or Y:

	if saare[i][1]=='R' and X:
		X-=1
		p+=1
		ans+=saare[i][0]
		# print("EAT RED",saare[i][0])
	elif saare[i][1]=='G' and Y:
		Y-=1
		q+=1
		ans+=saare[i][0]
		# print("EAT GREEN",saare[i][0])
	elif saare[i][1]=='C':
		if X and not Y:
			X-=1
			p+=1
			ans+=saare[i][0]
			# print("EAT RED",saare[i][0])
		elif Y and not X:
			Y-=1
			q+=1
			ans+=saare[i][0]
			# print("EAT GREEN",saare[i][0])
		else:
			if P[p] > Q[q]:
				q+=1
				Y-=1
				ans+=saare[i][0]
				# print("EAT GREEN",saare[i][0])
			else:
				p+=1
				X-=1
				ans+=saare[i][0]
				# print("EAT RED",saare[i][0])
	i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl())
y = sorted(inpl())
c = sorted(inpl())
c = c[::-1]

i = X-a; j = Y-b
ind = 0
while i < X and j < Y and ind < Z:
    if x[i] <= y[j]:
        if x[i] < c[ind]:
            x[i] = c[ind]
            ind += 1
            i += 1
        else:
            break
    else:
        if y[j] < c[ind]:
            y[j] = c[ind]
            ind += 1
            j += 1
        else:
            break
print(sum(x[X-a:]) + sum(y[Y-b:]))

Submission status: Wrong Answer

Solution code:
#500
X, Y, A, B, C = map(int,input().split())
p0 = list(map(int,input().split()))
q0 = list(map(int,input().split()))
r0 = list(map(int,input().split()))
p = sorted(p0, reverse = True); p.append(0)
q = sorted(q0, reverse = True); q.append(0)
r = sorted(r0, reverse = True); r.append(0)

happy = 0
i = 0
j = 0
k = 0
red = 0
green = 0
white = 0

for _ in range(X+Y):
    if r[k] >= p[i] and r[k] >= q[j]:
        happy += r[k]
        white += 1
        k += 1
    elif p[i] > q[j]:
        if red != X:
            happy += p[i]
            red += 1
            i += 1
        elif q[j] >= r[k] and green != Y:
            happy += q[j]
            green += 1
            j += 1
    elif p[i] <= q[j]:
        if green != Y:
            happy += q[j]
            green += 1
            j += 1
        elif p[i] >= r[k] and red != X:
            happy += p[i]
            red += 1
            i += 1
            
print(happy)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heapify, heapreplace


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

heapify(P)
heapify(Q)
heapify(R)

while R:
    p, q, r = P[0], Q[0], heappop(R)
    if p < q:
        T, t = P, p
    else:
        T, t = Q, q

    if t < r:
        heapreplace(T, r)

P.sort(reverse=True)
Q.sort(reverse=True)
ans = 0
for i in range(X):
    ans += P[i]
for i in range(Y):
    ans += Q[i]

print(ans)

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()
q.sort()
r.sort(reverse=True)
xlis = deque(p[len(p)-x:])
ylis = deque(q[len(q)-y:])
r = deque(r)
while True:
    if len(r) == 0:
        break
    xs = xlis.popleft()
    ys = ylis.popleft()
    rm = r.popleft()
    if rm < xs and rm < ys:
        xlis.append(xs)
        ylis.append(ys)
        break
    if xs < ys and xs < rm:
        xlis.append(rm)
        ylis.append(ys)
    elif ys < xs and ys < rm:
        ylis.append(rm)
        xlis.append(xs)
    else:
        xlis.append(xs)
        ylis.append(ys)
print(sum(xlis)+sum(ylis))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

x,y,a,b,c = [int(i) for i in readline().split()]
p = [int(i) for i in readline().split()]
q = [int(i) for i in readline().split()]
r = [int(i) for i in readline().split()]

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

from heapq import *

hq = p[:x]+q[:y]
hq.sort(reverse=True)

res = []
rr = r[:]
while hq:
    v = hq.pop()
    while r and r[-1] < v:
        r.pop()
    if r: r.pop()
    else: res.append(v)

#print(res)
print(sum(res) + sum(rr[:x+y-len(res)]))