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

pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
import itertools
pl_ac = [0] + list(itertools.accumulate(pl))
ql_ac = [0] + list(itertools.accumulate(ql))
rl_ac = [0] + list(itertools.accumulate(rl))



import bisect
ans = 0
#　赤色をi個食べるとすると無職x-i
for i in range(x+1):
    tmp = 0
    if i > a or x - i > c or b + c - (x - i) < y:
        continue
    #あか
    tmp += pl_ac[-1] - pl_ac[-1-i]
    # #無職
    # tmp += rl_ac[-1] - ql_ac[-1-(x-i)]
    #残りの無職
    if x-i == 0:
        rl_c = rl[:]
    else:
        rl_c = rl[:-(x-i)]
    # ub以上のりんご何個ある？
    ub = 10 ** 9 + 1

    lb = -1
    while True:
        if ub == lb:
            target = ub
            break
        target = (ub + lb) // 2 + 1
        idx = bisect.bisect_left(ql, target)
        idx2 = bisect.bisect_left(rl_c, target)
        if (b - idx) + (c - (x - i) - idx2) >= y:
            lb = target
        else:
            ub = target - 1
    idx = bisect.bisect_left(ql, target)
    idx2 = bisect.bisect_left(rl_c, target)
    tmp += ql_ac[-1] - ql_ac[idx]
    tmp += rl_ac[-1] - rl_ac[idx2]
    gg = (b - idx) + (c - (x - i) - idx2) - y
    ans -= target * gg
    ans = max(tmp, ans)

print(ans)

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()))
result = 0
Z = 0
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p.append(-1)
q.append(-1)
r.append(-1)

pindex = 0
qindex = 0
rindex = 0
while (X>0 or Y>0) and X+Y-Z>0:
        
    
    if (X>0 or Y>0) and X+Y-Z>0:
        if p[pindex]>=q[qindex] and p[pindex]>=r[rindex] and X > 0:
            result += p[pindex]
            pindex += 1
            X-=1
        elif q[qindex]>=p[pindex] and q[qindex]>=r[rindex] and Y > 0:
            result += q[qindex]
            
            qindex +=1
            Y-=1
        elif r[rindex]>=q[qindex] and r[rindex]>=p[pindex]:
        
            result += r[rindex]
            rindex += 1
            Z+=1

        elif X > 0 and Y <= 0:
            result += p[pindex]
            pindex += 1
            X-=1
        elif Y > 0 and X <=0:
            result += q[qindex]
            
            qindex +=1
            Y-=1
       
print(result)

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())))
S=sorted(P[A-X:]+Q[B-Y:])
i=0
while S[i]<R[-1-i]:
    if len(R)>i or len(S)>i:
        break
    i+=1
if i==0:
    R=[]
print(sum(S[i:])+sum(R[-i:]))

Submission status: Wrong Answer

Solution code:
import heapq

XYABC = list(map(int, input().split()))
p = input().split()
q = input().split()
r = input().split()

mp = list(map(lambda x:int(x)*(-1), p)) #各要素を-1倍
heapq.heapify(mp)
mq = list(map(lambda x:int(x)*(-1), q)) #各要素を-1倍
heapq.heapify(mq)
mr = list(map(lambda x:int(x)*(-1), r)) #各要素を-1倍
heapq.heapify(mr)

#print(heapq.heappop(mp)*(-1))  最大値の取得と表示

red = []
green = []
muji = []

for i in range(XYABC[0]):
    red.append(heapq.heappop(mp)*(-1))
for i in range(XYABC[1]):
    green.append(heapq.heappop(mq)*(-1))
mrange = XYABC[0] + XYABC[1] if (XYABC[0] + XYABC[1]) < len(mr) else len(mr)
for i in range(mrange):
    muji.append(heapq.heappop(mr)*(-1))

sum = 0
rindex = 0
mindex = 0
for i in range(XYABC[0]):
    if ((mindex < mrange) and red[rindex] < muji[mindex]):
        sum += muji[mindex]
        mindex += 1
    else:
        sum += red[rindex]
        rindex += 1

gindex = 0
for i in range(XYABC[1]):
    if ((mindex < mrange) and green[gindex] < muji[mindex]):
        sum += muji[mindex]
        mindex += 1
    else:
        sum += green[gindex]
        gindex += 1

gsum = 0
rindex = 0
mindex = 0
gindex = 0
for i in range(XYABC[1]):
    if ((mindex < mrange) and green[gindex] < muji[mindex]):
        gsum += muji[mindex]
        mindex += 1
    else:
        gsum += green[gindex]
        gindex += 1
for i in range(XYABC[0]):
    if ((mindex < mrange) and red[rindex] < muji[mindex]):
        gsum += muji[mindex]
        mindex += 1
    else:
        gsum += red[rindex]
        rindex += 1

print(sum if sum > gsum else gsum)

Submission status: Wrong Answer

Solution code:
from collections import deque
from copy import deepcopy
x, y, a, b, c = map(int, input().split()) #2つ以上の整数
a_temp = list(map(int, input().split()))
b_temp = list(map(int, input().split()))
c_temp = list(map(int, input().split()))
a_temp.sort()
b_temp.sort()
c_temp.sort()
a_list = deque(a_temp)
b_list = deque(b_temp)
c_list = deque(c_temp)
_a_list = deepcopy(a_list)
_b_list = deepcopy(b_list)
_c_list = deepcopy(c_list)
_x = deepcopy(x)
_y = deepcopy(y)
ans = _ans =  0
for _ in range(x):
    ans += a_list.pop()

for _ in range(y):
    if b_list[-1] > c_list[-1]:
        ans += b_list.pop()
    else:
        ans += c_list.pop()

for _ in range(_x):
    if _a_list[-1] > _c_list[-1]:
        _ans += _a_list.pop()
    else:
        _ans += _c_list.pop()

for _ in range(_y):
    _ans += _b_list.pop()

print(max(ans, _ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-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(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=False)
ans = 0
L = P[:X] + Q[:Y]
L.sort()
idx = 0
for i in range(X+Y):
    if idx >= C:
        break
    if L[i] < R[idx]:
        L[i] = R[idx]
        idx += 1
print(sum(L))

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)
P = P[:X]
Q = Q[:Y]
R.sort()
while R and (P[-1] < R[-1] or Q[-1] < R[-1]):
    if P[-1] < Q[-1]:
        P[-1] = R.pop()
    else:
        Q[-1] = R.pop()
print(sum(P) + sum(Q))

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    X, Y, _, _, _ = [int(x) for x in input().split()]
    pi = deque(sorted([int(x) for x in input().split()], reverse=True))
    qi = deque(sorted([int(x) for x in input().split()], reverse=True))
    ri = deque(sorted([int(x) for x in input().split()], reverse=True))

    p = pi.popleft()
    q = qi.popleft()
    r = ri.popleft()
    pi.append(0)
    qi.append(0)
    ri.append(0)

    count = 0
    apples = X + Y
    for _ in range(apples):
        if X > 0 and p >= r:
            count += p
            p = pi.popleft()
            X -= 1
            continue
        if Y > 0 and q >= r:
            count += q
            q = qi.popleft()
            Y -= 1
            continue
        
        # 無色が赤と緑より大きい
        if X > 0 and p <= q:
            count += r
            r = ri.popleft()
            X -= 1
            continue
        if Y > 0 and q <= p:
            count += r
            r = ri.popleft()
            Y -= 1
            continue

        # 無色が小さいけど、足すしかない
        if X > 0:
            count += r
            r = ri.popleft()
            X -= 1
        elif Y > 0 :
            count += r
            r = ri.popleft()
            Y -= 1

    print(count)
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = [int(i) for i in input().split()]
Pa = sorted([int(i) for i in input().split()])[::-1]
Qb = sorted([int(i) for i in input().split()])[::-1]
Rc = sorted([int(i) for i in input().split()])[::-1]

csP = [0 for _ in range(A)]
csP[0] = Pa[0]
for p in range(1, A):
  csP[p] = csP[p-1] + Pa[p]
csQ = [0 for _ in range(B)]
csQ[0] = Qb[0]
for q in range(1, B):
  csQ[q] = csQ[q-1] + Qb[q]

default = csP[X-1] + csQ[Y-1]

def check(x):
    if x <= default:
      return True
    else:
      total = default
      p0 = X-1
      q0 = Y-1
      x0 = Pa[p0]
      y0 = Qb[q0]
      c0 = 0
      r0 = Rc[c0]
      while r0 > min(x0, y0):
        if x0 > y0 and q0 >=0:
          total += (r0 - y0)
          q0 -= 1
          if q0 < 0:
            y0 = 100001
          else:
            y0 = Qb[q0]
        elif y0 < x0 and p0 >= 0:
          total += (r0 - x0)
          p0 -= 1
          if p0 < 0:
            x0 = 100001
          else:
            x0 = Pa[p0]
        else:
          if p0 > q0:
            total += (r0 - x0)
            p0 -= 1
            if p0 < 0:
              x0 = 100001
            else:
              x0 = Pa[p0]
          else:
            total += (r0 - y0)
            q0 -= 1
            if q0 < 0:
              y0 = 100001
            else:
              y0 = Qb[q0]
                        
        c0 += 1
        if c0 >= C or (r0<0 and q0 < 0):
          break
        r0 = Rc[c0]
        
      
      return x <= total
    

def max_binary_search(check, l=1, r=200000000000001, err=1):
    while r - l > err:  
      mid = (l + r) // 2
      if check(mid):
        l = mid
      else:
        r = mid
    return l
print(max_binary_search(check))

Submission status: Wrong Answer

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

# print(p, q, r)
pp = x - 1
qp = y - 1
rp = 0
while rp < c:
    if r[rp] > p[pp] or r[rp] > q[qp]:
        if p[pp] >= q[qp]:
            q[qp] = r[rp]
            qp -= 1
        else:
            p[pp] = r[rp]
            pp -= 1
    rp += 1

# print(p,q)
print(sum(p[:x]) + sum(q[: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,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 22:06:13 2020

@author: Kanaru Sato
"""

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 = []
Q = []
R = []

for i in range(a):
    P.append([P_[i],1])
for i in range(b):
    Q.append([Q_[i],2])
for i in range(c):
    R.append([R_[i],3])

p = P+R
p.sort(reverse=True, key=lambda x: x[0])
q = Q+R
q.sort(reverse=True, key=lambda x: x[0])
##########
pr = 0
for i in range(x):
    if p[i][1] == 3:
        pr += 1

qr = 0
for i in range(y):
    if q[i][1] == 3:
        qr += 1
        
n = min(pr,qr)

############

prest = p[x:len(p)+1]
qrest = q[y:len(q)+1]
rest = prest+qrest
rest.sort(reverse=True, key=lambda x: x[0])

sum = 0
for i in range(n):
    sum += rest[i][0]

rsum = 0
if pr <= qr:
    for i in range(x):
        if p[i][1] == 3:
            rsum += p[i][0]
else:
    for i in range(y):
        if q[i][1] == 3:
            rsum += q[i][0]

psum = 0
for i in range(x):
    psum += p[i][0]
qsum = 0
for i in range(y):
    qsum += q[i][0]

ans = psum + qsum -rsum + sum

print(ans)

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()))
result = 0
Z = 0
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p.append(-1)
q.append(-1)
r.append(-1)

pindex = 0
qindex = 0
rindex = 0
while (X>0 or Y>0) and X+Y-Z>0:
        
    
    if (X>0 or Y>0) and X+Y-Z>0:
        if p[pindex]>=q[qindex] and p[pindex]>=r[rindex] and X > 0:
            result += p[pindex]
            pindex += 1
            X-=1
        elif q[qindex]>=p[pindex] and q[qindex]>=r[rindex] and Y > 0:
            result += q[qindex]
            
            qindex +=1
            Y-=1
        elif r[rindex]>=q[qindex] and r[rindex]>=p[pindex]:
        
            result += r[rindex]
            rindex += 1
            Z+=1

        elif X > 0:
            result += p[pindex]
            pindex += 1
            X-=1
        elif Y > 0:
            result += q[qindex]
            
            qindex +=1
            Y-=1
       
print(result)

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)

pp=0
pq=0
pr=0
s=0
while x+y > 0:
    if x>0 and y>0 and pr < c:
        if p[pp]>=q[pq]:
            if p[pp]>=r[pr]:
                s+=p[pp]
                pp+=1
                x-=1
            else:
                s+=r[pr]
                pr+=1
                x-=1
        else:
            if q[pq]>=r[pr]:
                s+=q[pq]
                pq+=1
                y-=1
            else:
                s+=r[pr]
                pr+=1
                y-=1
    elif x>0 and y==0 and pr < c:
        if p[pp]>=r[pr]:
            s+=p[pp]
            pp+=1
            x-=1
        else:
            s+=p[pp]
            pp+=1
            x-=1
    elif x==0 and y>0 and pr < c:
        if q[pq]>=r[pr]:
            s+=q[pq]
            pq+=1
            y-=1
        else:
            s+=r[pr]
            pr+=1
            y-=1
    elif x>0 and y==0 and pr == c:
        s+=p[pp]
        pp+=1
        x-=1
    elif x==0 and y>0 and pr == c:
        s+=q[pq]
        pq+=1
        y-=1
        
print(s)

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 j>c:continue
    # 赤の美味しさ総和
    t=p[i]+r[j]
    # 上手いこと緑の美味しさ総和を求める
    # 三分探索？
    # 違うっぽい、もうだめだ
    # 整数の三分探索はにぶたんに帰着
    # 緑をy-t個、無をt個
    solve=lambda t:q[y-t]+r[j+t]-r[j]
    ok1=0
    ng1=k+1
    while ng1-ok1>1:
        # 無のうちmid個を緑に変換
        mid=(ok1+ng1)//2
        if solve(mid)-solve(mid-1)>0:ok1=mid
        else:ng1=mid
    # にぶたんもやってmaxを取る絶対無理
    ok2=0
    ng2=k+1
    while ng2-ok2>1:
        # 無のうちmid個を緑に変換
        mid=(ok2+ng2)//2
        if ri[j+mid]>=qi[y-mid+1]:ok2=mid
        else:ng2=mid
    t+=max(solve(ok1),solve(ok2))
    if t>m:m=t
print(m)

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)[a-x:]
q=sorted(q)[b-y:]
r=sorted(r,reverse=True)
minp_idx=0
minq_idx=0
for i in range(c):
  if minp_idx>=x and minq_idx>=y:
    break
  elif minp_idx>=x:
    if q[minq_idx]<r[i]:
      q[minq_idx]=r[i]
      minq_idx+=1
    else:
      break
  elif minq_idx>=y:
    if p[minp_idx]<r[i]:
      p[minp_idx]=r[i]
      minp_idx+=1
    else:
      break
  elif p[minp_idx]==q[minq_idx]:
    tmp=minp_idx
    tmp2=minq_idx
    smaller=False
    while tmp<x and tmp2<y:
      if p[tmp]<q[tmp2]:
        smaller=minp_idx
        minp_idx+=1
        break
      elif p[tmp]>q[tmp2]:
        smaller=minq_idx
        minq_idx+=1
        break
      else:
        tmp+=1
        tmp2+=1
    if smaller:
      p[smaller]=r[i]
    else:
      if x-minp_idx>y-minq_idx:
        p[minp_idx]=r[i]
        minp_idx+=1
      else:
        q[minq_idx]=r[i]
        minq_idx+=1
  elif p[minp_idx]<q[minq_idx]:
    if p[minp_idx]<r[i]:
      p[minp_idx]=r[i]
      minp_idx+=1
    else:
      break
  elif p[minp_idx]>q[minq_idx]:
    if q[minq_idx]<r[i]:
      q[minq_idx]=r[i]
      minq_idx+=1
    else:
      break
print(sum(p)+sum(q))

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

ri=sorted(r)[::-1]

qi=q[::]
pi=p[::]
pi=sorted(pi)[::-1]
pi=pi[:x]
qi=sorted(qi)[::-1]
qi=qi[:y]

l=pi+qi
l=sorted(l)

for i in range(min(c,x+y)):
    if l[i]>ri[i]:
        break
print(sum(l[i:])+sum(ri[:i]))

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)
red = x-1
gre = y-1
mu = 0
while True:
    if red < 0 or gre < 0 or mu == c:
        break
    else:
        badr = p_[red]
        badg = q_[gre]
        badmu = r_[mu]
        if badr <= badg:
            if badr < badmu:
                red = red-1
                mu = mu+1
            else:
                break
        else:
            if badg < badmu:
                gre = gre-1
                mu = mu+1
            else:
                break
ans = 0
for i in range(red+1):
    ans += p_[i]
for i in range(gre+1):
    ans += q_[i]
for i in range(mu):
    ans += r_[i]
print(ans)

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)
Z = X+Y
P = p[:X]
Q = q[:Y]
R = r[:Z]
ans = 0
if X <= Y:
  S = P + R
  S.sort(reverse=True)
  a = S[:X]
  b = S[X:]
  ans += sum(a)
  T = Q + b
  T.sort(reverse=True)
  c = T[:Y]
  ans += sum(c)
else:
  S = Q + R
  S.sort(reverse=True)
  a = S[:Y]
  b = S[Y:]
  ans += sum(a)
  T = P + b
  T.sort(reverse=True)
  c = T[:X]
  ans += sum(c)
print(ans)
print(a,b)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
al.sort()
bl.sort()
cl.sort()
h = cl[c-1]
result = 0
i = a-1
j = a-x
while i>=j:
  if(al[i]>= h):
    result = result+al[i]
  else:
    result = result+h
    c = c-1
    h = cl[c-1]
  i-=1
k = b-1
l = b-y
while k>=l:
  if(bl[k]>= h):
    result = result+bl[k]
  else:
    result = result +h
    c = c-1
    h = cl[c-1]
  k-=1
print(result)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
re=list(map(int,input().split()))
gr=list(map(int,input().split()))
mu=list(map(int,input().split()))
re.sort(reverse=1)
gr.sort(reverse=1)
mu.sort(reverse=1)
ans=sum(re[:x])
ind=0
for i in range(x):
  v=re[x-1-i]
  if i+1>c:
    break
  w=mu[i]
  if v<w:
    ans+=w-v
  else:
    ind=i+1
    break

ans+=sum(gr[:y])
for i in range(y):
  v=gr[y-1-i]
  if ind+i+1>c:
    break
  w=mu[ind+i]
  if v<=w:
    ans+=w-v
  else:
    ind=i
    break





print(ans)
#print(re,gr,mu,ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
X,Y,A,B,C = map(int,input().split())
P = deque(map(int,input().split()))
Q = deque(map(int,input().split()))
R = deque(map(int,input().split()))
p = sorted(P,reverse=True)
q = sorted(Q,reverse=True)
r = deque(sorted(R,reverse=True))
p1 = deque(p[0:X])
q1 = deque(q[0:Y])
while len(r) > 0:
    if min(p1[X-1],q1[Y-1]) < r[0]:
        if min(p1[X-1],q1[Y-1]) == p1[-1]:
            p1.pop()
            p1.append(r.popleft())
            p1 = deque(sorted(p1))
        else:
            q1.pop()
            q1.append(r.popleft())
            q1 = deque(sorted(q1))
    else:
        break
ans = sum(p1) + sum(q1)
print(ans)

Submission status: Wrong Answer

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

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

for i in range(min(x, y, c)):
    if p[-1-i] > q[-1-i]:
        if q[-1-i] < r[i]:
            q[-1-i] = r[-1-i]
            r.append(r[-1-i])
        else:
            continue
    elif p[-1-i] <= q[-1-i]:
        if p[-1-i] < r[i]:
            p[-1-i] = r[i]
            r.append(r[-1-i])
            
print(sum(p)+sum(q))

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

eat = []

# 食べる
p.sort(reverse=True)
if X > A:
    eat.extend(p)
else:
    eat.extend(p[:X])

q.sort(reverse=True)
if Y > B:
    eat.extend(q)
else:
    eat.extend(q[:Y])
loss = X+Y - len(eat)

# 足りない分を補充する
while loss > 0:
    r.sort(reverse=True)
    eat.append(r.pop(0))    
    loss -= 1

# rの方が大きいものがあれば入れ替える
eat.sort()
for i in range(len(eat)):
    if len(r) != 0 and eat[i] < r[0]:
        eat[i] = r.pop(0)
    else:
        break

print(sum(eat))

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    readline=stdin.readline
    X,Y,A,B,C=map(int,readline().split())
    p=list(map(int,readline().split()))
    q=list(map(int,readline().split()))
    r=list(map(int,readline().split()))

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

    res=sum(p[:X])+sum(q[:Y])
    i=X-1
    j=Y-1
    k=0
    while True:
        if k==C:
            break
        if i!=0 and j!=0:
            if q[j]<=p[i]:
                if q[j]<r[k]:
                    res-=q[j]
                    res+=r[k]
                    j-=1
                    k+=1
                else:
                    break
            else:
                if p[i]<r[k]:
                    res-=p[i]
                    res+=r[k]
                    i-=1
                    k+=1
                else:
                    break
        elif i==0:
            if q[j]<r[k]:
                res-=q[j]
                res+=r[k]
                j-=1
                k+=1
            else:
                break
        elif j==0:
            if p[i]<r[k]:
                res-=p[i]
                res+=r[k]
                i-=1
                k+=1
            else:
                break
        else:
            break

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

ps = sorted(ps)
qs = sorted(qs)
rs = sorted(rs)

score = 0
while True:
    if x == 0 and y == 0:
        break
    if len(rs) == 0:
        # 無色のりんごは残っていない
        if x > 0:
            p = ps[-1]
            ps.pop(-1)
            score += p
            x -= 1
        if y > 0:
            q = qs[-1]
            qs.pop(-1)
            score += q
            y -= 1

    else:
        if x > 0 and y == 0:
            # 緑は残っていない → 赤か無色を食べる
            p = ps[-1]
            r = rs[-1]
            x -= 1
            if r > p:
                rs.pop(-1)
                score += r
            else:
                ps.pop(-1)
                score += p
        elif y > 0 and x == 0:
            # 赤は残っていない → 緑か無色を食べる
            q = qs[-1]
            r = rs[-1]
            y -= 1
            if r > q:
                rs.pop(-1)
                score += r
            else:
                qs.pop(-1)
                score += q
        elif x > 0 and y > 0:
            # 赤も緑も無色もある。どれを食べるか。
            p = ps[-1]
            q = qs[-1]
            r = rs[-1]
            if r >= p and r >= q:
                # 無色を食べたほうが良い。残りの美味しさをなるべく多く残すほうが良い。
                rs.pop(-1)
                score += r
                if p < q:
                    # 赤にして食べる
                    x -= 1
                else:
                    # 緑にして食べる
                    y -= 1
            elif p > r:
                ps.pop(-1)
                score += p
                x -= 1
            elif q > r:
                qs.pop(-1)
                score += q
                y -= 1

print(score)

Submission status: Wrong Answer

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

xx = sorted(xx, reverse=True)[:x]
yy = sorted(yy, reverse=True)[:y]
rr = sorted(rr, reverse=True)[:x+y]

ri = -1
xi = x
yi = y
happy = 0
for i in range(min(x+y, len(rr))):
    if (xx[xi-1] <= yy[yi-1]) and(xx[xi-1] < rr[ri+1]) and (xi > 0):
        xi -= 1
        ri +=1
        continue
    if (yy[yi-1] <= xx[xi-1]) and(yy[yi-1] < rr[ri+1]) and (yi > 0):
        yi -= 1
        ri +=1
        continue
print(sum(xx[:xi]) + sum(yy[:yi]) + sum(rr[:ri+1]))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
r=input().split()
R=[int(a) for a in r]
g=input().split()
G=[int(a) for a in g]
w=input().split()
W=[int(a) for a in w]
R=sorted(R,reverse=True)
G=sorted(G,reverse=True)
W=sorted(W,reverse=True)
answer=0
aka=0
midori=0
for _ in range(X+Y):
    if len(W)==0:
        if aka!=X:
            answer+=R[0]
            aka+=1
            del R[0]
        if midori!=Y:
            answer+=G[0]
            midori+=1
            del G[0]
    else:
        if len(R)==0:
            if len(G)==0:
                pass
            else:
                if midori != Y:
                    midori += 1
                    if G[0] >= W[0]:
                        answer += G[0]
                        del G[0]
                    else:
                        answer += W[0]
                        del W[0]
        else:
            if len(G)==0:
                if aka!=X:
                    aka+=1
                    if R[0]>=W[0]:
                        answer+=R[0]
                        del R[0]
                    else:
                        answer+=W[0]
                        del W[0]
            else:
                if R[0]>=G[0]:
                    if midori!=Y:
                        midori+=1
                        if G[0]>=W[0]:
                            answer+=G[0]
                            del G[0]
                        else:
                            answer+=W[0]
                            del W[0]
                    else:
                        if aka!=X:
                            aka+=1
                            answer+=R[0]
                            del R[0]

                else:
                    if aka!=X:
                        aka+=1
                        if R[0]>=W[0]:
                            answer+=R[0]
                            del R[0]
                        else:
                            answer+=W[0]
                            del W[0]
                    else:
                        if midori!=Y:
                            midori+=1
                            answer+=G[0]
                            del G[0]
print(answer)

Submission status: Wrong Answer

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

A = P[-X:]
G = Q[-Y:]

for r in R:
    if r - min(A[-X], G[-Y]) < 0:
        break

    if A[-X] <= G[-Y]:
        bisect.insort(A, r)
    else:
        bisect.insort(G, r)

# print(A[-X:], G[-Y:])
# print(A[:], G[:])
print(sum(A[-X:]) + sum(G[-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.sort()
q.sort()
r.sort()
if x!=a:
  del p[0:a-x]
if y!=b:
  del q[0:b-y]
for i in range(c):
  if p[0]<q[0] and p[0]<r[-1]:
    p.append(r[-1])
    p.remove(p[0])
    r.remove(r[-1])
  elif q[0]<p[0] and q[0]<r[-1]:
    q.append(r[-1])
    q.remove(q[0])
    r.remove(r[-1])
  else:
    break
print(sum(p)+sum(q))

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = (int(x) for x in 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)
ans = sum(p[:x]) + sum(q[:y])
cnt = 0
cnt_a = 0
cnt_b = 0
for cnt in range(c):
    if (r[cnt] < p[x-cnt_a-1] and r[cnt] < q[y-cnt_b-1]) or (x-cnt_a-1 < 0 and y-cnt_b-1 < 0):
        break
    if p[x-cnt_a-1] < q[y-cnt_b-1] and x-cnt_a-1 > -1:
        ans = (ans-p[x-cnt_a-1]) + r[cnt] 
        cnt_a += 1
        # cnt+=1
    elif p[x-cnt_a-1] > q[y-cnt_b-1] and y-cnt_b-1 > -1:
        ans = (ans-q[y-cnt_b-1]) + r[cnt] 
        cnt_b += 1
        # cnt += 1
    else:
        # determine side
        j = 0
        try:
            while p[x-cnt_a-1-j] == q[y-cnt_b-1-j] and x-cnt_a-1-j > -1 and y-cnt_b-1-j > -1:
                j += 1
            if p[x-cnt_a-1-j] < q[y-cnt_b-1-j] and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 1
        except:
            if x > y and x-cnt_a-1 > -1:
                ans = (ans-p[x-cnt_a-1]) + r[cnt] 
                cnt_a += 1
                # cnt+=1
            elif y-cnt_b-1 > -1:
                ans = (ans-q[y-cnt_b-1]) + r[cnt] 
                cnt_b += 1
                # cnt += 1
    
print(ans)