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 heapq


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    X, Y, A, B, C = map(int, input().split())
    red = list(map(int, input().split()))
    green = list(map(int, input().split()))
    nocolor = list(map(int, input().split()))

    red.sort()
    green.sort()
    nocolor.sort()
    answer = sum(red[A - X :]) + sum(green[B - Y :])
    heap = red[A - X :] + green[B - Y :]
    flag = 0
    while heap and flag < C:
        m = heapq.heappop(heap)
        if nocolor[flag] > m:
            answer -= m
            answer += nocolor[flag]
            heapq.heappush(heap, nocolor[flag])
            flag += 1
        else:
            heapq.heappush(heap, m)
            flag += 1
    print(answer)


if __name__ == "__main__":
    main()

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(lambda x: -int(x), input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
p = p[:X]
q = q[:Y]

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(R)

while len(R) > 0:
    r = heapq.heappop(p)
    g = heapq.heappop(q)
    t = heapq.heappop(R)
    if r >= -t and g >= -t:
        heapq.heappush(p, r)
        heapq.heappush(q, g)
        break
    if r < -t:
        heapq.heappush(p, -t)
        heapq.heappush(q, g)
    else:
        heapq.heappush(q, -t)
        heapq.heappush(p, r)

print(sum(list(p)) + sum(list(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()
q.sort()
r.sort(reverse=True)

ppick = p[-x:]
qpick = q[-y:]

pi = 0
qi = 0

for i in range(len(r)):
    if pi >= x:
        while True:
            if qi < y and i < c and r[i] > qpick[qi]:
                qpick[qi] = r[i]
                qi += 1
                i += 1
            else:
                break
    elif qi >= y:
        while True:
            if pi < x and i < c and r[i] > ppick[pi]:
                ppick[pi] = r[i]
                pi += 1
                i += 1
            else:
                break
    elif ppick[pi] > qpick[qi] and qpick[qi] < r[i]:
        qpick[qi] = r[i]
        qi += 1
        continue
    elif ppick[pi] < qpick[qi] and ppick[pi] < r[i]:
        ppick[pi] = r[i]
        pi += 1
        continue
    break

print(sum(ppick) + sum(qpick))

Submission status: Wrong Answer

Solution code:
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 = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
p_cum = [0]
q_cum = [0]
r_cum = [0]
for i in range(a):
    p_cum.append(p_cum[i] + p[i])
for i in range(b):
    q_cum.append(q_cum[i] + q[i])
for i in range(c):
    r_cum.append(r_cum[i] + r[i])
ans = 0
for i in range(0, min(c, a) + 1):
    for j in range(0, min(c - i, b) + 1):
        ans = max(ans, p_cum[x - i] + q_cum[y - j] + r_cum[i + j])
print(ans)

Submission status: Wrong Answer

Solution code:
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 = list(reversed(sorted(p)))
q = list(reversed(sorted(q)))
r = list(reversed(sorted(r)))
p_cum = [0]
q_cum = [0]
r_cum = [0]
for i in range(a):
    p_cum.append(p_cum[i] + p[i])
for i in range(b):
    q_cum.append(q_cum[i] + q[i])
for i in range(c):
    r_cum.append(r_cum[i] + r[i])
ans = 0
for i in range(0, min(c, a) + 1):
    for j in range(0, min(c - i, b) + 1):
        print(x-i, y-j, i+j)
        ans = max(ans, p_cum[x - i] + q_cum[y - j] + r_cum[i + j])
print(ans)

Submission status: Wrong Answer

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

p.sort(key=lambda x: -x)
q.sort(key=lambda x: -x)
r.sort(key=lambda x: -x)

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

psum = sum(p)
qsum = sum(q)
pi, qi, ri = 0, 0, 0
while ri < len(r):
    found = ""
    if pi < X and qi < Y:
        if p[pi] <= q[qi]:
            if p[pi] < r[ri]:
                found = "p"
        else:
            if q[qi] < r[ri]:
                found = "q"
    elif pi < X:
        if p[pi] < r[ri]:
            found = "p"
    elif qi < Y:
        if q[qi] < r[ri]:
            found = "q"

    if found == "p":
        psum -= p[pi]
        psum += r[ri]
        ri += 1
    elif found == "q":
        qsum -= q[qi]
        qsum += r[ri]
        ri += 1
    else:
        break

print(psum+qsum)

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)
p_s=[0]*(a+1)
q_s=[0]*(b+1)
r_s=[0]*(c+1)
p_s[0]=0
q_s[0]=0
r_s[0]=0
res1=res2=0

for i in range(1,max(a,b,c)+1):
    if i<a+1:
        p_s[i]=p_s[i-1]+p[i-1]
    if i<b+1:
        q_s[i]=q_s[i-1]+q[i-1]
    if i<c+1:
        r_s[i]=r_s[i-1]+r[i-1]
res1=p_s[x]
res2=q_s[y]
numc=0
for i in range(1,c+1):
    if x-i<0 or res1>=p_s[x-i]+r_s[i]:
        numc=i-1
        break
    else:
        res1=p_s[x-i]+r_s[i]
if numc!=0:
    r_s=list(map(lambda x:x-r_s[numc] , r_s))
for i in range(1,c-numc+1):
    if y-i<0 or res2>=q_s[y-i]+r_s[i+numc]:
        break
    else:
        res2=q_s[y-i]+r_s[i+numc]
print(res1+res2)

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)
p_s=[0]*(a+1)
q_s=[0]*(b+1)
r_s=[0]*(c+1)
p_s[0]=0
q_s[0]=0
r_s[0]=0
res1=res2=0

for i in range(1,max(a,b,c)+1):
    if i<a+1:
        p_s[i]=p_s[i-1]+p[i-1]
    if i<b+1:
        q_s[i]=q_s[i-1]+q[i-1]
    if i<c+1:
        r_s[i]=r_s[i-1]+r[i-1]
res1=p_s[x]
res2=q_s[y]
numc=0
for i in range(1,c+1):
    if x-i<0 or res1>=p_s[x-i]+r_s[i]:
        numc=i-1
        break
    else:
        res1=p_s[x-i]+r_s[i]
if numc!=0:
    r_s=list(map(lambda x:x-r_s[numc-1] , r_s))
for i in range(1,c-numc+1):
    if y-i<0 or res2>=q_s[y-i]+r_s[i]:
        break
    else:
        res2=q_s[y-i]+r_s[i]
print(res1+res2)

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)
p_s=[0]*(a+1)
q_s=[0]*(b+1)
r_s=[0]*(c+1)
p_s[0]=0
q_s[0]=0
r_s[0]=0
res1=res2=0

for i in range(1,max(a,b,c)):
    if i<a:
        p_s[i]=p_s[i-1]+p[i-1]
    if i<b:
        q_s[i]=q_s[i-1]+q[i-1]
    if i<c:
        r_s[i]=r_s[i-1]+r[i-1]
res1=p_s[x]
res2=q_s[y]
numc=0
for i in range(1,c+1):
    if x-i<0 or res1>=p_s[x-i]+r_s[i]:
        numc=i-1
        break
    else:
        res1=p_s[x-i]+r_s[i]
if numc!=0:
    r_s=list(map(lambda x:x-r_s[numc-1] , r_s))
for i in range(1,c-numc+1):
    if y-i<0 or res2>=q_s[y-i]+r_s[i]:
        break
    else:
        res2=q_s[y-i]+r_s[i]
print(res1+res2)

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)
p_s=[0]*a
q_s=[0]*b
r_s=[0]*c
p_s[0]=p[0]
q_s[0]=q[0]
r_s[0]=r[0]
res1=res2=0

for i in range(1,max(a,b,c)):
    if i<a:
        p_s[i]=p_s[i-1]+p[i]
    if i<b:
        q_s[i]=q_s[i-1]+q[i]
    if i<c:
        r_s[i]=r_s[i-1]+r[i]
res1=p_s[x-1]
res2=q_s[y-1]
numc=0
for i in range(1,c+1):
    if x-i-1<0 or res1>=p_s[x-i-1]+r_s[i-1]:
        numc=i-1
        break
    else:
        res1=p_s[x-i-1]+r_s[i-1]
if numc!=0:
    r_s=list(map(lambda x:x-r_s[numc-1] , r_s))
for i in range(1,c-numc+1):
    if y-i-1<0 or res2>=q_s[y-i-1]+r_s[i-1]:
        break
    else:
        res2=q_s[y-i-1]+r_s[i-1]
print(res1+res2)

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)
p_s=[0]*a
q_s=[0]*b
r_s=[0]*c
p_s[0]=p[0]
q_s[0]=q[0]
r_s[0]=r[0]
res1=res2=0

for i in range(1,max(a,b,c)):
    if i<a:
        p_s[i]=p_s[i-1]+p[i]
    if i<b:
        q_s[i]=q_s[i-1]+q[i]
    if i<c:
        r_s[i]=r_s[i-1]+r[i]
res1=p_s[x-1]
res2=q_s[y-1]
numc=0
for i in range(1,c+1):
    if x-i-1<0 or res1>=p_s[x-i-1]+r_s[i-1]:
        numc=i-1
        break
    else:
        res1=p_s[x-i-1]+r_s[i-1]
for i in range(1,c-numc+1):
    if y-i-1<0 or res2>q_s[y-i-1]+r_s[i-1]:
        break
    else:
        res2=q_s[y-i-1]+r_s[i-1]
print(res1+res2)

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)
p_s=[0]*a
q_s=[0]*b
r_s=[0]*c
p_s[0]=p[0]
q_s[0]=q[0]
r_s[0]=r[0]
res1=res2=0

for i in range(1,max(a,b,c)):
    if i<a:
        p_s[i]=p_s[i-1]+p[i]
    if i<b:
        q_s[i]=q_s[i-1]+q[i]
    if i<c:
        r_s[i]=r_s[i-1]+r[i]
res1=p_s[x-1]
res2=q_s[x-1]
numc=0
for i in range(1,c+1):
    if x-i-1<0 or res1>=p_s[x-i-1]+r_s[i-1]:
        numc=i-1
        break
    else:
        res1=p_s[x-i-1]+r_s[i-1]
for i in range(1,c-numc+1):
    if y-i-1<0 or res2>q_s[y-i-1]+r_s[i-1]:
        break
    else:
        res2=q_s[y-i-1]+r_s[i-1]
print(res1+res2)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
P.sort(reverse=True)
Q = list(map(int, input().split()))
Q.sort(reverse=True)
R = list(map(int, input().split()))
R.sort(reverse=True)
p = 0
q = 0
r = 0
x = 0
y = 0
res = 0

while x < X or y < Y:
    _p = P[p] if p < A else 0
    _q = Q[q] if q < B else 0
    _r = R[r] if r < C else 0
    if x >= X:
        y += 1
        if _q > _r:
            res += _q
            q += 1
        else:
            res += _r
            r += 1
    elif y >= Y:
        x += 1
        if _p > _r:
            res += _p
            p += 1
        else:
            res += _r
            r += 1
    elif _r >= _p and _r >= _q:
        res += _r
        r += 1
        if _p > _q:
            y += 1
        else:
            x += 1
    elif _p > _q:
        res += _p
        p += 1
        x += 1
    elif _p <= _q:
        res += _q
        q += 1
        y += 1

print(res)

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
P.sort(reverse=True)
Q = list(map(int, input().split()))
Q.sort(reverse=True)
R = list(map(int, input().split()))
R.sort(reverse=True)
p = 0
q = 0
r = 0
x = 0
y = 0
res = 0

while x < X or y < Y:
    _p = P[p] if p < A else 0
    _q = Q[q] if q < B else 0
    _r = R[r] if r < C else 0
    if _r >= _p and _r >= _q:
        res += _r
        r += 1
        if _p > _q and y < Y:
            y += 1
        else:
            if x < X:
                x += 1
            else:
                y += 1

    elif _p > _q and x < X:
        res += _p
        p += 1
        x += 1
    elif _p <= _q and y < Y:
        res += _q
        q += 1
        y += 1
    else:
        if x < X:
            p += 1
            res += _p
            x += 1
        else:
            q += 1
            res += _q
            y += 1

print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    x, y, a, b, c = map(int, stdin.readline().split())
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

    pqr = []

    for pi in p:
        pqr.append([pi, 0])
    for qi in q:
        pqr.append([qi, 1])
    for ri in r:
        pqr.append([ri, 2])

    pqr.sort(reverse=True)

    ans = 0
    c_a = 0
    c_b = 0
    c_c = 0

    for pqri in pqr:
        if pqri[1] == 0 and c_a < x:
            ans += pqri[0]
            c_a += 1
        elif pqri[1] == 1 and c_b < y:
            ans += pqri[0]
            c_b += 1
        elif pqri[1] == 2 and (c_a < x or c_b < y) and c_a + c_b + c_c < x + y:
            ans += pqri[0]
            c_c += 1
        elif c_a + c_b + c_c == x + y:
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
import heapq
class Heapq:
    # 最大値を取り出す際は desc=True に設定
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
s = sorted(p, reverse=True)[:x]
t = sorted(q, reverse=True)[:y]
u = sorted(r, reverse=True)
ans = sum(s) + sum(t)
heap_x = Heapq(s)
heap_y = Heapq(t)
heap_r = Heapq(u, desc=True)
for i in range(c):
    xi = heap_x.top()
    yi = heap_y.top()
    ri = heap_r.top()
    if ri > xi or ri > yi:
        if xi > yi:
            ans -= yi
            ans += ri
            heap_r.pop()
            heap_y.push(ri)
        else:
            ans -= xi
            ans += ri
            heap_r.pop()
            heap_x.push(ri)
    else:
      break
      heap_r.pop()
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()))
import heapq
class Heapq:
    # 最大値を取り出す際は desc=True に設定
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
s = sorted(p, reverse=True)[:x]
t = sorted(q, reverse=True)[:y]
u = sorted(r, reverse=True)
ans = sum(s) + sum(t)
heap_x = Heapq(s)
heap_y = Heapq(t)
heap_r = Heapq(u, desc=True)
for i in range(c):
    xi = heap_x.top()
    yi = heap_y.top()
    ri = heap_r.top()
    if ri > xi or ri > yi:
        if xi > yi:
            ans -= yi
            ans += ri
            heap_r.pop()
            heap_y.push(ri)
        else:
            ans -= xi
            ans += ri
            heap_r.pop()
            heap_x.push(ri)
    else:
      heap_r.pop()
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()))
import heapq
class Heapq:
    # 最大値を取り出す際は desc=True に設定
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        return heapq.heappop(self.hq) * self.sign
 
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
 
    def top(self):
        return self.hq[0] * self.sign
s = sorted(p, reverse=True)[:x]
t = sorted(q, reverse=True)[:y]
u = sorted(r, reverse=True)
ans = sum(s) + sum(t)
heap_x = Heapq(s)
heap_y = Heapq(t)
heap_r = Heapq(u, desc=True)
for i in range(c):
    xi = heap_x.top()
    yi = heap_y.top()
    ri = heap_r.top()
    if ri > xi or ri > yi:
        if xi > yi:
            ans -= yi
            ans += ri
            heap_r.pop()
            heap_y.push(ri)
        else:
            ans -= xi
            ans += ri
            heap_r.pop()
            heap_x.push(ri)
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)
p_sum = [0]*(a+1)
q_sum = [0]*(b+1)
for i in range(a):
    p_sum[i+1] = p_sum[i] + p[i]
for i in range(b):
    q_sum[i+1] = q_sum[i] + q[i]
#print(p_sum)
#print(q_sum)
ans = [0]*(c+1)
ans[0] = p_sum[X] + q_sum[Y]
x, y = X, Y
for i in range(c):
    ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i]-q[y-1]+r[i], ans[i])
    if ans[i+1] == ans[i]-p[x-1]+r[i]:
        x -= 1
    elif ans[i+1] == ans[i]-q[y-1]+r[i]:
        y -= 1
    elif ans[i+1] == ans[i]:
        break

print(max(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)
p_sum = [0]*(a+1)
q_sum = [0]*(b+1)
for i in range(a):
    p_sum[i+1] = p_sum[i] + p[i]
for i in range(b):
    q_sum[i+1] = q_sum[i] + q[i]
#print(p_sum)
#print(q_sum)
ans = [0]*(c+1)
ans[0] = p_sum[X] + q_sum[Y]
x, y = X, Y
for i in range(c):
    ans[i+1] = max(ans[i]-p[x-1]+r[i], ans[i]-q[y-1]+r[i], ans[i])
    if ans[i+1] == ans[i]-p[x-1]+r[i]:
        x -= 1
    elif ans[i+1] == ans[i]-q[y-1]+r[i]:
        y -= 1
print(max(ans))

Submission status: Wrong Answer

Solution code:
X, Y, A, B, C = map(int, input().split())
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()])


S = sorted(P[:X]+Q[:Y]+R, reverse=True)
ans = sum(S[:X+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.extend(q)
p.extend(r)
p.sort()

print(sum(p[len(p)-(x+y):]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

ans = 0
while(X > 0 or Y > 0):
    if X > 0:
        red = p.get()
    else:
        red = 0
        
    if Y > 0:
        green = q.get()
    else:
        green = 0
        
    if not r.empty():
        transparent = r.get()
    else:
        transparent = 0
        
    if max(red, green, transparent) == red:
        ans += red
        q.put(green)
        r.put(transparent)
        X -= 1
    elif max(green, transparent) == green:
        ans += green
        p.put(red)
        r.put(transparent)
        Y -= 1
    else:
        if X > 0 and (min(red, green) == red or Y <= 0):
            ans += transparent
            p.put(red)
            q.put(green)
            X -= 1
        elif Y > 0:
            ans += transparent
            p.put(red)
            q.put(green)
            Y -= 1
        else:
            p.put(red)
            q.put(green)
            r.put(transparent)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

ans = 0
while(X > 0 or Y > 0):
    if X > 0:
        red = p.get()
    else:
        red = 0
        
    if Y > 0:
        green = q.get()
    else:
        green = 0
        
    if not r.empty():
        transparent = r.get()
    else:
        transparent = 0
        
    if max(red, green, transparent) == red:
        ans += red
        q.put(green)
        r.put(transparent)
        X -= 1
    elif max(green, transparent) == green:
        ans += green
        p.put(red)
        r.put(transparent)
        Y -= 1
    else:
        if X > 0 and (min(red, green) == red or Y <= 0):
            ans += transparent
            p.put(red)
            q.put(green)
            X -= 1
        elif Y > 0:
            ans += transparent
            p.put(red)
            q.put(green)
            Y -= 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

ans = 0
while(X > 0 or Y > 0):
    if not p.empty() and X > 0:
        red = p.get()
    else:
        red = 0
        
    if not q.empty() and Y > 0:
        green = q.get()
    else:
        green = 0
        
    if not r.empty():
        transparent = r.get()
    else:
        transparent = 0
        
    if X > 0 and max(red, green, transparent) == red:
        ans += red
        q.put(green)
        r.put(transparent)
        X -= 1
    elif Y > 0 and max(green, transparent) == green:
        ans += green
        p.put(red)
        r.put(transparent)
        Y -= 1
    else:
        if X > 0 and min(red, green) == red:
            ans += transparent
            p.put(red)
            q.put(green)
            X -= 1
        elif Y > 0:
            ans += transparent
            p.put(red)
            q.put(green)
            Y -= 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

cnt = 0
while (X > 0 or Y > 0):
    if not r.empty():
        transparent = r.get()
    else:
        transparent = 0
        
    if X > 0:
        if not p.empty():
            red = p.get()
            if red >= transparent:
                r.put(transparent)
                cnt += red
            else:
                p.put(red)
                cnt += transparent
        else:
            cnt += transparent
        X -= 1
    else:
        r.put(transparent)
        
        
    if not r.empty():
        transparent = r.get()
    else:
        transparent = 0       
           
    if Y > 0:
        if not q.empty():
            green = q.get()
            if green >= transparent:
                r.put(transparent)
                cnt += green
            else:
                q.put(green)
                cnt += transparent
        else:
            cnt += transparent
        Y -= 1
    else:
        r.put(transparent)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

cnt = 0
yin = 1
xin = 0
while (X > 0 or Y > 0):
    if yin == 1:
        if not r.empty():
            transparent = r.get()
        else:
            transparent = 0
    xin == 0   
    if X > 0:
        xin == 1
        if not p.empty():
            red = p.get()
            if red > transparent:
                r.put(transparent)
                cnt += red
            else:
                p.put(red)
                cnt += transparent
        else:
            cnt += transparent
        X -= 1
        
    if xin == 1:       
        if not r.empty():
            transparent = r.get()
        else:
            transparent = 0       
    yin == 0        
    if Y > 0:
        yin == 1
        if not q.empty():
            green = q.get()
            if green > transparent:
                r.put(transparent)
                cnt += green
            else:
                q.put(green)
                cnt += transparent
        else:
            cnt += transparent
        Y -= 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import queue

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 = queue.LifoQueue()
q = queue.LifoQueue()
r = queue.LifoQueue()

P.sort()
Q.sort()
R.sort()

for i in range(a):
    p.put(P[i])
    
for i in range(b):
    q.put(Q[i])
    
for i in range(c):
    r.put(R[i])
    

cnt = 0
while (X > 0 or Y > 0):
    if Y > 0:
        if not r.empty():
            transparent = r.get()
        else:
            transparent = 0
        
    if X > 0:
        if not p.empty():
            red = p.get()
            if red > transparent:
                r.put(transparent)
                cnt += red
            else:
                p.put(red)
                cnt += transparent
        else:
            cnt += transparent
        X -= 1
        
    if X > 0:       
        if not r.empty():
            transparent = r.get()
        else:
            transparent = 0       
            
    if Y > 0:
        if not q.empty():
            green = q.get()
            if green > transparent:
                r.put(transparent)
                cnt += green
            else:
                q.put(green)
                cnt += transparent
        else:
            cnt += transparent
        Y -= 1
        
print(cnt)

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)
pi = x - 1
qi = y - 1
ri = 0

while ri < c and (p[pi] < r[ri] or q[qi] < r[ri]):
    if p[pi] >= q[qi]:
        q[qi] = r[ri]
        qi -= 1
    else:
        p[pi] = r[ri]
        pi -= 1
    ri += 1

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort(reverse=True)
    q = list(map(int, input().split()))
    q.sort(reverse=True)
    r = list(map(int, input().split()))
    r.sort(reverse=True)
    r = deque(r)
    target = p[:X] + q[:Y]
    target.sort(reverse=True)
    ans = 0
    i = 0
    while i < X + Y:
        if len(r) == 0:
            ans += target[i]
            i += 1
            continue
        if target[i] >= r[0]:
            ans += target[i]
        else:
            ans += r.popleft()
        i += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
X,Y,A,B,C = map(int, input().split())
#L = [int(input()) for i in range(N)]
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)
p=P[:X]
q=Q[:Y]


ans=0
countp=0
countq=0
countr=0
count=0
r=0
pt=0
qt=0
lR=len(R)
#print(p)
#print(q)
while count<X+Y:
    if countr<lR and r==0:
        r=R[countr]
        countr+=1


    if countp<X and pt==0:
        pt=p[countp]
        countp+=1
    

    if countq<Y and qt==0:
        qt=q[countq]
        countq+=1



    print(pt,qt,r)
    ans+=max(r,pt,qt)
    if r>=pt and r>=qt:
        r=0
    elif pt>=r and pt>=qt:
        pt=0
    else:
        qt=0
    
    count+=1


print(ans)

Submission status: Wrong Answer

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

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

l = p[:x] + q[:y]
l.sort()

i = 0
while l[i] < r[i] and i < len(l) and i < len(r):
    l[i] = r[i]

print(sum(l))