Alice can force the final array to have only one element if the number of rounds, is at least . At every round, Alice divides the array in equal (or almost equal for odd size array array) two parts.
Bob’s strategy in this case is to keep the part that have the maximum element in it.
Hence, for , the answer is equal to the maximum element of the array.
Time Complexity:
For , the answer is equal to the maximum element of the array.
Hence we can assume,
Let’s define, = the sum of the elements of the final array if the game is played on for rounds.
Base Case: , for
Transition: for
But this is too slow with time complexity:
We can notice that, for a fixed and , is non-decreasing for increasing .
So, we can binary search for the largest such index that,
.
Then to find , we only have to consider these two values:
and
.
This speeds up the solution to:
Exploiting the monotonicity, it is also possible to get a solution with .
Let's binary search on the answer. Let's fix and check if Alice can force the final array to have sum at most .
If , then Alice must split the array into two parts such that each part has sum
If , then Alice must split the array into two parts such that each part can be further split into two parts with sum .
So, Alice must split the whole array into parts where each part has sum .
Similarly, if the game is played for rounds, Alice must be able to split the whole array into parts where each part has sum .
To find if the whole array can be split into parts each having sum .
we can iterate from left to right and split the array into parts with sum greedily and check if the number of parts is at most .
Time Complexity: