Help
solve this problem!Define the prefix of an array as a sub-array from the beginning of the array up to an index. For example, the prefix of index of the array would be .
Define a prefix query when you take a prefix of the array, , and multiply all the elements in the prefix with . Essentially, this operation flips the signs of the elements.
Given an array of integers, find the maximum sum of the elements you can obtain after performing prefix queries.
Since
knows that there can be many ways to get the maximum sum, he wants to know the indices of the prefix queries. He also wants to have the least amount of queries, sorted in ascending order.Input Specification
The first line will contain the integer , the number of elements of the array, .
The second line will contain integers, the elements of the array, .
Output Specification
On the first line, output a single integer, the maximum sum you can obtain.
On the second line, output the indices (-indexed) of the prefix queries, in ascending order.
If there are multiple possible solutions, output the lexicographically least.
Subtasks
Subtask 1 (30%)
Subtask 2 (70%)
No further constraints.
Sample Input 1
4
-1 2 3 4
Sample Output 1
10
1
Explanation for Sample 1
The maximum sum is , which can be obtained by flipping the signs of the elements up to the first element.
Sample Input 2
5
3 -4 -2 -9 10
Sample Output 2
28
1 4
Explanation for Sample 2
The original array is 3 -4 -2 -9 10
.
The array, after the queries, is
3 -4 -2 -9 10
-3 -4 -2 -9 10
3 4 2 9 10
The maximum sum is .
Comments