Problem:


Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74



Sample input:
1 2 2 2 1
2 4
5 1
3


Sample output:
12

Submission status: Wrong Answer

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

p =sorted(p)[::-1][:x][::-1]
q =sorted(q)[::-1][:y][::-1]
r =sorted(r)[::-1][:x+y]

pp = 0
qq = 0
pf = True
qf = True
for rr in r:
    lll = False
    if pf == True and qf == True:
        if p[pp]<rr and q[qq]<rr:
            lll = True
            if p[pp]<q[qq] and pf == True:
                p[pp] = rr
                pp += 1
                if pp == x:
                    pf = False
            elif qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
    if pf == True and lll == False:
        lll = True
        if p[pp]<rr:
            if pf == True:
               p[pp] = rr
               pp += 1
               if pp == x:
                  pf = False
    if pf == True and lll == False:
        lll = True
        if q[qq]<rr:
            if qf == True:
                q[qq] = rr
                qq +=1
                if qq == y:
                    qf = False
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()))
r.append(0)
p.sort()
q.sort()
r.sort()
ans = 0
for i in range(1,X+1):
    if(p[A-i] > r[-1]):
        ans += p[A-i]
    else:
        ans += r[-1]
        del r[-1]
for i in range(1,Y+1):
    if(q[B-i] > r[-1]):
        ans += q[B-i]
    else:
        ans += r[-1]
        del r[-1]
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 = sorted(p)
q = sorted(q)
r = sorted(r)
P = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C):
    if (r[R-i] > p[P]):
        if (q[Q] > p[P]):
            P += 1
    elif (r[R-i] > q[Q]):
        Q += 1
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R:]))

Submission status: Wrong Answer

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

red.sort()
green.sort()
no.sort()
a -= 1
b -= 1
c -= 1
max_a = int(a)
max_b = int(b)

ans = 0
for i in range(x):
    ans += red[a]
    a -= 1
for i in range(y):
    ans += green[b]
    b -= 1
a += 1
b += 1

for i in range(x+y):
    if c >= 0 and a <= max_a and b <= max_b:
        gr = no[c] - red[a]
        gg = no[c] - green[b]
        if gr > gg:
            if gr > 0:
                ans += no[c]
                ans -= red[a]
                c -= 1
                a += 1
        elif gg > gr:
            if gg > 0:
                ans += no[c]
                ans -= green[b]
                c -= 1
                b += 1
    elif c >= 0 and a <= max_a:
        if no[c] - red[a] > 0:
            ans += no[c]
            ans -= red[a]
            c -= 1
            a += 1
    elif c >= 0 and b <= max_b:
        if no[c] - green[b] > 0:
            ans += no[c]
            ans -= green[b]
            c -= 1
            b += 1
    else:
        break

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)
x=p[:X]
y=q[:Y]
s=sum(x)+sum(y)
sub=0
ite=min(len(x),len(y),len(r))
for i in range(ite):
    if x[-1]>y[-1]:
        t=y.pop(-1)
        if t<r[0]:
            sub=sub+r.pop(0)-t
        else:
            break
    else:
        t=x.pop(-1)
        if t<r[0]:
            sub=sub+r.pop(0)-t
        else:
            break

print(s+sub)

Submission status: Wrong Answer

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

import heapq
ans = 0
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
red = 0
g = 0
p1 = heapq.heappop(p)*(-1)
q1= heapq.heappop(q)*(-1)
r1 = heapq.heappop(r)*(-1)
for i in range(x+y):
    if c<=0:
        if red==x and g<y:
            ans += q1
            if q:
                q1 = heapq.heappop(q)*(-1)
        elif red<x and g==y:
            ans += p1
            if p:
                heapq.heappop(p)*(-1)
        else:
            if p1>q1:
                ans += p1
                if p:
                    p1 = heapq.heappop(p)*(-1)
                red += 1
            else:
                ans += q1
                if q:
                    q1 = heapq.heappop(q)*(-1)
                g += 1
    elif red<x and g<y:
        if max(p1,q1)>=r1:
            if p1 > q1:
                ans += p1
                if p:
                    p1 = heapq.heappop(p)*(-1)
                red += 1
            else:
                ans += q1
                if q:
                    q1 = heapq.heappop(q)*(-1)
                g += 1
        else:
            if p1>q1:
                ans += r1
                if r:
                    r1 = heapq.heappop(r)*(-1)
                g += 1
            else:
                ans += r1
                if r:
                    r1 = heapq.heappop(r)*(-1)
                red += 1
                c -= 1

    elif red==x and g<y:
        if q1>=r1:
            ans += q1
            if q:
                q1 = heapq.heappop(q)*(-1)
            g += 1
        else:
            ans += r1
            if r:
                r1 = heapq.heappop(r)*(-1)
            g+= 1
            c -= 1
    elif red<x and g==y:
        if p1>=r1:
            ans += p1
            if p:
                p1 = heapq.heappop(p)*(-1)
            red += 1
        else:
            ans += r1
            if r:
                r1 = heapq.heappop(r)*(-1)
            red+= 1
            c -= 1
    elif red==x and g==y:
        ans += r1
        if r:
            r1 = heapq.heappop(r)*(-1)
        c-=1
print(ans)

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = [int(i) for i in input().split()]
pa = [int(i) for i in input().split()]
pb = [int(i) for i in input().split()]
pc = [int(i) for i in input().split()]

pa = sorted(pa, reverse=True)
pa = pa[:x]
pb = sorted(pb, reverse=True)
pb = pb[:y]
pc = sorted(pc, reverse=True)

l = pa + pb
l = sorted(l, reverse=True)

for i in range(len(pc)):
  for j in range(len(l)):
    if pc[i] > l[j]:
      l[j] = pc[i]
  if j == len(l)-1:
    break
      
print(sum(l))

Submission status: Wrong Answer

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

p_idx = 0
q_idx = 0
r_idx = 0

p = P[p_idx]
q = Q[q_idx]
r = R[r_idx]


ans = 0
while 0 <= X and 0 <= Y:
    #print("X=", X, "Y=", Y)
    #print("p,q,r", p, q, r)
    #print("ans", ans)
    #print("p,q,r,X,Y,ans", p, q, r, X, Y, ans)

    m = max(p, q, r)

    if m == -1:
        break

    if m == r:
        ans += r
        r_idx += 1

        if r_idx == C:
            r = -1
        else:
            r = R[r_idx]

        lp = p_idx + X - 1
        lq = q_idx + Y - 1

        if lp <= A-1 and lq <= B-1:
            p_l = P[lp]
            q_l = Q[lq]

            if q_l <= p_l:
                Y -= 1
            else:
                X -= 1
        elif B-1 < lq:
            Y -= 1
        else:
            X -= 1

    elif m == p:
        ans += p
        p_idx += 1
        X -= 1

        if p_idx == A or X == 0:
            p = -1
        else:
            p = P[p_idx]
    elif m == q:
        ans += q
        q_idx += 1
        Y -= 1

        if q_idx == B or Y == 0:
            q = -1
        else:
            q = Q[q_idx]

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(x):
    return q[y-x]+r[j+x]-r[j]
(x,y,a,b,c),*t=[map(int,t.split())for t in open(0)]
p,q,r=[[0]+sorted(t)[::-1]for t in t]
pi=p[:]
qi=q[:]
ri=r[:]
for i in range(a):p[i+1]+=p[i]
for i in range(b):q[i+1]+=q[i]
for i in range(c):r[i+1]+=r[i]
m=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
        if solve(mid)-solve(mid-1)>0:ok=mid
        else:ng=mid
    t+=solve(ok)
    if t>m:m=t
print(m)

Submission status: Wrong Answer

Solution code:
def no_of_red(A,C,X):
    x=0
    s=0
    while(x<X):
        if(len(C)>0):
            if(A[0]>C[0]):
                s+=A[0]
                A.pop(0)
            else:
                s+=C[0]
                C.pop(0)
        else:
            s+=A[0]
            A.pop(0)
        x+=1
    return s

def reverse(l):
    return l[::-1]

def no_of_green(B,C,Y):
    y=0
    s=0
    while(y<Y):
        if(len(C)>0):
            if(B[0]>C[0]):
                s+=B[0]
                B.pop(0)
            else:
                s+=C[0]
                C.pop(0)
        else:
            s+=B[0]
            B.pop(0)
        y+=1
    return s

X,Y,A,B,C=raw_input().split(' ')
X=int(X)
Y=int(Y)
A=int(A)
B=int(B)
B=int(B)
p=list(raw_input().split(' '))
p=[int(P) for P in p]
q=list(raw_input().split(' '))
q=[int(P) for P in q]
r=list(raw_input().split(' '))
r=[int(P) for P in r]
p.sort()
p=reverse(p)
q.sort()
q=reverse(q)
r.sort()
r=reverse(r)
print(no_of_green(q,r,Y)+no_of_red(p,r,X))

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=0
app=[[] for _ in range(a+b+c)]
for i in range(a+b+c):
  if i<a:
    app[i]=[re[i],0]
  elif a<=i<a+b:
    app[i]=[gr[i-a],1]
  else:
    app[i]=[mu[i-a-b],2]
app.sort(reverse=1)
aka=0
mid=0
i=0
#print(app)
for i in range(a+b+c):
  c=app[i][1]
  if c==1:
    continue
  elif c==0:
    aka+=1
    ans+=app[i][0]
    app[i][0]=0
  else:
    aka+=1
    ans+=app[i][0]
    app[i][0]=0
  if aka==x:
    break


app.sort(reverse=1)
#print(app)
for i in range(a+b+c):
  c=app[i][1]
  if c==0:
    continue
  elif c==1:
    mid+=1
    ans+=app[i][0]
    app[i][0]=0
  else:
    mid+=1
    ans+=app[i][0]
    app[i][0]=0
  if mid==y:
    break




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

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

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import heapq
import sys
from itertools import accumulate
from collections import defaultdict

input = sys.stdin.readline

def main():
    X, Y, A, B, C = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    ans = 0
    P_d = defaultdict(int)
    Q_d = defaultdict(int)
    R_d = defaultdict(int)

    for i in range(len(P)):
        P[i] = -P[i]
        P_d[P[i]] += 1
        
    for i in range(len(Q)):
        Q[i] = -Q[i]
        Q_d[Q[i]] += 1

    
    for i in range(len(R)):
        R[i] = -R[i]
        R_d[R[i]] += 1

    H = P + Q + R
    heapq.heapify(H)
    red = 0
    green = 0
    nocl = 0
    ans = 0
    for i in range(A + B + C):
        tmp = heapq.heappop(H)
        if red + green + nocl == X + Y:
            print(-ans)
            exit()

        if P_d[tmp] >= 1 and red < X:
            P_d[tmp] -= 1
            red += 1
            ans += tmp
        elif Q_d[tmp] >= 1 and green < Y:
            Q_d[tmp] -= 1
            green += 1
            ans += tmp
        elif R_d[tmp] >= 1:
            nocl += 1
            ans += tmp
    





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()))
p.sort()
q=list(map(int, input().split()))
q.sort()
r=list(map(int, input().split()))
r.sort(reverse=True)

i=-X
j=-Y
k=0
deru=0
while deru==0 and k<C and (r[k]>p[i] or r[k]>q[j]):
  if p[i]>q[j] and j<0:
    j+=1
    k+=1
  elif p[i]>q[j] and j>=0 and i<0:
    i+=1
    k+=1
  elif p[i]<q[j] and i<0:
    i+=1
    k+=1
  elif p[i]<q[j] and i>=0 and j<0:
    j+=1
    k+=1
  else:
    deru=1
    
if i==0:
  a=0
else:
  a=sum(p[i:])
  
if j==0:
  b=0
else:
  b=sum(q[j:])
  
if k==0:
  c=0
else:
  c=sum(r[:k])
  
print(a+b+c)

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)[-X:]
q_ = sorted(q)[-Y:]
r_ = sorted(r)

cnt = 0
while len(r_)>0 and len(p_) > cnt:
    if p_[cnt] < r_[-1]:
        p_[cnt] = r_.pop(-1)
        cnt += 1
    else:
        break
cnt = 0
while len(r_)>0 and len(q_) > cnt:
    if q_[cnt] < r_[-1]:
        q_[cnt] = r_.pop(-1)
        cnt += 1
    else:
        break

red = sum(p_)
green = sum(q_)
print(red+green)

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:
          total += (r0 - y0)
          q0 -= 1
          if q0 < 0:
            break
          y0 = Qb[q0]
        elif y0 <= x0:
          total += (r0 - x0)
          p0 -= 1
          if p0 < 0:
            break
          x0 = Pa[p0]
            
        c0 += 1
        if c0 >= C:
          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=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)

tot=sum(p[:X])+sum(q[:Y])

a=0
b=0
f=False
for i in r:
    if f==True:
        break
    elif a==p and b==q:
        break
    elif a==p:
        if i>q[Y-b-1]:
            tot+=i-q[Y-b-1]
            b+=1
        else:
            f=True
    elif b==q:
        if i>p[X-a-1]:
            tot+=i-p[X-a-1]
            a+=1
        else:
            f=True
    else:
        if i>p[X-a-1] and i>q[Y-b-1]:
            if p[X-a-1]<q[Y-b-1]:
                tot+=i-p[X-a-1]
                a+=1
            else:
                tot+=i-q[Y-b-1]
                b+=1
        elif i>p[X-a-1]:
            tot+=i-p[X-a-1]
            a+=1
        elif i>q[Y-b-1]:
            tot+=i-q[Y-b-1]
            b+=1
        else:
            f=True

print(tot)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = [-1] + sorted(list(map(int, input().split())))
Q = [-1] + sorted(list(map(int, input().split())))
R = [-1] + sorted(list(map(int, input().split())))

ans = 0
N = X+Y
while N > 0:
  max_V = max(P[-1], Q[-1], R[-1])
  if P[-1] == max_V:
    P.pop(-1)
    if X < 1:
      continue
    X -= 1
  elif Q[-1] == max_V:
    Q.pop(-1)
    if Y < 1:
      continue
    Y -= 1
  else:
    R.pop(-1)
  ans += max_V
  N = X+Y
  
print(ans)

Submission status: Wrong Answer

Solution code:
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict
import bisect
x,y,a,b,c = inputs()
p = inputs()
p.sort()
p = p[::-1]
p = p[:x]
p = p[::-1]
q = inputs()
q.sort()
q = q[::-1]
q=q[:y]
q = q[::-1]
r = inputs()
r.sort()
r = r[::-1]
ans = 0
for i in r:
    if i<p[0] and i<q[0]:
        break
    red = bisect.bisect_left(p,i)
    green = bisect.bisect_left(q,i)
   # print(p[red],q[green])
    if q[green-1]<p[red-1]:
        q[green-1]=i
    else:
        p[red-1]=i
    #print(p,q)
print(sum(p)+sum(q))

Submission status: Wrong Answer

Solution code:
import math
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
i=0
j=0
k=0
# red=0
# green=0
while i<len(p) and j<len(q) and k<len(r) and x>0 and y>0:
	if p[i]>=q[j]:
		if p[i]>=r[k]:
			if x>0:
				x-=1
				ans+=p[i]
				i+=1
			else:
				if y<=0:
					break
				if q[j]>=r[k]:
					ans+=q[j]
					j+=1
					y-=1
				else:
					ans+=r[k]
					k+=1
					y-=1
		else:
			if x>0:
				x-=1
				ans+=r[k]
				k+=1
			else:
				if y<=0:
					break
				if q[j]>=r[k]:
					ans+=q[j]
					j+=1
					y-=1
				else:
					ans+=r[k]
					k+=1
					y-=1
	else:
		if q[j]>=r[k]:
			if y>0:
				ans+=q[j]
				j+=1
				y-=1
			else:
				if x<=0:
					break
				if p[i]>=r[k]:
					ans+=q[i]
					i+=1
					x-=1
				else:
					ans+=r[k]
					k+=1
					x-=1
		else:
			if y>0:
				y-=1
				ans+=r[k]
				k+=1
			else:
				if x<=0:
					break
				if p[i]>=r[k]:
					ans+=p[i]
					i+=1
					x-=1
				else:
					ans+=r[k]
					k+=1
					x-=1
while i<len(p) and k<len(r) and x>0:
	if p[i]>=r[k]:
			if x>0:
				x-=1
				ans+=p[i]
				i+=1
			else:
				break
	else:
		if x>0:
			x-=1
			ans+=r[k]
			k+=1
		else:
			break
while j<len(q) and k<len(r) and y>0:
	if q[j]>=r[k]:
			if y>0:
				y-=1
				ans+=q[j]
				j+=1
			else:
				break
	else:
		if y>0:
			y-=1
			ans+=r[k]
			k+=1
		else:
			break

while i<len(p) and x>0:
	ans+=p[i]
	i+=1
	x-=1
while j<len(q) and y>0:
	ans+=q[j]
	j+=1
	y-=1
print(ans)

Submission status: Wrong Answer

Solution code:
l=list(map(int,input().split()))
r=list(map(int,input().split()))
g=list(map(int,input().split()))
c=list(map(int,input().split()))
r=r+c
g=g+c
r.sort()
g.sort()
r=r[::-1]
g=g[::-1]
tot=0
for i in range(l[1]):
	tot=tot+g[i]
for i in range(l[0]):
	tot=tot+r[i]
print(tot)

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()
P = P[:X]
Q = Q[:Y]
S = []
#print(P,Q,S)
for _ in range(X+Y):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000000
    elif len(Q) == 0:
        q = 1000000000000000
    else:
        p = P[-1]
        q = Q[-1]
    #print(p,q)
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
    #print(P,Q,S)
ans = 0
for i in P:
    ans += i
for i in Q:
    ans += i
for i in S:
    ans += i
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())))
q = sorted(list(map(int,input().split())))
r = sorted(list(map(int,input().split())))
pp=p[a-x:a]
qq=q[b-y:b]
heapq.heapify(pp)
heapq.heapify(qq)
for i in range(c):
     s=heapq.heappop(pp)
     t=heapq.heappop(qq)
     if r[-i] > s or r[-i] > t:
          if s >= t:
               heapq.heappush(pp, s)
               heapq.heappush(qq, r[-1])
          else:
               heapq.heappush(qq, t)
               heapq.heappush(pp, r[-1])
     else:
          heapq.heappush(pp, s)
          heapq.heappush(qq, t)
          break
print(sum(pp)+sum(qq))

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

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

dp = [0] * X
p_idx = 0
q_idx = 0
r_idx = 0

# print(dp)
for i in range(X):
    if r_idx < len(r) and r[r_idx] > p[p_idx]:
        dp[i] = r[r_idx]
        r_idx += 1
    else:
        dp[i] = p[p_idx]
        p_idx += 1
# print(dp)
red = sum(dp)

dp2 = [0] * Y
for i in range(Y):
    if r_idx < len(r) and r[r_idx] > q[q_idx]:
        dp2[i] = r[r_idx]
        r_idx += 1
    else:
        dp2[i] = q[q_idx]
        q_idx += 1

# print(dp2)
green = sum(dp2)
print(red + green)

Submission status: Wrong Answer

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

p_idx = 0
q_idx = 0
r_idx = 0

p = P[p_idx]
q = Q[q_idx]
r = R[r_idx]


ans = 0
for _ in range(X+Y+1):
    #print("X=", X, "Y=", Y)
    #print("p,q,r", p, q, r)
    #print("ans", ans)
    #print("p,q,r,X,Y,ans", p, q, r, X, Y, ans)

    m = max(p, q, r)

    if m == -1:
        break

    if m == r:
        ans += r
        r_idx += 1

        if r_idx == C:
            r = -1
        else:
            r = R[r_idx]

        lp = p_idx + X - 1
        lq = q_idx + Y - 1

        if lp <= A-1 and lq <= B-1:
            p_l = P[lp]
            q_l = Q[lq]

            if q_l <= p_l:
                Y -= 1
            else:
                X -= 1
        elif A-1 < lp:
            Y -= 1
        else:
            X -= 1

    elif m == p:
        ans += p
        p_idx += 1
        X -= 1

        if p_idx == A or X == 0:
            p = -1
        else:
            p = P[p_idx]
    elif m == q:
        ans += q
        q_idx += 1
        Y -= 1

        if q_idx == B or Y == 0:
            q = -1
        else:
            q = Q[q_idx]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
X, Y, A, B, C = [int(str) for str in input().strip().split()]
ps = [int(str) for str in input().strip().split()]
qs = [int(str) for str in input().strip().split()]
rs = [int(str) for str in input().strip().split()]

def sums(li):
    ret = [0]
    for i in range(len(li)):
        ret.append(ret[-1] + li[i])
    return ret

def f(n):
    if n == 0:
        return red_and_green_sums[-1]
    if n > X + Y:
        return r_sums[n]
    return red_and_green_sums[X + Y - n] + r_sums[n]

ps.sort(reverse=True)
qs.sort(reverse=True)
rs.sort(reverse=True)

r_sums = sums(rs)

red_and_green = ps[:X] + qs[:Y]
red_and_green.sort(reverse=True)
red_and_green_sums = sums(red_and_green)

# print([f(i) for i in range(C)])
print(max([f(i) for i in range(C + 1)]))

Submission status: Wrong Answer

Solution code:
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list ,reverse=True)
  for i in range(len(sum_list)):
    if sum_list[i] < mu_list[0]:
      sum_list[i] = mu_list[0]
      mu_list = mu_list[1:]
  print(sum(sum_list))
  
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(reverse=True)
Q.sort(reverse=True)
R.sort()
P = P[:X]
Q = Q[:Y]
S = []
print(P,Q,S)
for _ in range(X+Y):
    if len(R) == 0:
        break
    s = R[-1]
    if len(P) == 0:
        p = 1000000000000000
    elif len(Q) == 0:
        q = 1000000000000000
    else:
        p = P[-1]
        q = Q[-1]
    #print(p,q)
    if p >= q:
        if q < s:
            del Q[-1]
            del R[-1]
            S.append(s)
        else:
            break
    else:
        if p < s:
            del P[-1]
            del R[-1]
            S.append(s)
        else:
            break
    print(P,Q,S)
ans = 0
for i in P:
    ans += i
for i in Q:
    ans += i
for i in S:
    ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

heap_x = []
heap_y = []

X, Y, A, B, C = map(int, input().split())
P = list(map(lambda x: int(x)*(-1), input().split()))
Q = list(map(lambda x: int(x)*(-1), input().split()))
R = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)

for i in range(X+Y):
    if len(heap_x) == X:
        if Q[0] <= R[0]:
            heapq.heappush(heap_y, heapq.heappop(Q))
            heapq.heappush(Q, 0)
        else:
            heapq.heappush(heap_y, heapq.heappop(R))
            heapq.heappush(R, 0)
    elif len(heap_y) == Y:
        if P[0] <= R[0]:
            heapq.heappush(heap_x, heapq.heappop(P))
            heapq.heappush(P, 0)
        else:
            heapq.heappush(heap_x, heapq.heappop(R))
            heapq.heappush(R, 0)
    else:
        if P[0] <= Q[0]:
            if P[0] <= R[0]:
                heapq.heappush(heap_x, heapq.heappop(P))
                heapq.heappush(P, 0)
            else:
                heapq.heappush(heap_x, heapq.heappop(R))
                heapq.heappush(R, 0)
        else:
            if Q[0] <= R[0]:
                heapq.heappush(heap_y, heapq.heappop(Q))
                heapq.heappush(Q, 0)
            else:
                heapq.heappush(heap_y, heapq.heappop(R))
                heapq.heappush(R, 0)

print(-(sum(heap_x)+sum(heap_y)))

Submission status: Wrong Answer

Solution code:
x,y,A,B,C = map(int,input().split())

a = list(map(int,input().split()))

b = list(map(int,input().split()))

c = list(map(int,input().split()))

a = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]

a = a[:x]
b = b[:y]
ans = a+b
ans = ans[::-1]
index = 0

for i in range(0,C):
    if(c[i] > ans[index]):
        ans[index] = c[i]
        index = index + 1
    else:
        break

    # if(index == x+y):
    #     break
print(sum(ans))

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()
f = [1]*c
rr = [[r[i],i,0] for i in range(a)]+[[cl[i],i,1] for i in range(c)]
rr.sort(key = lambda x:x[0],reverse=True)
ans = 0
for i in range(x):
    ans+=rr[i][0]
    if rr[i][2]==1:
        f[rr[i][1]] = 0
gg = [[g[i],i,0] for i in range(b)]+[[cl[i],i,1] for i in range(c) if f[i]]
gg.sort(key = lambda x:x[0],reverse=True)
for i in range(y):
    ans+=gg[i][0]

f = [1]*c

gg1 = [[g[i],i,0] for i in range(b)]+[[cl[i],i,1] for i in range(c)]
gg1.sort(key = lambda x:x[0],reverse=True)
ans1 = 0
for i in range(y):
    ans1+=gg1[i][0]
    if gg1[i][2]==1:
        f[gg1[i][1]] = 0

rr1 = [[r[i],i,0] for i in range(a)]+[[cl[i],i,1] for i in range(c) if f[i]]
rr1.sort(key = lambda x:x[0],reverse=True)
for i in range(x):
    ans1+=rr1[i][0]

print(max(ans,ans1))