#P8476. 「GLR-R3」惊蛰
「GLR-R3」惊蛰
Background
"A light rain makes all flowers fresh; with one thunder, Jingzhe begins."
At noon, in the lounge, on Ayang's shoulder.
"I have a wish: to take part in the National Music Festival, win an award, and together with Ayang, break free from this bitter sea of training."
"Coming for love, working hard to get away... is that so?"
The midday sunlight seeps through the curtains and gently touches the sleepy person's cheeks. Tianyi's left hand quietly rests on the guitar in Ayang's arms,
"Zheng—"
The hibernating insects are awakened by the thunder, and no one promises them that the rain will come.
Jingzhe "I am willing to grind the years into a looking glass and search all across this starry sky, focusing the faint light into my palm and holding it tight without letting go."
Problem Description
The contest is getting close, and various tests have become more frequent. As the professional analyst for Tianyi and the others, your job is to do statistics and analysis of the team members' performance. In short, a certain leader is coming to visit, so you are required to revise a pleasing-looking analysis report.
In the existing tests, for a particular player, their fluctuation value in the -th test is a non-negative integer . A smaller fluctuation value means the player's mentality and performance are more stable, so you need to "slightly adjust" the fluctuation sequence into another non-negative integer sequence . However, you cannot be too dishonest, yet the report must look good, so must satisfy:
- is monotone non-increasing, because the player is getting better and better;
- For each , if , the teacher will be unhappy, so you need to spend units of energy to persuade the teacher (where is a given constant);
- For each , if , the player will be unhappy, possibly very unhappy, so you need to spend units of energy to comfort the player.
You want, under these conditions, to minimize the total energy spent. As an experienced competitive programming contestant, you should compute this minimum value yourself.
Formal statement
Given a non-negative integer sequence , define the function as
$$f(x,y)=\begin{cases} x-y,&x\ge y\\ C,&x< y \end{cases},$$where is a given constant. Construct a non-increasing non-negative integer sequence to minimize
You only need to output this minimum value.
Input Format
The first line contains two integers, the sequence length and the given constant .
The next line contains the sequence .
Output Format
Output one line with one integer, the minimum value.
3 3
4 5 2
1
10 5
12 17 20 2 0 1 13 6 10 1
26
Hint
Sample #1 Explanation
Construct . Then:
$$\begin{aligned} \sum_{i=1}^nf(b_i,a_i) &= f(5,4)+f(5,5)+f(2,2)\\ &= 1+0+0\\ &= 1. \end{aligned}$$Sample #2 Explanation
Construct , and you can obtain the answer.
Constraints
This problem uses Subtask scoring.
Let be the value range of the elements in and the constant .
For of the data, , .
For different subtasks, the constraints are as follows:
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| A | ||||
| B | ||||
| None | ||||
- Special Property A: For the constant , .
- Special Property B: For the sequence , the elements are monotone increasing.
Translated by ChatGPT 5