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
readline=sys.stdin.buffer.readline
X,Y,A,B,C = map(int, readline().rstrip().split())
arr_a = readline().rstrip().decode().split()
arr_b = readline().rstrip().decode().split()
arr_c = readline().rstrip().decode().split()
s_arr_a = sorted(arr_a,reverse=True)
s_arr_b = sorted(arr_b,reverse=True)
s_arr_c = sorted(arr_c,reverse=True)
s2_arr_a = s_arr_a.copy()
s2_arr_b = s_arr_b.copy()
s2_arr_c = s_arr_c.copy()
ans1 = 0
ans2 = 0
for i in range(X):
  if len(s_arr_a) > 0 and len(s_arr_c) > 0:
    if int(s_arr_a[0]) > int(s_arr_c[0]):
      ans1+=int(s_arr_a.pop(0))
    else:
      ans1+=int(s_arr_c.pop(0))
  elif len(s_arr_a) > 0:
      ans1+=int(s_arr_a.pop(0))
  else:
      ans1+=int(s_arr_c.pop(0))
for i in range(Y):
  if len(s_arr_b) > 0 and len(s_arr_c) > 0:
    if int(s_arr_b[0]) > int(s_arr_c[0]):
      ans1+=int(s_arr_b.pop(0))
    else:
      ans1+=int(s_arr_c.pop(0))
  elif len(s_arr_b) > 0:
      ans1+=int(s_arr_b.pop(0))
  else:
      ans1+=int(s_arr_c.pop(0))

for i in range(Y):
  if len(s2_arr_b) > 0 and len(s2_arr_c) > 0:
    if int(s2_arr_b[0]) > int(s2_arr_c[0]):
      ans2+=int(s2_arr_b.pop(0))
    else:
      ans2+=int(s2_arr_c.pop(0))
  elif len(s2_arr_b) > 0:
      ans2+=int(s2_arr_b.pop(0))
  else:
      ans2+=int(s2_arr_c.pop(0))

for i in range(X):
  if len(s2_arr_a) > 0 and len(s2_arr_c) > 0:
    if int(s2_arr_a[0]) > int(s2_arr_c[0]):
      ans2+=int(s2_arr_a.pop(0))
    else:
      ans2+=int(s2_arr_c.pop(0))
  elif len(s2_arr_a) > 0:
      ans2+=int(s2_arr_a.pop(0))
  else:
      ans2+=int(s2_arr_c.pop(0))
if ans1 >= ans2:
  print(ans1)
else:
  print(ans2)

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y+1]
px = 0
qx = 0
for i in range(C):
    if px == len(p) or qx ==len(q):
        break
    if min(p[px],q[qx],r[i]) ==p[px]:
        p[px] = r[i]
        px +=1
    elif min(p[px],q[qx],r[i]) ==q[qx]:
        q[qx] = r[i]
        qx += 1
    else:
        px += 1
        qx += 1
print(sum(p)+sum(q))

Submission status: Wrong Answer

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

sump = sum(p)
sumq = sum(q)
ans = sump + sumq
for c in range(C):
    rc = r[c]
    if not p or p[-1] < rc:
        if p:
            sump -= p.pop()
        sump += rc
    elif not q or q[-1] < rc:
        if q:
            sumq -= q.pop()
        sumq += rc
    ans = max(ans, sump + sumq)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
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]

p.append(10**4)
q.append(10**4)
r.append(10**4)
result = sum(p+q)-2*(10**4)
ii, jj = x+y, c
for i in range(min(ii, jj)):

    if p[x-1]<r[c-1]:
        result += r[c-1]-p[x-1]
        c -= 1
        x -= 1
    elif q[y-1]<r[c-1]:
        result += r[c-1]-q[y-1]
        c -= 1
        y -= 1
    else:
        break
print(result)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
x,y,a,b,c=LI()
p=LI()
q=LI()
r=LI()

def solve(p,q,r):
    ans=0
    q=[(-i,0) for i in q]
    r=[(-i,1) for i in r]
    g=q+r
    heapify(g)
    
    c=0
    bl=0
    while c<y:
        j,t=heappop(g)
        ans+=-j
        bl+=t
        c+=1
    
    while g:
        j,t=g.pop()
        if t==1:
            p.append(-j)
    p.sort(key=lambda z:-z)
    ans+=sum(p[:x])
    return ans
    
print(max(solve(p,q,r),solve(q,p,r)))

Submission status: Wrong Answer

Solution code:
#E - Red and Green Apples
X,Y,A,B,C= map(int, input().split())
a =sorted(list(map(int, input().split())),reverse=True)
b =sorted(list(map(int, input().split())),reverse=True)
c =sorted(list(map(int, input().split())),reverse=True)

DP_a =[]
DP_b =[]
j = 1
k = 1
a_s =sum(a[:X])
b_s =sum(b[:Y])

for i in range(C):
    if c[i] > a[X-j] or c[i] > b[Y-k]:
        if c[i] > a[X-j] and a[X-j] > b[Y-k]:
            j += 1
            if j >= X:
                DP_a.append(c[i])
            else:
                pass
        elif c[i] > b[Y-k] :
            k += 1
            if k >= Y:
                DP_b.append(c[i])
            else:
                pass
        else:
            pass
    else:
        break

a_s = a_s-sum(a[X-len(DP_a):X])+sum(DP_a)
b_s = b_s-sum(b[Y-len(DP_b):Y])+sum(DP_b)


print(a_s+b_s)

Submission status: Wrong Answer

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]

x_a.reverse()
x_b.reverse()

s = 0
v = 0
t = 0
while s < x and v < y and t < c:
    if x_a[s] <= x_b[v]:
        #print('B')
        if x_a[s] <= s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        else:
            break
    else:
        #print('A')
        if x_b[v] < s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        else:
            break

ans = sum(x_a) + sum(x_b)
print(ans)

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
apple_list = split_input_2nd + split_input_3rd + split_input_4th
apple_list = sorted(apple_list, reverse=True)
for i in range(x+y):
    result += apple_list[i]
    
print(result)

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    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)

    ptn1 = 0
    ptn2 = 0
    ptn1 = sum(q[:y])
    ptn2 = sum(p[:x])
    idxr = 0
    idxp = 0
    for i in range(x):
        if r[idxr] > p[idxp]:
            ptn1 += r[idxr]
            idxr += 1
        else:
            ptn1 += p[idxp]
            idxp += 1
    idxr = 0
    idxq = 0
    for i in range(y):
        if r[idxr] > q[idxq]:
            ptn2 += r[idxr]
            idxr += 1
        else:
            ptn2 += q[idxq]
            idxq += 1

    print(max(ptn1,ptn2))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from pprint import pprint
from bisect import bisect_left
import numpy


def read():
    X, Y, A, B, C = list(map(int, input().strip().split()))
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    R = list(map(int, input().strip().split()))
    return X, Y, A, B, C, P, Q, R

def argsort(x, reverse=False):
    return sorted(range(len(x)), key=lambda k: x[k], reverse=reverse)

def solve(X, Y, A, B, C, P, Q, R):
    P = list(sorted(P, reverse=True))
    Q = list(sorted(Q, reverse=True))
    R = list(sorted(R, reverse=True))

    i = X
    j = Y
    k = 0
    score = sum(P[0:i]) + sum(Q[0:j])
    for r in R:
        if i > 0 and j > 0:
            if P[i-1] < Q[j-1] and P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
                k += 1
            elif Q[j-1] <= P[i-1] and Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
                k += 1
            else:
                break
        elif i > 0:
            if P[i-1] < r:
                score = score - P[i-1] + r
                i -= 1
                k += 1
            else:
                break
        elif j > 0:
            if Q[j-1] < r:
                score = score - Q[j-1] + r
                j -= 1
                k += 1
            else:
                break
        else:
            break
    print(P[:i])
    print(Q[:j])
    print(R[:(X-i)], R[(X-i):(Y-j)])
    return sum(P[:i] + Q[:j] + R[:(X-i)+(Y-j)])

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Wrong Answer

Solution code:
#E - Red and Green Apples
X,Y,A,B,C= map(int, input().split())
a =sorted(list(map(int, input().split())),reverse=True)
b =sorted(list(map(int, input().split())),reverse=True)
c =sorted(list(map(int, input().split())),reverse=True)
print(a,b,c)
DP_a =[]
DP_b =[]
j = 1
k = 1
a_s =sum(a[:X])
b_s =sum(b[:Y])

for i in range(C):
    if c[i] > a[X-j] or c[i] > b[Y-k]:
        if c[i] > a[X-j] and a[X-j] > b[Y-k]:
            j += 1
            if j >= X:
                DP_a.append(c[i])
            else:
                pass
        elif c[i] > b[Y-k] :
            k += 1
            if k >= Y:
                DP_b.append(c[i])
            else:
                pass
        else:
            pass
    else:
        break

a_s = a_s-sum(a[X-len(DP_a):X])+sum(DP_a)
b_s = b_s-sum(b[Y-len(DP_b):Y])+sum(DP_b)


print(a_s+b_s)

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X, Y, A, B, C = iim()
    P = list(iim())
    Q = list(iim())
    R = list(iim())

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

    p1 = [0]*(X+1)
    for i in range(X):
        p1[i+1] = p1[i] + P[i]
    q1 = [0]*(Y+1)
    for i in range(Y):
        q1[i+1] = q1[i] + Q[i]

    si = [X-1, Y-1]
    S = [P, Q]
    if P[si[0]] < Q[si[1]]:
        idx = 0
    else:
        idx = 1
    ans = 0
    for i in range(C):
        if S[idx][si[idx]] < R[i]:
            si[idx] -= 1
            ans += R[i]

            if si[idx] < 0:
                if si[idx^1] == 0:
                    break
                else:
                    idx ^= 1
            elif P[si[0]] < Q[si[1]]:
                idx = 0
            else:
                idx = 1
        else:
            break

    print(p1[si[0]+1] + q1[si[1]+1] + ans)

if __name__ == "__main__":
    resolve()

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)

p = p[:x]
q = q[:x]
a = p + q + r 
a = sorted(a, reverse=True)
print(sum(a[:x+y]))

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
while sumcount <= n-1:
    if rest[i][0] == 3:
        rcount += 1
        if rcount > diff:
            sum += rest[i][0]
            sumcount += 1
    else:
        sum += rest[i][0]
        sumcount += 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:
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.insert(0, 0)
p.append(0)
q.insert(0, 0)
q.append(0)
r.append(0)

result = sum(p[:x+1]) + sum(q[:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Submission status: Wrong Answer

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

pq = sorted(p[:X] + q[:Y])
for i in range(min(X+Y,C)):
  if r[i] < pq[i]:
    break
else:
  i+=1
print(sum(r[:i] + pq[i:]))

Submission status: Wrong Answer

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

s_a = [int(i) for i in list(input().split())]
s_b = [int(i) for i in list(input().split())]
s_c = [int(i) for i in list(input().split())]

s_a.sort(reverse = True)
s_b.sort(reverse = True)
s_c.sort(reverse = True)

x_a = s_a[0:x]
x_b = s_b[0:y]

x_a.reverse()
x_b.reverse()

s = 0
v = 0
t = 0
while s < x and v < y and t < c:
    if x_a[s] <= x_b[v]:
        #print('B')
        if x_a[s] <= s_c[t]:
            x_a[s] = s_c[t]
            s += 1
            t += 1
        else:
            break
    else:
        #print('A')
        if x_b[v] <= s_c[t]:
            x_b[v] = s_c[t]
            v += 1
            t += 1
        else:
            break

ans = sum(x_a) + sum(x_b)
print(ans)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = (int(i_x) for i_x in input().split())

allredapple = input().split()
allgreenapple = input().split()
allnonapple =input().split()

allredapple.sort(reverse=True)
allgreenapple.sort(reverse=True)
allnonapple.sort(reverse=True)


zenalist = allredapple[:x] + allgreenapple[:y]
zenalist.sort(reverse=True)

for i in range(len(allnonapple)):
  for k in range(len(zenalist)):
    if int(zenalist[k]) < int(allnonapple[i]):
      zenalist[k] = allnonapple[i]
      break

anser = 0      
for i in range(len(zenalist)):
  anser += int(zenalist[i])

print(anser)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=map(int,input().split())
a=list(map(int,input().rstrip().split()))
b=list(map(int,input().rstrip().split()))
c=list(map(int,input().rstrip().split()))
a.sort(reverse=True)
b.sort(reverse=True)
d=0
c.sort(reverse=True)
a1=a+c
a1.sort(reverse=True)
for i in range(x):
    d=d+a1[i]
l=x-len(c)
b1=b+c[l:len(c)]
b1.sort(reverse=True)
for j in range(y):
    d=d+b1[j]
print(d)

Submission status: Wrong Answer

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

pq = sorted(p[:X] + q[:Y])
print(pq,r)
for i in range(min(X+Y,C)):
  if r[i] < pq[i]:
    break
else:
  i+=1
print(i)
print(sum(r[:i] + pq[i:]))

Submission status: Wrong Answer

Solution code:
import heapq

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

p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=False)

red = p[:X]
green = q[:Y]
nocolor = r


heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)

for nc in nocolor:
    R = heapq.heappop(red)
    G = heapq.heappop(green)
    heapq.heappush(red,R)
    heapq.heappush(green,G)
    if R > nc and G > nc:
        break
    elif nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green,nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red,nc)
    elif nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red,nc)
    elif nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green,nc)


print(sum(red)+sum(green))

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0
x,y,a,b,c=LI()
p=LI()
q=LI()
r=LI()
q=[(-i,0) for i in q]
r=[(-i,1) for i in r]
g=q+r
heapify(g)

c=0
bl=0
while c<y:
    j,t=heappop(g)
    ans+=-j
    bl+=t
    c+=1

while g:
    j,t=g.pop()
    if t==1:
        p.append(-j)
p.sort(key=lambda z:-z)
ans+=sum(p[:x])

print(ans)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
red=list(map(int, input().split()))
green=list(map(int, input().split()))
white=list(map(int, input().split()))
list=[]
a=0
b=0
c=0
for j in range(i[0]):
    a=max(red)
    list.append(a)
for j in range(i[1]):
    b=max(green)
    list.append(b)
for j in range(i[0]+i[1]):
    if max(white)>min(list):
        list.remove(min(list))
        list.append(max(white))
    else:
        break
print(sum(list))

Submission status: Wrong Answer

Solution code:
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
r = sorted(r,reverse = True)
p = p[A-X:]
q = q[B-Y:]
if X+Y<C:
    r = r[:X+Y+1]
px = 0
qx = 0
for i in range(len(r)):
    if px == len(p) or qx ==len(q):
        break
    if min(p[px],q[qx],r[i]) ==p[px]:
        p[px] = r[i]
        px +=1
    elif min(p[px],q[qx],r[i]) ==q[qx]:
        q[qx] = r[i]
        qx += 1
    else:
        px += 1
        qx += 1
print(sum(p)+sum(q))

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)
s =0

e = max(X,Y)
for a in range (e):
    if P[a]>Q[a] and len(R)!=0:
        if Q[a]<R[0]:
            Q.insert(a, R[0])
            R.pop(0)
    elif P[a]<Q[a] and len(R)!=0:
        if P[a]<R[0]:
            P.insert(a, R[0])
            R.pop(0)
for i in range (X):
    s += P[i]
for j in range (Y):
    s += Q[j]
print(s)

Submission status: Wrong Answer

Solution code:
x,y,a,b,c = list(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)
cnt = 0
while x > 0:
    if len(r) == 0:
        if len(p) == 0:
            break
        else:
            cnt += p.pop(0)
    elif p[0] >= r[0]:
        cnt += p.pop(0)
    else:
        cnt += r.pop(0)
    x -= 1
while y > 0:
    if len(r) == 0:
        if len(q) == 0:
            break
        else:
            cnt += q.pop(0)
    elif q[0] >= r[0]:
        cnt += q.pop(0)
    else:
        cnt += r.pop(0)
    y -= 1  
print(cnt)

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()))
S=[[0,'pqr'] for j in range(A+B+C)]
countX=X
countY=Y
count=0
for i in range(A):
    S[i]=[p[i],'p']
for i in range(B):
    S[A+i]=[q[i],'q']
for i in range(C):
    S[A+B+i]=[r[i],'r']
S_sorted = sorted(S, key=lambda x: x[0])
for i in range(len(S_sorted)):
    if S_sorted[len(S_sorted)-i-1][1]=='p':
        if countX>0:
            countX-=1
            count+=S_sorted[len(S_sorted)-i-1][0]
    elif S_sorted[len(S_sorted)-i-1][1]=='q':
        if countY>0:
            countY-=1
            count+=S_sorted[len(S_sorted)-i-1][0]
    else:
        if countX==0:
            countY-=1
            count+=S_sorted[len(S_sorted)-i-1][0]
        else:
            countX-=1
            count+=S_sorted[len(S_sorted)-i-1][0]
    
    if countX==0 and countY==0:
        break
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    x, y, a, b, c = map(int, input().split())
    al = sorted(list(map(int, input().split())), reverse=True)[:x]
    bl = sorted(list(map(int, input().split())), reverse=True)[:y]
    cl = sorted(list(map(int, input().split())), reverse=True)
    ans = 0
    xi, yi = 0, 0
    for i in cl:
        if al:
            ai = al[-1]
        else:
            ai = 0
        if bl:
            bi = bl[-1]
        else:
            bi = 0
        if ai < bi:
            if al:
                m = al.pop()
            else:
                m = 0
        else:
            if bl:
                m = bl.pop()
            else:
                m = 0
                
        if m < i:
            ans += i
        else:
            ans += m
            break
    ans += sum(al)+sum(bl)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x,y,a,b,c=tuple(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)
sum=[]
while(x>0 or y>0):
    if(x>0 and y>0 and p[0]<q[0]):
        if(c>0 and r[0]>p[0]):
            sum.append(r[0])
            r.pop(0)
            x-=1
            c-=1
        else:
            sum.append(p[0])
            p.pop(0)
            x-=1
    elif(x>0 and y>0):
        if(c>0 and r[0]>q[0]):
            sum.append(r[0])
            r.pop(0)
            y-=1
            c-=1
        else:
            sum.append(q[0])
            q.pop(0)
            y-=1
    elif(x>0):
        if(c>0 and r[0]>p[0]):
            sum.append(r[0])
            r.pop(0)
            x-=1
            c-=1
        else:
            sum.append(p[0])
            p.pop(0)
            x-=1
    elif(y>0):
        if(c>0 and r[0]>q[0]):
            sum.append(r[0])
            r.pop(0)
            y-=1
            c-=1
        else:
            sum.append(q[0])
            q.pop(0)
            y-=1
suml=0
for i in sum:
    suml+=i

print(suml)

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    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)

    ptn1 = 0
    ptn2 = 0
    ptn1 = sum(q[:y])
    ptn2 = sum(p[:x])
    idx = 0
    for i in range(x):
        if r[idx] > p[i]:
            ptn1 += r[idx]
            idx += 1
        else:
            ptn1 += p[i]
    idx = 0
    for i in range(y):
        if r[idx] > q[i]:
            ptn2 += r[idx]
            idx += 1
        else:
            ptn2 += q[i]

    print(max(ptn1,ptn2))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq

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

p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()), reverse=False)

red = p[:X]
green = q[:Y]
nocolor = r


heapq.heapify(red)
heapq.heapify(green)
# heapq.heapify(nocolor)

for nc in nocolor:
    R = red[0]
    G = green[0]
    if R > nc and G > nc:
        break
    elif nc > R and nc > G:
        if R > G:
            q = heapq.heappop(green)
            heapq.heappush(green,nc)
        else:
            q = heapq.heappop(red)
            heapq.heappush(red,nc)
    elif nc > R:
        q = heapq.heappop(red)
        heapq.heappush(red,nc)
    elif nc > G:
        q = heapq.heappop(green)
        heapq.heappush(green,nc)


print(sum(red)+sum(green))