#P3648. [APIO2014] 序列分割
[APIO2014] 序列分割
Description
You are playing a game on a sequence of non-negative integers of length . In this game, you need to split the sequence into non-empty blocks. To obtain blocks, repeat the following operation times:
- Choose a block that has more than one element (initially, you have a single block, i.e., the entire sequence).
- Choose two adjacent elements and split this block between them into two non-empty blocks.
- After each operation, you gain a score equal to the product of the sums of elements in the two newly created blocks. You want to maximize the final total score.
Input Format
The first line contains two integers and . It is guaranteed that .
The second line contains non-negative integers (), representing the sequence described above.
Output Format
On the first line, output the maximum total score you can obtain.
On the second line, output integers between and , indicating the positions where you split between two elements in each operation to maximize the total score. The -th integer means that at the -th operation you split between positions and .
If there are multiple optimal solutions, output any of them.
7 3
4 1 3 4 0 2 3
108
1 3 5
Hint
You can obtain a score of by the following operations:
Initially, you have one block . Split after the 1st element to gain points.
You now have two blocks . Split after the 3rd element to gain points.
You now have three blocks . Split after the 5th element to gain points.
Therefore, after these operations you obtain four blocks and a total score of .
Constraints:
- Subtask 1 (11 points): .
- Subtask 2 (11 points): .
- Subtask 3 (11 points): .
- Subtask 4 (17 points): , .
- Subtask 5 (21 points): , .
- Subtask 6 (29 points): , .
Thanks to @larryzhong for providing strengthened testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号