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:
input_1st = input()
input_2nd = input()
input_3rd = input()
input_4th = input()

split_input_1st = input_1st.split()
split_input_2nd = list(map(int, input_2nd.split()))
split_input_3rd = list(map(int, input_3rd.split()))
split_input_4th = list(map(int, input_4th.split()))

x = int(split_input_1st[0])
y = int(split_input_1st[1])
a = int(split_input_1st[2])
b = int(split_input_1st[3])
c = int(split_input_1st[4])

result = 0

red_apple_list = sorted(split_input_2nd, reverse=True)
green_apple_list = sorted(split_input_3rd, reverse=True)
transparent_apple_list = sorted(split_input_4th, reverse=True)

repeat = 0
if x > y:
    repeat = x
else:
    repeat = y

for i in range(repeat):
    # print('i:', i)
    # if len(red_apple_list) == 0:
    if i > x - 1:
        if len(green_apple_list) == 0:
            # print('1:', transparent_apple_list[0])
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
        elif len(transparent_apple_list) == 0:
            # print('2:', green_apple_list[0])
            result += green_apple_list[0]
            green_apple_list.remove(green_apple_list[0])
        elif green_apple_list[0] > transparent_apple_list[0]:
            # print('3:', green_apple_list[0])
            result += green_apple_list[0]
            green_apple_list.remove(green_apple_list[0])
        else:
            # print('4:', transparent_apple_list[0])
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
    # elif len(green_apple_list) == 0:
    elif i > y - 1:
        if len(red_apple_list) == 0:
            # print('5:', transparent_apple_list[0])
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
        elif len(transparent_apple_list) == 0:
            # print('6:', red_apple_list[0])
            result += red_apple_list[0]
            red_apple_list.remove(red_apple_list[0])
        elif red_apple_list[0] > transparent_apple_list[0]:
            # print('7:', red_apple_list[0])
            result += red_apple_list[0]
            red_apple_list.remove(red_apple_list[0])
        else:
            # print('8:', transparent_apple_list[0])
            result += transparent_apple_list[0]
            transparent_apple_list.remove(transparent_apple_list[0])
    else:
        if red_apple_list[0] > green_apple_list[0]:
            if red_apple_list[0] > transparent_apple_list[0]:
                # print('9:', red_apple_list[0])
                result += red_apple_list[0]
                red_apple_list.remove(red_apple_list[0])
                if green_apple_list[0] > transparent_apple_list[0]:
                    # print('10:', transparent_apple_list[0])
                    result += green_apple_list[0]
                    green_apple_list.remove(green_apple_list[0])
                else:
                    # print('11:', transparent_apple_list[0])
                    result += transparent_apple_list[0]
                    transparent_apple_list.remove(transparent_apple_list[0])
            else:
                # print('12:', transparent_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
                if len(transparent_apple_list) != 0 and green_apple_list[0] > transparent_apple_list[0]:
                    # print('13:', green_apple_list[0])
                    result += green_apple_list[0]
                    green_apple_list.remove(green_apple_list[0])
                else:
                    # print('14:', transparent_apple_list[0])
                    result += transparent_apple_list[0]
                    transparent_apple_list.remove(transparent_apple_list[0])
        else:
            if green_apple_list[0] > transparent_apple_list[0]:
                # print('15:', green_apple_list[0])
                result += green_apple_list[0]
                green_apple_list.remove(green_apple_list[0])
                if red_apple_list[0] > transparent_apple_list[0]:
                    # print('16:', red_apple_list[0])
                    result += red_apple_list[0]
                    red_apple_list.remove(red_apple_list[0])
                else:
                    # print('17:', transparent_apple_list[0])
                    result += transparent_apple_list[0]
                    transparent_apple_list.remove(transparent_apple_list[0])
            else:
                # print('18:', transparent_apple_list[0])
                result += transparent_apple_list[0]
                transparent_apple_list.remove(transparent_apple_list[0])
                if len(transparent_apple_list) != 0 and red_apple_list[0] > transparent_apple_list[0]:
                    # print('19:', red_apple_list[0])
                    result += red_apple_list[0]
                    red_apple_list.remove(red_apple_list[0])
                else:
                    # print('20:', transparent_apple_list[0])
                    result += transparent_apple_list[0]
                    transparent_apple_list.remove(transparent_apple_list[0])
    
print(result)

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()))
lis=p+q+r
lis.sort(reverse=True)
ans=0
for i in range(x+y):
      ans+=lis[i]
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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        elif q[j] == v:
            ans += q[j]
            countB += 1
            j += 1
        else:
            ans += r[k]
            countC += 1
            k += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    for k in range(countC+1):
        m = X-countA - k
        n = Y-countB - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            ans = max(ans, ans + pp[m] + qq[n])
    return ans



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())
    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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        elif q[i] == v:
            ans += q[j]
            countB += 1
            j += 1
        else:
            ans += r[k]
            countC += 1
            k += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    for k in range(countC+1):
        m = X-countA - k
        n = Y-countB - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            ans = max(ans, ans + pp[m] + qq[n])
    return ans



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())
    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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        elif p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        else:
            ans += q[j]
            countB += 1
            j += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    for k in range(countC+1):
        m = X-countA - k
        n = Y-countB - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            ans = max(ans, ans + pp[m] + qq[n])
    return ans



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())
    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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        elif p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        else:
            ans += q[j]
            countB += 1
            j += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    out = ans
    for k in range(countC+1):
        m = X-countA - k
        n = Y-countB - (countC - k)
        if 0<= m < len(pp) and 0<=n < len(qq):
            out = max(out, ans + pp[m] + qq[n])
    return ans



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

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort()
q.sort()
p.reverse()
q.reverse()

a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=p[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range((X+Y)*2):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
  if(red>X and i-X-Y+1+green==Y):
    break
  if(i<X):
      sum1+=p[i]
      sum2+=c[i]
  if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
  if(i==X+Y and red<=X and green<=Y):
    print(d)
    break
  if(red>X and i-X-Y+1+green==Y):
    print(sum1)
    break
  elif(green>Y and i-X-Y+1+red==X):
    print(sum2)
    break

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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        elif p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        else:
            ans += q[j]
            countB += 1
            j += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    out = ans
    for k in range(countC+1):
        m = X - k - countA
        n = Y - (countC - k) - countB
        if 0<= m < len(pp) and 0<=n < len(qq):
            out = max(out, ans + pp[m] + qq[n])
    return ans



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

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort()
q.sort()
p.reverse()
q.reverse()

a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=p[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range((X+Y)*2):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
  if(red>X and i-X-Y+1+green==Y):
    break
  if(i<X):
      sum1+=p[i]
      sum2+=c[i]
  if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
  if(i==X+Y and red<=X and green<=Y):
    print(sum)
    break
  if(red>X and i-X-Y+1+green==Y):
    print(sum1)
    break
  elif(green>Y and i-X-Y+1+red==X):
    print(sum2)
    break

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    X, Y, A, B, C = iip()
    p = iip(listed=True)
    p.extend([0 for i in range(10**6)])
    q = iip(listed=True)
    q.extend([0 for i in range(10**6)])
    r = iip(listed=True)

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

    red = p[:X]
    blue = q[:Y]
    red.sort()
    blue.sort()

    #ir = 0
    #ib = 0
    #for nocolor in r:
    #    if min(red[ir], blue[ib]) < nocolor:
    #        if red[ir] < blue[ib]:
    #            red[ir] = nocolor
    #            if ir <= len(red)-2:
    #                ir += 1
    #        else:
    #            blue[ib] = nocolor
    #            if ir <= len(blue)-2:
    #                ib +=1
    #    else:
    #        break

    print(sum(red)+sum(blue))



    pass

if __name__ == "__main__":
    main()

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.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

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

for i in c:
  if a[-1] < b[-1] and i > a[-1]:
    # aに挿入
    for j in range(len(a)):
      if a[j] < i:
        a.insert(j, i)
        a.pop(-1)
  elif a[-1] >= b[-1] and i > b[-1]:
    # bに挿入
    for j in range(len(b)):
      if b[j] < i:
        b.insert(j, i)
        b.pop(-1)
  else:
    break
    
print(sum(a) + sum(b))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque

X,Y,A,B,C=map(int, sys.stdin.readline().split())
P=map(int, sys.stdin.readline().split())
Q=map(int, sys.stdin.readline().split())
R=map(int, sys.stdin.readline().split())
K=[X,Y]

S=[]
for p in P: S.append((p,0))
for q in Q: S.append((q,1))
for r in R: S.append((r,2))
S.sort(reverse=True)

ans=0
for value,kind in S:
    if kind in (0,1):   #0:赤 1:緑
        if K[kind]>0:
            ans+=value
            K[kind]-=1
    elif kind==2:       #2:無色
        if K[0]>0:
            ans+=value
            K[0]-=1
        elif K[1]>0:
            ans+=value
            K[1]-=1

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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        else:
            if p[i] == v:
                ans += p[i]
                countA += 1
                i += 1
            elif q[j] == v:
                ans += q[j]
                countB += 1
                j += 1

    if countA + countB + countC == X+Y:
        return ans

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

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    for i in range(len(p)):
        pp.append(pp[-1] + p[i])
    for j in range(len(q)):
        qq.append(qq[-1] + q[j])

    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 ans



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

Submission status: Wrong Answer

Solution code:
val = input().split(' ')
x = int(val[0])
y = int(val[1])
a = int(val[2])
b = int(val[3])
c = int(val[4])

p_list = sorted([int(a) for a in input().split(' ')])
q_list = sorted([int(a) for a in input().split(' ')])
r_list = sorted([int(a) for a in input().split(' ')])
p_list.reverse()
q_list.reverse()
r_list.reverse()

xapples = p_list[0:x+1]
yapples = q_list[0:y+1]
zapples = r_list[0:x+y+1]

xapples.extend(yapples)
xapples.extend(zapples)
tmp_apples = sorted(xapples)
tmp_apples.reverse()
apples = tmp_apples[0:x+y]
print(sum(apples))

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)


while r and min(p[X-1], q[Y-1]) < r[0]:
  p.sort(reverse=True)
  q.sort(reverse=True)
  if p[X-1] < q[Y-1]:
    p[X-1] = r[0]
    r.pop(0)
  else:
    q[Y-1] = r[0]
    r.pop(0)

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


while r and min(p[X-1], q[Y-1]) < r[0]:
  
  if p[X-1] < q[Y-1]:
    p[X-1] = r[0]
    r.pop(0)
  else:
    q[Y-1] = r[0]
    r.pop(0)

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

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split()) #x,yだけ見る。
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:]
print(sum(p+q+r[x+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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        else:
            if p[i] == v:
                ans += p[i]
                countA += 1
                i += 1
            if q[j] == v:
                ans += q[j]
                countB += 1
                j += 1

    if countA + countB + countC == X+Y:
        return ans

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    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 ans



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

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_right, bisect_left

def to_cumsum(arr, pad=True):
    """
    1次元配列を累積和の1次元配列に変換する
    pad: 先頭に0の項を作る場合はTrue
    """
    cumsum = 0
    padding = 1 if pad else 0
    new = [0] * (len(arr) + padding)
    for i, e in enumerate(arr):
        cumsum += e
        new[i + padding] = cumsum
    return new

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


X, Y, A, B, C = MI()
P = LMI()
Q = LMI()
R = LMI()

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

Pcum = to_cumsum(P, pad=True)
Qcum = to_cumsum(Q, pad=True)
Rcum = to_cumsum(R, pad=True)


def bi(arr, v):
    l = 0
    r = len(arr)
    while l + 1 < r:
        mid = (l + r) // 2
        if arr[mid] >= v:
            l = mid
        else:
            r = mid
    return r

ans = 0
for i in range(X + 1):
    a = Pcum[i]
    if X - i < len(R):
        idx = bi(Q, R[X - i])
        idx = min(idx, Y)
        a += Qcum[idx]
        ridx = X - i + max(0, Y - idx)
        a += Rcum[min(ridx, len(Rcum) - 1)]
    ans = max(ans, a)
print(ans)

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)

V = sorted(Ps[:X] + Qs[:Y] ,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:
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()))
R.sort(reverse=True)
P.sort(reverse=True)
Q.sort(reverse=True)

Z = P[:X]+Q[:Y]
for i in range(len(Z)):
    if Z[i]<R[0]:
        Z.insert(i,R[0])
        Z.pop(-1)
        R.pop(0)
    if len(R)==0:
        break
w = sum(Z)
print(w)

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+1):
    if R < 0:
        break
    if P < A:
        if (r[C-i-1] >= p[P]):
            if Q < B:
                if (q[Q] >= p[P]):
                    P += 1
                    R -= 1
                else:
                    break
            else:
                P += 1
                R -= 1
        elif Q < B:
            if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
            else:
                break
        else:
            break
    elif Q < B:
        if r[C-i-1] > q[Q]:
            Q += 1
            R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))

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

diff = abs(pr-qr)

sum = 0
sumcount = 0
rcount = 0
i = 0
while sumcount <= n-1:
    if rest[i][1] == 3:
        rcount += 1
        if rcount > diff:
            sum += rest[i][0]
            sumcount += 1
    else:
        sum += rest[i][0]
        sumcount += 1
    i += 1

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:
import sys
from collections import Counter
input = sys.stdin.readline

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 A > X:
    p = p[-X:]
if B > Y:
    q = q[-X:]

p.extend(q)
p.extend(r)

p.sort()

print(sum(p[-(X+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 and countA+countB+countC < X+Y:
        v = max([p[i], q[j], r[k]])
        if p[i] != v and q[j] != v:
            ans += r[k]
            countC += 1
            k += 1
        elif p[i] == v:
            ans += p[i]
            countA += 1
            i += 1
        elif q[j] == v:
            ans += q[j]
            countB += 1
            j += 1

    if countA + countB + countC == X+Y:
        return ans

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

    pp = [0]
    qq = [0]
    p = p[i:]
    q = q[j:]
    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 ans



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