TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
list_of_red = list(map(int, input().split()))
list_of_green = list(map(int, input().split()))
list_of_colorless = list(map(int, input().split()))

list_of_green.sort(reverse=True)
list_of_red.sort(reverse=True)
list_of_colorless.sort(reverse=True)

max_of_red = list_of_red[0:x]
max_of_green = list_of_green[0:y]

ans = sum((max_of_red+max_of_green+list_of_colorless)[:x+y])
print(ans)

x, y, a, b, c = map(int, input().split())
list_of_red = list(map(int, input().split()))
list_of_green = list(map(int, input().split()))
list_of_colorless = list(map(int, input().split()))

list_of_green.sort(reverse=True)
list_of_red.sort(reverse=True)
list_of_colorless.sort(reverse=True)

max_of_red = list_of_red[:x]
max_of_green = list_of_green[:y]

temp = (max_of_red+max_of_green+list_of_colorless)
temp.sort(reverse=True)
ans = sum(temp[:x+y])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
X, Y, A, B, C = map(int,input().split())
P = sorted(list(map(int,input().split())), reverse=True)
Q = sorted(list(map(int,input().split())), reverse=True)
R = sorted(list(map(int,input().split())), reverse=True)
P = P[:X]
Q = Q[:Y]
A = P + Q + R
A.sorted(reverse=True)
ans = sum(A[:X+Y])
print(ans)

X, Y, A, B, C = map(int,input().split())
P = sorted(list(map(int,input().split())), reverse=True)
Q = sorted(list(map(int,input().split())), reverse=True)
R = sorted(list(map(int,input().split())), reverse=True)
P = P[:X]
Q = Q[:Y]
A = P + Q + R
A.sort(reverse=True)
ans = sum(A[:X+Y])
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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()


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()
p = p[len(p)-x:]
q.sort()
q = q[len(q)-y:]
r.extend(q)
r.extend(p)
r.sort()

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x,y,a,b,c=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]
Q=sorted(list(map(int,input().split())))[::-1]
R=sorted(list(map(int,input().split())))[::-1]+[0]*(max(x+y-c,0))
L=sorted(P[:x]+Q[:y])[::-1]
print(L)
print(R)
l=r=0
for i in range(x+y): 
    if r+R[i]<l+L[-i-1]:
        print(sum(L[:x+y-i]+sorted(L[x+y-i:]+R[:i])[::-1][:i]))
        exit()
    r+=R[i]
    l+=L[-i-1]
print(r)

x,y,a,b,c=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]
Q=sorted(list(map(int,input().split())))[::-1]
R=list(map(int,input().split()))
L=sorted(P[:x]+Q[:y]+R)[::-1]
print(sum(L[:x+y]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

from collections import deque

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

def sort(L):
  if len(L)==1:
    return L
  left = sort(L[:len(L)//2])
  right = sort(L[len(L)//2:])
  result = []
  left.append(-1)
  right.append(-1)
  left_index = 0
  right_index = 0
  while len(result)<len(L):
    if left[left_index]>=right[right_index]:
      result.append(left[left_index])
      left_index += 1
    else:
      result.append(right[right_index])
      right_index += 1
  return result

P = sort(P)[:X]
Q = sort(Q)[:Y]
R = sort(R)

P_index = X-1
Q_index = Y-1
R_index = 0

# -*- coding: utf-8 -*-

from collections import deque

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

print(sum(R)

# -*- coding: utf-8 -*-
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(P+Q+list(map(int, input().split())), reverse=True)[:X+Y]
print(sum(R))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

X, Y, A, B, C = i_l()
p = i_l()
q = i_l()
r = i_l()

p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

p_i = 0
q_i = 0
r_i = 0

ans1 = 0
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans1 += p[p_i]
        p_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1
    print(ans1)
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans1 += q[q_i]
        q_i += 1
    else:
        ans1 += r[r_i]
        r_i += 1


ans2 = 0
p_i = 0
q_i = 0
r_i = 0
for i in range(Y):
    if r_i > C-1 or q[q_i] > r[r_i]:
        ans2 += q[q_i]
        q_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1
for i in range(X):
    if r_i > C-1 or p[p_i] > r[r_i]:
        ans2 += p[p_i]
        p_i += 1
    else:
        ans2 += r[r_i]
        r_i += 1

ans3 = 0
if X + Y <= C:
    ans3 = sum(r[:(X+Y)])

print(max(ans1, ans2, ans3))

import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

X, Y, A, B, C = i_l()
p = i_l()
q = i_l()
r = i_l()

p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
r = sorted(r, reverse=True)

p = p[:X]
q = q[:Y]
arr = sorted((p + q + r), reverse=True)

print(sum(arr[:(X+Y)]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x,y,a,b,c=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
white=sorted(list(map(int,input().split())),reverse=True)
eat_list=sorted(red[:x]+green[:y])
for i in range(min(len(eat_list),len(white))):
  if eat_list[i]<white[i]:
    eat_list[i]=white[i]
  else:
    break
print(eat_list)
print(sum(eat_list))

x,y,a,b,c=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
white=sorted(list(map(int,input().split())),reverse=True)
eat_list=sorted(red[:x]+green[:y])
for i in range(min(len(eat_list),len(white))):
  if eat_list[i]<white[i]:
    eat_list[i]=white[i]
  else:
    break
print(sum(eat_list))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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 = p.sort(reverse=True)
q = q.sort(reverse=True)
r = r.sort(reverse=True)
p = p[:X]
q = q[:Y]
sumlist = list()
sumlist.extend(p)
sumlist.extend(q)
sumlist.extend(r)
sumlist = sumlist.sort(reverse=True)
print(sum(sumlist[:X+Y]))

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 = p[:X]
q = q[:Y]
sumlist = list()
sumlist.extend(p)
sumlist.extend(q)
sumlist.extend(r)
sumlist.sort(reverse=True)
print(sum(sumlist[:X+Y]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, Y, A, B, C = (int(x) for x in input().split())
R = [int(i) for i in input().split()]
G = [int(i) for i in input().split()]
M = [int(i) for i in input().split()]

print(R, G, M)

R.sort(reverse=True)
G.sort(reverse=True)

for i in range(X):
  M.append(R[i])

for i in range(Y):
  M.append(G[i])

M.sort(reverse=True)

ans = 0
for i in range(X + Y):
  ans = M[i] + ans

print(ans)


X, Y, A, B, C = (int(x) for x in input().split())
R = [int(i) for i in input().split()]
G = [int(i) for i in input().split()]
M = [int(i) for i in input().split()]

R.sort(reverse=True)
G.sort(reverse=True)

for i in range(X):
  M.append(R[i])

for i in range(Y):
  M.append(G[i])

M.sort(reverse=True)

ans = 0
for i in range(X + Y):
  ans = M[i] + ans

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
print(nl)
x, y, a, b, c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
print(p)
print(q)
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(c):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))


import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
x, y, a, b, c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(c):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
ans = 0
for i in range(a):
    if len(p) > 0 and len(r) > 0:
        if p[-1] >= r[-1]:
            ans += p[-1]
            p.pop()
        else:
            ans += r[-1]
            r.pop()
    else:
        if len(p) == 0:
            ans += r[-1]
        else:
            ans += p[-1]
            
for i in range(b):
    if len(q) > 0 and len(r) > 0:
        if q[-1] >= r[-1]:
            ans += q[-1]
            q.pop()
        else:
            ans += r[-1]
            r.pop()
    else:
        if len(q) == 0:
            ans += r[-1]
        else:
            ans += q[-1]

print(ans)


x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
ans = p[-x:] + q[-y:] + r
ans.sort()
n = len(ans)
cnt = 0
for i in range(x+y):
    cnt += ans[n-1-i]
print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(100000)
class fact():
    def __init__(self, i, mod):
        self.l = [1] * (i+1)
        for i in range(1, i+1):
            self.l[i] = self.l[i-1] * i
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 2 * (10 ** 5) + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)


def main():
    N = int(input())
    d = {}
    mod = 10**9 + 7
    f = fact(N, mod)
    for i in range(N-1):
        a, b = map(int, input().split())
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
    for i in range(1, N+1):
        v = set()
        r, t = solve(i, N, v, f, d)
        print(r % mod)
def solve(n, a, v, f, d):
    v.add(n)
    x = 0
    unv = []
    for i in d[n]:
        if i not in v:
            x += 1
            unv.append(i)
    if x == 1:
        r, t = solve(unv[0], a-1, v, f, d)
        return r, t + 1
    if x == 0:
        return 1, 1
    t = 1
    r = 1
    for i in unv:
        rr, tt = solve(i, a-1, v, f, d)
        t += tt
        r *= rr
        r *= f.g2[tt]
    r *= f.l[t-1]
    return r, t
main()


import heapq
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)
    h = []
    for i in p[:X]:
        heapq.heappush(h, (i, 'r'))
    for i in q[:Y]:
        heapq.heappush(h, (i, 'g'))
    a = sum(p[:X]) + sum(q[:Y])
    ra = 0
    ga = 0
    i = 0
    while h:
        t = heapq.heappop(h)
        if r[i] < t[0]:
            break
        if t[1] == 'r' and ra <= X:
            a += r[i]
            a -= t[0]
            ra += 1
            i += 1
        elif t[1] == 'g' and ga <= Y:
            ga += 1
            a += r[i]
            a -= t[0]
            i += 1
        if ra == X and ga == Y:
            break
        if i >= C:
            break
    return a
print(main())


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
x,y,a,b,c=map(int,input().split())
p=[0]+sorted(list(map(int,input().split())))[a-x:]
q=[0]+sorted(list(map(int,input().split())))[b-y:]
r=[0]+sorted(list(map(int,input().split())))
pi=-1
qi=-1
ri=-1
gs=0
rs=0
ws=0
s=0              
while gs+rs+ws!=x+y:
    print(r[ri],p[pi],q[qi])
    if r[ri]>=q[qi]>=p[pi]:
        s += r[ri]
        ws+=1
        ri-=1

    elif r[ri]>=p[pi]>=q[qi]:
        s += r[ri]
        ws += 1
        ri -= 1

    elif q[qi]>=r[ri]>=p[pi]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif q[qi]>=p[pi]>=r[ri]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif p[pi]>=r[ri]>=q[qi]:
        s += p[pi]
        rs += 1
        pi -= 1

    elif p[pi]>=q[qi]>=r[ri]:
        s += p[pi]
        rs += 1
        pi -= 1

print(s)


x,y,a,b,c=map(int,input().split())
p=[0]+sorted(list(map(int,input().split())))[a-x:]
q=[0]+sorted(list(map(int,input().split())))[b-y:]
r=[0]+sorted(list(map(int,input().split())))
pi=-1
qi=-1
ri=-1
gs=0
rs=0
ws=0
s=0              
while gs+rs+ws!=x+y:
    if r[ri]>=q[qi]>=p[pi]:
        s += r[ri]
        ws+=1
        ri-=1

    elif r[ri]>=p[pi]>=q[qi]:
        s += r[ri]
        ws += 1
        ri -= 1

    elif q[qi]>=r[ri]>=p[pi]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif q[qi]>=p[pi]>=r[ri]:
        s += q[qi]
        gs += 1
        qi -= 1

    elif p[pi]>=r[ri]>=q[qi]:
        s += p[pi]
        rs += 1
        pi -= 1

    elif p[pi]>=q[qi]>=r[ri]:
        s += p[pi]
        rs += 1
        pi -= 1

print(s)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
xyabc = list(map(int,input().rsplit()))
p = list(map(int,input().rsplit()))
q = list(map(int,input().rsplit()))
r = list(map(int,input().rsplit()))
x = xyabc[0]
y = xyabc[1]
p.sort()
q.sort()

z =p[:x]+q[:y]
z = z + r
z.sort()
print(sum(z[:x+y]))


xyabc = list(map(int,input().rsplit()))
p = list(map(int,input().rsplit()))
q = list(map(int,input().rsplit()))
r = list(map(int,input().rsplit()))
x = xyabc[0]
y = xyabc[1]
p.sort(reverse=True)
q.sort(reverse=True)

z =p[:x]+q[:y]
z = z + r
z.sort(reverse=True)
print(sum(z[:x+y]))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque

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)
xlis = deque(p[len(p)-x:])
ylis = deque(q[len(q)-y:])
r = deque(r)
while True:
    xs = xlis.popleft()
    ys = ylis.popleft()
    rm = r.popleft()
    if rm < xs and rm < ys:
        xlis.append(xs)
        ylis.append(ys)
        break
    if xs < ys and xs < rm:
        xlis.append(rm)
        ylis.append(ys)
    elif ys < xs and ys < rm:
        ylis.append(rm)
        xlis.append(xs) 
print(sum(xlis)+sum(ylis))

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 = list(map(int, input().split()))

a = sorted(P[:X] + Q[:Y] + R, reverse  = True)
print(sum(a[:(X+Y)]))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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()))

red = sorted(p, reverse=True)[:X]
green = sorted(q, reverse=True)[:Y]
white = sorted(r, reverse=True)

original = sorted(red + green)
while original[0] < white[0]:
  original[0] = white[0]
  white.pop(0)
  original.sort()
  
print(sum(original))


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

red = sorted(p, reverse=True)[:X-1]
green = sorted(q, reverse=True)[:Y-1]
white = sorted(r, reverse=True)

original = sorted(red + green)
while original[0] < white[0]:
  original[0] = white[0]
  white.pop(0)
  original.sort()
  
print(sum(original))

from collections import deque
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 = sorted(r, reverse=True)

ans_p = deque(p[:X])
ans_q = deque(q[:Y])
ans_r = deque(r)

while (ans_p[-1]<ans_r[0]) or (ans_q[-1]<ans_r[0]):
  if ans_p[-1] <= ans_q[-1]:
    ans_p.pop()
    ans_p.appendleft(ans_r[0])
    ans_r.popleft()
  else:
    ans_q.pop()
    ans_q.appendleft(ans_r[0])
    ans_r.popleft()
  if not ans_r:
    break;
    
ans = sum(ans_p) + sum(ans_q)
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + r)[-x-y:]))

(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list ,reverse=True)[:X+Y]
  print(sum(sum_list))

def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  j = 0
  sum_list = sorted(aka_list + midori_list)
  for i in range(len(sum_list)):
    if sum_list[i] < mu_list[j]:
      sum_list[i] = mu_list[j]
      j += 1
  print(sum(sum_list))
  
main()

スコード 

Copy
Copy
def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list)[:X+Y]
  print(sum(sum_list))
  

def main():
  X, Y, A, B, C  = map(int, input().split())
  aka_list = sorted([int(t) for t in input().split()],reverse=True)[:X]
  midori_list = sorted([int(t) for t in input().split()],reverse=True)[:Y]
  mu_list = sorted([int(t) for t in input().split()],reverse=True)
  
  sum_list = sorted(aka_list + midori_list + mu_list ,reverse=True)[:X+Y]
  print(sum(sum_list))

main()

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X, Y, A, B, C = map(int, input().split())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
nc = list(map(int, input().split()))

r.sort(reverse=True)
g.sort(reverse=True)
nc.sort(reverse=True)

selected = r[:X] + g[:Y]
selected.sort()

for i in range(X+Y):
  if selected[i] < nc[i]:
    selected[i] = nc[i]
    
print(sum(selected))

X, Y, A, B, C = map(int, input().split())
r = list(map(int, input().split()))
g = list(map(int, input().split()))
nc = list(map(int, input().split()))

r.sort(reverse=True)
g.sort(reverse=True)
nc.sort(reverse=True)

selected = r[:X] + g[:Y]
selected.sort()

if len(selected) > len(nc) or len(selected) == len(nc):
  L = len(nc)
else:
  L = len(selected)

for i in range(L):
  if selected[i] < nc[i]:
    selected[i] = nc[i]
    
print(sum(selected))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
P_=P[A-X:]
Q_=Q[B-Y:]
while P_[0]<R[-1] or Q_[0]<R[-1]:
    if P_[0]<Q_[0]:
        P_.pop(0)
        P_.append(R.pop(-1))
    else:
        Q_.pop(0)
        Q_.append(R.pop(-1))
print(sum(P_)+sum(Q_))

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
S=sorted(P[A-X:]+Q[B-Y:])
ans=sum(S)
for i in range(min(R,S)):
    if S[i]<R[-1-i]:
        S[i]=R[-1-i]
    else:
        break
print(sum(S))

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
S=sorted(P[A-X:]+Q[B-Y:])
i=0
while S[i]<R[-1-i]:
    if len(R)>i or len(S)>i:
        break
    i+=1
print(sum(S[i+1:])+R[-1-i:])

X,Y,A,B,C=map(int,input().split())
P=sorted(list(map(int,input().split())))
Q=sorted(list(map(int,input().split())))
R=sorted(list(map(int,input().split())))
S=sorted(P[A-X:]+Q[B-Y:])
i=0
while S[i]<R[-1-i]:
    if len(R)>i or len(S)>i:
        break
    i+=1
if i==0:
    R=[]
print(sum(S[i:])+sum(R[-i:]))

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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.append(x_b)
x_a.append(s_c)
x_a.sort(reverse = True)
ans = x_a[0:x+y]
print(sum(ans))

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]


sum_a = x_a + x_b + s_c
sum_a.sort(reverse = True)

print(sum(sum_a))

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)

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

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]


sum_a = x_a + x_b + s_c
sum_a.sort(reverse = True)
sum_a = sum_a[0:x+y]
print(sum(sum_a))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
2 2 2 2 2
8 6
9 1
2 1

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

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

P_new = P[-X::]
Q_new = Q[-Y::]


agg = P_new + Q_new +R
agg.sort()
print(sum(agg[-X-Y::]))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

print(p, q, r)
pi, qi, ri = X-1, Y-1, 0
tp, tq, tr = p[pi], q[qi], r[ri]
ans = 0
while pi >= 0 or qi >= 0:
    if tp >= tr and  tq >= tr:
        break
    elif tp < tr and tq < tr:
        if tp < tq:
            p[pi] = r[ri]
            pi -= 1
            ri += 1
        else:
            q[qi] = r[ri]
            qi -= 1
            ri += 1
    elif tp < tr or tq < tr:
        if tp < tr:
            p[pi] = r[ri]
            ri += 1
            pi -= 1
            tp = p[pi]
        else:
            q[qi] = r[ri]
            ri += 1
            qi -= 1
            tq = q[qi]
    else:
        break

print(sum(p)+sum(q))

import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q))
pq.sort()
ri = 0
for i, t in enumerate(pq):
    if t < r[ri]:
        pq[i] = r[ri]
        ri += 1
print(sum(pq))

import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q, r))
pq.sort()
print(sum(pq[-(X+Y):]))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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**9+1)
q.append(10**9+1)
r.append(10**9+1)
result = sum(p+q)-2*(10**4)
ii, jj = x+y, c
for i in range(c):
    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
    if c<0:
        break
print(result)

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)
rr = [0]
for i in r:
    rr.append(rr[-1]+i)
p = p[:x]
q = q[:y]
pq = sorted(p+q)
ppqq = [sum(pq)]
for i in pq:
    ppqq.append(ppqq[-1]-i)
result = []
for i in range(min(x+y, c+1)):
    result.append(ppqq[i]+rr[i])
print(max(result))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()))
ps=sorted(p,reverse=True)
qs=sorted(q,reverse=True)
rs=sorted(r,reverse=True)
pn=ps[:x]
qn=qs[:y]
mp=pn[-1]
mq=qn[-1]
s=0
t=0
for i in range(max(x,y)):
  if mp>rs[i] and mq>rs[i]:
    break
  elif mp<=mq<=rs[i]:
    s+=1
    pn.pop(-s)
    pn.append(rs[i])
    if pn[-s-1]<rs[i]:
      mp=pn[-s-1]
    else:
      mp=rs[i]
      s=s-1
  elif mq<mp<=rs[i]:
    t+=1
    qn.pop(-t)
    qn.append(rs[i])
    if qn[-t-1]<rs[i]:
      mq=qn[-t-1]
    else:
      mq=rs[i]
      t=t-1
print(sum(pn)+sum(qn))

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()))
ps=sorted(p,reverse=True)
qs=sorted(q,reverse=True)
pn=ps[:x]
qn=qs[:y]
nl=sorted(pn+qn+r,reverse=True)
print(sum(nl[:x+y]))


Verdicts: Runtime Error

Accepted
Problem: 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.

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

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

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(lambda x:int(x)*(-1),input().split()))
from heapq import *

heapify(lst_r)
for i in range(a-x):
    _ = heappop(lst_r)

heapify(lst_g)
for i in range(b-y):
    _ = heappop(lst_g)
    
heapify(lst_n)

flg = lst_r > lst_g


while len(lst_n)>=0:
    cur = -1 * heappop(lst_n)
    if flg and cur > lst_g[0]:
        _ = heappushpop(lst_g,cur)
        flg = lst_r > lst_g
    elif (not flg) and cur > lst_r[0]:
        _ = heappushpop(lst_r,cur)
        flg = lst_r > lst_g
    else:
        break
print(sum(lst_g)+sum(lst_r))

x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(lambda x:int(x)*(-1),input().split()))
from heapq import *

heapify(lst_r)
for i in range(a-x):
    _ = heappop(lst_r)

heapify(lst_g)
for i in range(b-y):
    _ = heappop(lst_g)
    
heapify(lst_n)

flg = lst_r > lst_g

cur = -1 * heappop(lst_n)
while len(lst_n)>0:
    if flg and cur > lst_g[0]:
        _ = heappushpop(lst_g,cur)
    elif (not flg) and cur > lst_r[0]:
        _ = heappushpop(lst_r,cur)
    else:
        break
print(sum(lst_g)+sum(lst_r))

x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(int,input().split()))
lst_r = sorted(lst_r, ascending=False)[:x]
lst_g = sorted(lst_g, ascending=False)[:y]
lst_all = sorted(lst_r + lst_g + lst_n, ascending=False)[:x+y]
print(sum(lst_all))

x,y,a,b,c = map(int,input().split())
lst_r = list(map(int,input().split()))
lst_g = list(map(int,input().split()))
lst_n = list(map(int,input().split()))
lst_r = sorted(lst_r, reverse=True)[:x]
lst_g = sorted(lst_g, reverse=True)[:y]
lst_all = sorted(lst_r + lst_g + lst_n, reverse=True)[:x+y]
print(sum(lst_all))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted