luogu#P7959. [COCI 2014/2015 #6] WTF
[COCI 2014/2015 #6] WTF
Problem Description
You are given an array of length , an array of length with value range , and an integer .
We apply a Warshall-Turing-Fourier transform to array using the following pseudocode:
sum = 0
for i = 1 to n
index = min{ID[i], ID[i+1]}
sum = sum + A[index]
Rorate(A, r)
Change(A)
for i = 1 to n
index = max{ID[i], ID[i+1]}
index = index + 1
sum = sum + A[index]
Rorate(A, r)
Where:
- means changing every element in array to its opposite number.
- means copying array twice to obtain array , and replacing with .
That is, rotate right by positions.
You already know array and integer , but you do not know array .
You need to find the maximum possible value of in the pseudocode after the WTF transform.
: It does not actually exist. Of course, it can also be called the "Sept transform".
Input Format
The first line contains two integers .
The next line contains integers, representing array .
Output Format
The first line contains one integer, the maximum possible value of in the pseudocode.
The second line contains integers, the array that makes as large as possible.
If there are multiple solutions, output any one of them.
5 3
1 -1 1 -1 1
10
1 1 1 2 2 3
6 5
2 5 4 1 3 5
16
3 2 1 1 5 4 1
Hint
Scoring
If only the first line of your output is correct, you can get of the score.
But you must ensure that the second line has numbers that satisfy the requirements.
Constraints
This problem uses Special Judge.
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
You must ensure that your constructed .
Notes
According to the original problem settings, the full score is 160 points.
Translated from COCI 2014-2015 Contest #6 Task F WTF.
Translated by ChatGPT 5