#P8476. Fluctuation Value Adjustment
Fluctuation Value Adjustment
Fluctuation Value Adjustment
You are given a sequence of non‐negative integers \(a_1, a_2, \dots, a_n\) denoting the fluctuation values of a contestant in \(n\) tests. A lower fluctuation value means the contestant performed more stably. To prepare an attractive performance analysis report, you are allowed to adjust the sequence \(\{a_i\}\) into another non‐negative integer sequence \(\{b_i\}\) such that:
- The sequence \(\{b_i\}\) is nonincreasing (i.e. \(b_1 \ge b_2 \ge \cdots \ge b_n\)).
- For every \(i\): if \(b_i < a_i\), then the teacher gets unhappy and you need to spend a constant cost \(C\).
- For every \(i\): if \(b_i \ge a_i\), then the contestant gets upset and you must spend \(b_i - a_i\) units to calm him down.
Formally, define the cost function for each test as \[ f(b_i,a_i)=\begin{cases} b_i - a_i, & \text{if } b_i\ge a_i,\\ C, & \text{if } b_i < a_i. \end{cases} \] Your task is to choose a nonincreasing sequence \(\{b_i\}\) (with each \(b_i\) a nonnegative integer) so that the total cost \[ \sum_{i=1}^n f(b_i,a_i) \] is minimized. Output the minimum total cost.
inputFormat
The first line contains two integers \(n\) and \(C\) (the number of tests and the teacher penalty constant). The second line contains \(n\) nonnegative integers \(a_1, a_2, \dots, a_n\) separated by spaces.
outputFormat
Output a single integer — the minimum total cost achievable under the constraints.
sample
3 5
3 1 2
2
</p>