Assume you are given an array
We are doing a Warshall-Turing-Fourier transformation (this doesn't really exist) on array
sum = 0
for i = 1 to N
index = min{ ID[i], ID[i+1] }
sum = sum + A[index]
rotate array A to the right by R places
change the signs of all elements in A
for i = 1 to N
index = max{ ID[i], ID[i+1] }
index = index + 1
sum = sum + A[index]
rotate array A to the right by R places
You are given the array sum
after execution of the above algorithm?
Input
The first line of input contains the integers
The second line of input contains the elements of array
Output
The first line of output must contain the maximal value of sum
.
The second line of output must contain the array
If only the first line is correct (regardless of whether the second is printed), you will get
Scoring
In test cases worth
In test cases worth
Sample Input 1
5 3
1 -1 1 -1 1
Sample Output 1
10
1 1 1 2 2 3
Sample Input 2
6 5
2 5 4 1 3 5
Sample Output 2
16
3 2 1 1 5 4 1
Comments