問題一覧 > 通常問題

No.1117 数列分割

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 256 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 63
作問者 : first_vil / テスター : shinchan
お気に入りにしたユーザー ProblemId : 4450 / 自分の提出
問題文最終更新日: 2022-05-15 16:12:01
Sequence Partition
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 257 (順位表) の他の問題:

Note

This problem has a strict execution time limit, so we recommend using a fast language. (It has been confirmed that the writer's solution gets TLE in Python3 and AC in PyPy3.)

Problem Statement

There is a sequence $A$ of length $N$. Consider partitioning this sequence into $K$ contiguous subarrays $B_1,B_2,\dots,B_K$ so that the following conditions are satisfied.

  • Each of $B_1,B_2,\dots,B_K$ is a non-empty contiguous subarray of $A$ of length at most $M$.
  • Concatenating $B_1,B_2,\dots,B_K$ in this order yields $A$.

The score of a partition is defined as $\displaystyle \sum_{i=1}^{K}|\sum_{j=1}^{L_i}B_{i,j}|$, where $L_i$ is the length of $B_i$.

Find the maximum score.

Input

$N\ K\ M$
$A_1\ A_2\ \dots\ A_N$

  • All input values are integers.
  • $1 \le N \le 3000$
  • $1 \le K,M \le N$
  • $N \le M \times K$
  • $|A_i| \le 10^9$

Output

Output the maximum score, followed by a newline.

Sample

Sample 1
Input
5 2 4
-7 -7 17 3 -20
Output
26

For example, if the sequence is partitioned as $(-7,-7),(17,3,-20)$, the score is $|-7-7|+|17+3-20|=|-14|+|0|=14+0=14$.

Here, the partition $(-7,-7,17,3),(-20)$ is optimal, and the maximum score is $26$.

Sample 2
Input
3 2 2
-6 -15 13
Output
34
Sample 3
Input
9 5 3
17 11 9 -10 -20 5 19 -3 -3
Output
97

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。