harbor run -t openthoughts/tasktrove-exp-rpt-taco-v2-taco-7336harbor download openthoughts/tasktrove-exp-rpt-taco-v2-taco-7336It’s Chef's birthday, and he and his twin have received ( N ) gifts in total. Each gift ( i ) has a price of ( A[i] ). Both twins aim to keep the most expensive gifts for themselves.
The twins take ( K ) turns alternately, resulting in a total of ( 2 \cdot K ) turns. It is guaranteed that ( 2 \cdot K + 1 \leq N ). In each turn, a person may choose one gift, except for the last turn of the twin who moves second, where they may choose two gifts instead of one.
Assuming both twins choose optimally and that you can choose who takes the first turn, your task is to determine the maximum total cost of the gifts that Chef can keep.
For each test case, output a single line containing the maximum total cost of the gifts that Chef keeps.
3
3 1
1 3 2
3 1
3 1 3
5 2
5 1 3 2 4
3
4
8
Test Case 1: Chef goes first and chooses the gift with cost 3, leaving gifts with costs 1 and 2 for his twin. Total cost for Chef = 3.
Test Case 2: Chef allows his brother to choose first, and he picks the gift with cost 3. Chef then chooses the remaining gift with cost 3 and, since he moves second, he can choose one more gift with cost 1. Total cost for Chef = 3 + 1 = 4.
Test Case 3: Chef chooses first and will end up with gifts priced at 5 and 3. Total cost for Chef = 5 + 3 = 8.
The solution should be implemented in the /app/ directory. Please ensure that it adheres to the outlined constraints and formats.
Important: place your implementation at /app/solution.py so the verifier can run it.