Problem:


Score : 500 points

Problem Statement

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

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

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

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

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

Constraints

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

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

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

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

Eat the 2-nd red apple.

Eat the 1-st green apple.

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

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

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

Sample Output 3

74



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


Sample output:
12

Submission status: Wrong Answer

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    x,y,a,b,c = map(int, input().split())
    p = [int(i) for i in input().split()]
    q = [int(i) for i in input().split()]
    r = [int(i) for i in input().split()]
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    pd =deque()
    pd.extend(p[0:x])
    qd = deque()
    qd.extend(q[0:y])
    rd = deque()
    rd.extend(r)
    sum = 0
    i = 0
    while i <(x+y):
        if len(pd)>0 and pd[0] > rd[0]:
            sum = sum +pd[0]
            pd.popleft()
            i = i+1
        if len(qd)>0 and qd[0] > rd[0]:
            sum = sum +qd[0]
            qd.popleft()
            i = i+1
        if len(pd)==0 and len(qd)>0 and qd[0] < rd[0]:
            sum = sum +rd[0]
            rd.popleft()
            qd.pop()
            i = i+1
        if len(qd)==0 and len(pd)>0 and pd[0] < rd[0]:
            sum = sum +rd[0]
            rd.popleft()
            pd.pop()
            i = i+1

        if len(pd)>0 and pd[0] < rd[0] and len(qd)>0 and qd[0] < rd[0]:
            absp = rd[0] - pd[len(pd)-1]
            absq = rd[0] - qd[len(qd)-1]
            if absp > absq:
                pd.pop()
            else:
                qd.pop()
            sum = sum +rd[0]
            rd.popleft()
            i = i + 1
        i = i +1
    print(sum)

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:
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] > p[i] and r[k] > q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] >= r[k]:
                countA += 1
                ans += p[i]
                i += 1
            if q[j] >= r[k]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[j:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countA-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])
    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y- (countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])
    return out


if __name__ == '__main__':
    # main()
    print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque
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)
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()

print(ans)

Submission status: Wrong Answer

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

x, y = x-1, y-1
z = 0
red, green = 0, 0
ans = 0
while True:
    finish = True
    if p[x] <= q[y]:
        if z < c and p[x] < r[z]:
            x -= 1
            z += 1
            finish = False
    else:
        if z < c and q[y] < r[z]:
            y -= 1
            z += 1
            finish = False
    if finish:
        break
print(sum(p[:x+1]) + sum(q[:y+1]) + sum(r[:z]))

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:
##E
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)

psum = 0

for i in range(X):
    if p[i] > r[0]:
        psum += p[i]
    else:
        psum += r[0]
        r.pop(0)
        if not r:
            r = [0]
for i in range(Y):
    if q[i] > r[0]:
        psum += q[i]
    else:
        psum += r[0]
        r.pop(0)
        if not r:
            r = [0]
print(psum)

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    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)
    heapq.heappush(r,0)
    ans = 0
    for i in range(x):
        if a==0:
            ans -= heapq.heappop(r)
        elif p[0]<=r[0]:
            ans -= heapq.heappop(p)
            a -= 1
        else:
            ans -= heapq.heappop(r)
    for i in range(y):
        if b==0:
            ans -= heapq.heappop(r)
        elif q[0]<=r[0]:
            ans -= heapq.heappop(q)
            b -= 1
        else:
            ans -= heapq.heappop(r)
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
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())), reverse=True)

pp = p[:x]
qq = q[:y]
for k in r:
    if pp[-1] < qq[-1]:
        if pp[-1] < k:
            pp[-1] = k
        else:
            break
    else:
        if qq[-1] < k:
            qq[-1] = k
        else:
            break
print(sum(pp)+sum(qq))

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

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

for i in range(C):
    if p and q and r:
        if p[-1] <= q[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= p.pop(-1)
        elif q[-1] <= p[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= q.pop(-1)
        elif q[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= q.pop(-1)
        elif p[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= p.pop(-1)
        else:
            break
    elif p and r:
        if p[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= p.pop(-1)
        else:
            break
    elif q and r:
        if q[-1] < r[-1]:
            ans += r.pop(-1)
            ans -= q.pop(-1)
        else:
            break
    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)
l = p[:X] + q[:Y]
l.sort()
print(l)
for i in range(min(C,X+Y)):
    if r[i] > l[i]:
        l[i] = r[i]
print(sum(l))

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)]
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])
r.sort(reverse=True)
p.sort(reverse=True)
q.sort(reverse=True)
maze = p[:x] + q[:y]
ans = sum(maze)
dpc = [0]*(c+1)
dpa = [0]*(a+b+1)
maze.sort()
for i in range(c):
    dpc[i+1] = dpc[i] + r[i] 
for i in range(x+y):
    dpa[i+1] = dpa[i]+maze[i]

for i in range(c):
    ans = max(ans,ans - dpa[i+1] + dpc[i+1])
print(ans)

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]
        else:
          if p0 > q0:
            total += (r0 - x0)
            p0 -= 1
            if p0 < 0:
              break
            x0 = Pa[p0]
          else:
            total += (r0 - y0)
            q0 -= 1
            if q0 < 0:
              break
            y0 = Qb[q0]
                        
        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())
pList = list(map(int, input().split()))
qList = list(map(int, input().split()))
rList = list(map(int, input().split()))
pList.sort(reverse=True)
pList = pList[:x]
qList.sort(reverse=True)
qList = qList[:y]
rList.sort(reverse=True)
for r in rList:
    if pList[-1] > qList[-1] and qList[-1] < r:
        qList[-1] = rList.pop(0)
        qList.sort(reverse=True)
    if pList[-1] < qList[-1] and pList[-1] < r:
        pList[-1] = rList.pop(0)
        pList.sort(reverse=True)
print(sum(pList) + sum(qList))

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)
  
  j = 0
  sum_list = sorted(aka_list + midori_list)
  for i in range(len(sum_list)):
    if sum_list[i] < mu_list[j]:
      sum_list[i] = mu_list[j]
      if j < C-1: 
        j += 1
  print(sum(sum_list))
  
main()

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]

pp = x - 1
qp = y - 1
rp = c - 1
while rp >= 0:
    if r[rp] > p[pp] or r[rp] > q[qp]:
        if p[pp] >= q[qp]:
            q[qp] = r[rp]
            rp -= 1
            qp -= 1
        else:
            p[pp] = r[rp]
            rp -= 1
            qp -= 1
    rp -= 1

print(sum(p[:x]) + sum(q[:y]))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int, raw_input().split())
P = map(int, raw_input().split())
Q = map(int, raw_input().split())
R = map(int, raw_input().split())

Ps = sorted(P, reverse=True)
Qs = sorted(Q, reverse=True)
Rs = sorted(R, reverse=True)

Ps = Ps[:X+Y]
Qs = Qs[:X+Y]

pi,qi,ri = 0,0,0
pc,qc,rc = 0,0,0

PP, QQ = [],[]
for i in range(X+Y):
    if pi >= X and qi >= Y:
        # print "beeak"
        break
    if pi >= X and qi < Y:
        # print qi
        QQ.append(Qs[qi])
        qi += 1
        qc += 1
        continue
    if pi < X and qi >= Y:
        # print pi
        PP.append(Ps[pi])
        pi += 1
        pc += 1
        continue
    # print i, pi, qi

    if Qs[qi] < Ps[pi] and pi < X:
        # print Ps[pi]
        PP.append(Ps[pi])
        pi += 1
        pc += 1
    elif qi < Y:
        # print Qs[qi]
        QQ.append(Qs[qi])
        qi += 1
        qc += 1

# print PP
# print QQ

V = sorted(PP + QQ ,reverse=True)

# print V
r = Rs[0]
ans = -1
for i,v in enumerate(V):
    if v < r:
        a = V[:i]
        b = Rs[:X+Y-i]
        o = X+Y-(len(a)+len(b))
        # print o
        # print V[:i+o]
        # print Rs[:X+Y-i]
        ans = sum(V[:i+o]) + sum(Rs[:X+Y-i])
        break

if ans == -1:
    print sum(V)
else:
    print ans

Submission status: Wrong Answer

Solution code:
import collections
def main():

    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse = True)
    q.sort(reverse = True)
    r.sort(reverse = True)
    countA = 0
    countB = 0
    countC = 0
    ans = 0
    i = 0
    j = 0
    k = 0
    while countA < X and countB < Y and countC < C:
        if r[k] > p[i] and r[k] > q[j]:
            countC += 1
            ans += r[k]
            k += 1
        else:
            if p[i] >= r[k]:
                countA += 1
                ans += p[i]
                i += 1
            if q[j] >= r[k]:
                countB += 1
                ans += q[j]
                j += 1

    if countA == X:
        targ = q[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:Y-countB-countC])
        return ans

    if countB == Y:
        targ = p[i:] + r[k:]
        targ.sort(reverse = True)
        ans += sum(targ[:X-countB-countC])
        return ans

    p = p[i:]
    q = q[j:]
    pp = [0]
    qq = [0]
    print(i, j, k, ans)
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for i in range(len(q)):
        qq.append(qq[-1] + q[i])
    out = ans
    for k in range(countC+1):
        m = X-k
        n = Y- (countC-k)
        if 0<= m < len(pp) and 0<= n < len(qq):
            out = max(out, ans + pp[m] + qq[n])
    return out


if __name__ == '__main__':
    # main()
    print(main())

Submission status: Wrong Answer

Solution code:
import collections

def main():
    x, y, a, b, c = map(int, input().split(" "))
    ps = sorted(list(map(int, input().split(" "))), reverse=True)
    qs = sorted(list(map(int, input().split(" "))), reverse=True)
    rs = sorted(list(map(int, input().split(" "))), reverse=True)

    red_eat = ps[:x]
    blue_eat = qs[:y]

    eats = sorted(red_eat + blue_eat, reverse=True)
    #print(eats)
    eats_dict = collections.Counter(eats)
    #print(eats_dict)
    points = sum(eats)

    for i in range(c):
        r = rs[i]
        if eats[-1] > r:
            break
        else:
            flg = True
            for k in eats_dict:
                if k >= r:
                    flg = False
                else:
                    if flg == False:
                        eats_dict[k] -= 1
                        points += -k + r

    ans = points
    print(ans)


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

def max_binary_search(check, l=1, r=500000000000001, 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())

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 = sorted(ans)
# ans = ans[::-1]
index = 0
# print(ans)
# print(c)
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(ans)
print(sum(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())), reverse=True)

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[i]
        else:
            continue
    elif p[-1-i] <= q[-1-i]:
        if p[-1-i] < r[i]:
            p[-1-i] = r[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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
Z = max(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)

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] and x-cnt_a-1 > -1 and y-cnt_b-1 > -1:
        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)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = list(map(int,input().split()))
p = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = list(map(int,input().split()))
q = sorted(q,reverse=True)
r = list(map(int,input().split()))
r = sorted(r)
c_ori = c
while c >= 1 and x >= 1 and y >= 1 and (p[x-1] < r[c-1] or q[y-1] < r[c-1]):
    if p[x-1] < q[y-1]:
        x = x-1
        c = c-1
    else:
        y = y-1
        c = c-1
sum = 0
if x >= 1:
    for i in range(x):
        sum += p[i]
#print(sum)
if y >= 1:
    for i in range(y):
        sum += q[i]
#print(sum)
if c_ori > c:
    for i in range(c,c_ori):
        sum += r[i]
print(sum)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush
X, Y, A, B, C = map(int, input().split())


def int_(num_str):
    return int(num_str) * -1


plist = list(map(int_, input().split()))
qlist = list(map(int_, input().split()))
rlist = list(map(int_, input().split()))
heapify(plist)
heapify(qlist)
heapify(rlist)
ans = 0
while X > 0 or Y > 0:
    if rlist:
        r = heappop(rlist)
    else:
        r = 100

    if X == 0:
        q = heappop(qlist)
        if q < r:
            ans += q
        else:
            ans += r
            heappush(qlist, q)
        Y -= 1
    elif Y == 0:
        p = heappop(plist)
        if p < r:
            ans += p
        else:
            ans += r
            heappush(plist, p)
        X -= 1
    else:
        p = heappop(plist)
        q = heappop(qlist)
        if p < q:
            heappush(qlist, q)
            if p < r:
                ans += p
                if r != 100:
                    heappush(rlist, r)
            else:
                ans += r
                heappush(plist, p)
            X -= 1
        else:
            heappush(plist, p)
            if q < r:
                ans += q
                if r != 100:
                    heappush(rlist, r)
            else:
                ans += r
                heappush(qlist, q)
            Y -= 1
    # print(ans, X, Y)
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)
i, j, k = 0, 0, 0
s, t = 0, 0
ans = 0
for _ in range(x + y):
    if s < x and t < y:
        if i < a and j < b and k < c:
            if p[i] < r[k] or q[j] < r[k]:
                if p[i] < r[k]:
                    s += 1
                else:
                    t += 1
                ans += r[k]
                k += 1
            elif p[i] >= q[j]:
                ans += p[i]
                s += 1
                i += 1
            else:
                ans += q[j]
                t += 1
                j += 1
        elif i < a:
            if j < b:
                ans += p[i]
                s += 1
                i += 1
            elif k < c:
                if p[i] >= r[k]:
                    s += 1
                    ans += p[i]
                    i += 1
                else:
                    s += 1
                    ans += r[k]
                    k += 1
            else:
                ans += p[i]
                s += 1
                i += 1
        elif j < b:
            if k < c:
                if q[j] >= r[k]:
                    t += 1
                    ans += q[j]
                    j += 1
                else:
                    t += 1
                    ans += r[k]
                    k += 1
            else:
                t += 1
                ans += q[j]
                j += 1
        else:
            s += 1
            ans += r[k]
            k += 1
    elif s < x:
        if i < a and k < c:
            if p[i] < r[k]:
                s += 1
                ans += r[k]
                k += 1
            else:
                s += 1
                ans += p[i]
                i += 1
        elif i < a:
            s += 1
            ans += p[i]
            i += 1
        else:
            s += 1
            ans += r[k]
            k += 1
    elif t < y:
        if j < b and k < c:
            if q[j] < r[k]:
                t += 1
                ans += r[k]
                k += 1
            else:
                t += 1
                ans += q[j]
                j += 1
        elif j < b:
            s += 1
            ans += q[j]
            j += 1
        else:
            s += 1
            ans += r[k]
            k += 1
print(ans)