問題一覧 > 通常問題

No.2627 Unnatural Pitch

レベル : / AI推定難易度 : 2300 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 24
作問者 : 👑 AngrySadEight / テスター : aplysiaSheep zeta7532
お気に入りにしたユーザー ProblemId : 10496 / 自分の提出
問題文最終更新日: 2024-02-09 23:53:35
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. Back to the original
yukicoder contest 417 (順位表) の他の問題:

Problem Statement

You are given an integer sequence $A=(A_1, A_2, \dots, A_N)$ of length $N$. You may perform each of the following $4$ types of operations on this integer sequence $A$ any number of times, $0$ or more.

  • Operation 1: Increase the value of every element of $A$ by $1$.
  • Operation 2: Decrease the value of every element of $A$ by $1$.
  • Operation 3: Choose one element of $A$ and increase its value by $K$. Performing this operation $1$ time increases the unnaturalness by $1$.
  • Operation 4: Choose one element of $A$ and decrease its value by $K$. Performing this operation $1$ time increases the unnaturalness by $1$.

Initially, the value of the unnaturalness is $0$. Let $A_{min}$ be the minimum value of $A$ and $A_{max}$ be the maximum value of $A$. Your goal is to make $A_{min} \geq L, A_{max} \leq U$. Here, $U-L \geq K$.

Find the minimum value of the unnaturalness when the goal is achieved by performing operations. It can be shown that the goal is always achievable under the constraints.

Constraints

  • All input values are integers.
  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq K \leq 2 \times 10^5$
  • $0 \leq L, U \leq 10^{12}$
  • $U - L \geq K$
  • $0 \leq A_i \leq 10^{12}$

Input

The input is given from Standard Input in the following format.

$N$ $K$ $L$ $U$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Print the answer.

Sample

Sample 1
Input
6 12 7 22
8 12 15 25 15 23
Output
1

The goal can be achieved with unnaturalness $1$ as follows.

  • Perform operation 2. $A = (7, 11, 14, 24, 14, 22)$ results.
  • Perform operation 4. $A = (7, 11, 14, 12, 14, 22)$ results.

The goal cannot be achieved with unnaturalness $0$.

Sample 2
Input
6 12 10 28
15 30 15 30 15 30
Output
0

In some cases, the goal can be achieved with unnaturalness $0$.

Sample 3
Input
5 200000 141421356 173205080
200000000 223606797 244948974 264575131 282842712
Output
302

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