#P3648. [APIO2014] 序列分割

    ID: 1431 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2014APIOSpecial Judge枚举,暴力斜率优化前缀和

[APIO2014] 序列分割

Description

You are playing a game on a sequence of non-negative integers of length nn. In this game, you need to split the sequence into k+1k + 1 non-empty blocks. To obtain k+1k + 1 blocks, repeat the following operation kk 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 nn and kk. It is guaranteed that k+1nk + 1 \leq n.

The second line contains nn non-negative integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai1040 \leq a_i \leq 10^4), representing the sequence described above.

Output Format

On the first line, output the maximum total score you can obtain.

On the second line, output kk integers between 11 and n1n - 1, indicating the positions where you split between two elements in each operation to maximize the total score. The ii-th integer sis_i means that at the ii-th operation you split between positions sis_i and si+1s_i + 1.

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 108108 by the following operations:

Initially, you have one block (4,1,3,4,0,2,3)(4, 1, 3, 4, 0, 2, 3). Split after the 1st element to gain 4×(1+3+4+0+2+3)=524 \times (1 + 3 + 4 + 0 + 2 + 3) = 52 points.

You now have two blocks (4),(1,3,4,0,2,3)(4), (1, 3, 4, 0, 2, 3). Split after the 3rd element to gain (1+3)×(4+0+2+3)=36(1 + 3) \times (4 + 0 + 2 + 3) = 36 points.

You now have three blocks (4),(1,3),(4,0,2,3)(4), (1, 3), (4, 0, 2, 3). Split after the 5th element to gain (4+0)×(2+3)=20(4 + 0) \times (2 + 3) = 20 points.

Therefore, after these operations you obtain four blocks (4),(1,3),(4,0),(2,3)(4), (1, 3), (4, 0), (2, 3) and a total score of 52+36+20=10852 + 36 + 20 = 108.

Constraints:

  • Subtask 1 (11 points): 1k<n101 \leq k < n \leq 10.
  • Subtask 2 (11 points): 1k<n501 \leq k < n \leq 50.
  • Subtask 3 (11 points): 1k<n2001 \leq k < n \leq 200.
  • Subtask 4 (17 points): 2n10002 \leq n \leq 1000, 1kmin{n1,200}1 \leq k \leq \min\{n - 1, 200\}.
  • Subtask 5 (21 points): 2n100002 \leq n \leq 10000, 1kmin{n1,200}1 \leq k \leq \min\{n - 1, 200\}.
  • Subtask 6 (29 points): 2n1000002 \leq n \leq 100000, 1kmin{n1,200}1 \leq k \leq \min\{n - 1, 200\}.

Thanks to @larryzhong for providing strengthened testdata.

Translated by ChatGPT 5