#P7273. ix35 的等差数列

ix35 的等差数列

Background

An arithmetic progression is a sequence in which, starting from the second term, the difference between each term and the previous term is the same constant, and this constant is called the common difference. In particular, a sequence with only one term is also considered an arithmetic progression, and its common difference is regarded as 00.

Problem Description

You are given a positive integer sequence a1,a2,,ana_1, a_2, \ldots, a_n with nn terms, satisfying 1aiw1 \leq a_i \leq w.

You may perform some modifications. In one modification, you can change any term of the sequence to any positive integer w\leq w.

Find the minimum number of modifications needed to turn the original sequence into an arithmetic progression whose common difference is a non-negative integer.

Input Format

The first line contains two integers n,wn, w.
The next line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n.

Output Format

Output one integer on a single line, the required answer.

6 1000
1 2 999 4 72 6
2
10 2
2 1 2 2 1 1 2 2 2 2
3
1 1
1
0

Hint

Sample Explanation #1

Change a3a_3 to 33, and change a5a_5 to 55.


Constraints

This problem uses bundled testdata.

  • Subtask 1 (2020 points): n=2n = 2, w=2w = 2.
  • Subtask 2 (2020 points): n,w100n, w \leq 100.
  • Subtask 3 (1010 points): ai=1a_i = 1.
  • Subtask 4 (2020 points): n,w1000n, w \leq 1000.
  • Subtask 5 (3030 points): no special constraints.

For 100%100\% of the testdata, 1n,w3×1051 \leq n, w \leq 3 \times 10^5.


Original idea: ix35.

Translated by ChatGPT 5