I want to be able to solve the green diff, so I will solve the green diff that seems to be solvable.
Red apples eat up to $ X $ and green apples eat up to $ Y $, so you only eat $ X, Y $ before you sort $ p, q $ in descending order. .. Colorless apples can be in both colors, so connect $ p [: X], q [: Y], r $ and arrange them in descending order. The answer is the sum from the front of the concatenated list to $ X + Y $. Also, the sort for Python list is $ O (N log N) $, so it's tolerable.
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)
p = p[:x]
q = q[:y]
apple = p + q + r
apple.sort(reverse=True)
ans = sum(apple[:x+y])
print(ans)
I want to be green. see you.
Recommended Posts