3432. Smooth Array

单点时限: 4.0 sec

内存限制: 1024 MB

We always hope things in our lives will run smoothly, and having smooth arrays may help. An array $A$ of $N$ non-negative integers is $K_S$-smooth if the sum of every set of $K$ consecutive integers is exactly $S$. Unfortunately, not all arrays are $K_S$-smooth. In fact, all $K_S$-smooth arrays must contain a repeating pattern of length $K$.

Any array can be made $K_S$-smooth by changing its elements. In each change one element may be modified to any integer between $0$ and $S$, inclusive. You want to make all of your arrays smooth, but you don’t want to make any more changes than necessary. So the question is: What is the minimum number of changes you have to make so that a given array would become $K_S$-smooth?

输入格式

The first line of input will consist of three integers of the form:
$N\;\; K\;\; S$
where $N$ is the size of the array.

The remainder of the file will consist of $N$ integers, $a_n\in A$, separated by white space.

All input will be within the following constraints:

  • $1 \le K \le N \le 5000$;
  • $\forall a_n \in A,\; 0 \le a_n \le S \le 5000$.

输出格式

Your program must output a single integer specifying the minimum number of changes that must be made in order to make the array $K_S$ smooth.

样例

Input
3 3 5
1
2
3
Output
1
Input
6 3 5
1
2
3
3
2
1
Output
3
Input
5 1 5
1
2
3
4
5
Output
4

3 人解决,3 人已尝试。

3 份提交通过,共有 30 份提交。

7.9 EMB 奖励。

创建: 7 年前.

修改: 7 年前.

最后提交: 1 年,9 月前.

来源: NCNA 2017

题目标签
DP