luogu#P7959. [COCI 2014/2015 #6] WTF

    ID: 7286 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2014Special JudgeCOCI(克罗地亚)

[COCI 2014/2015 #6] WTF

Problem Description

You are given an array A\textbf A of length nn, an array ID\textbf{ID} of length n+1n+1 with value range [1,n1][1,n-1], and an integer rr.

We apply a Warshall-Turing-Fourier transform [1]^\textsf{[1]} to array A\textbf A 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:

  • Change(A)\texttt{Change}(\textbf A) means changing every element in array A\textbf A to its opposite number.
  • Rorate(A,r)\texttt{Rorate}(\textbf A, r) means copying array A\textbf A twice to obtain array B\textbf B, and replacing A\textbf A with B[nr+1,2nr]\textbf B[n-r+1,2n-r].
    That is, rotate right by rr positions.

You already know array A\textbf A and integer rr, but you do not know array ID\textbf{ID}.

You need to find the maximum possible value of sum\text{sum} in the pseudocode after the WTF transform.

[1]\textsf{[1]}: It does not actually exist. Of course, it can also be called the "Sept transform".

Input Format

The first line contains two integers n,rn, r.

The next line contains nn integers, representing array A\textbf A.

Output Format

The first line contains one integer, the maximum possible value of sum\text{sum} in the pseudocode.

The second line contains n+1n+1 integers, the array ID\textbf{ID} that makes sum\text{sum} 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 50%50\% of the score.

But you must ensure that the second line has n+1\bm{n+1} numbers that satisfy the requirements.

Constraints

This problem uses Special Judge.

  • For 20%20\% of the testdata, n7n \le 7.
  • For 60%60\% of the testdata, n300n \le 300.
  • For 100%100\% of the testdata, 2n3×1032 \le n \le 3 \times 10^3, 1rn1 \le r \le n, A[i][104,104]\textbf A[i] \in [-10^4, 10^4].

You must ensure that your constructed ID[i][1,n1]\textbf{ID}[i] \in [1,n-1].

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