You are given an integer array of length . Your task is to find the optimal split point in the array such that the sum of the subarray to the left of the split point is as close as possible to the sum of the subarray to the right, without including the element indexed at the split point. You are allowed to move one element from the left subarray to the right or vice versa to achieve a better balance.
Input Specification
The first line contains an integer , representing the length of the array.
The second line contains space-separated integers, , representing the elements of the array.
The following table shows how the available marks are distributed.
Marks Awarded | ||
---|---|---|
marks | ||
marks | ||
marks |
Output Specification
Output the index of the optimal split point and the index of the element that you moved between two subarrays separated by space. If you did not move any element between two subarrays, output -1
for the second number. If multiple solutions exist, output the lexicographically smallest one. The index of the optimal split point takes precedence, and -1
is given higher priority than the index of the moved element.
Sample Input
7
1 2 1 3 3 2 1
Sample Output
3 4
Explanation for Sample
By splitting at index , we obtain the arrays of and . By moving the element from the right array to the left array, we obtain arrays of and . The sum of both arrays is , meaning 3 4
is the most optimal split and move point. It can be shown that this is the lexicographically smallest solution.
Comments