Daft Trunk
Daft Trunk, the fab elephant DJ duo hailing from France, are producing their new album Random Access Mammoths. To get their signature trumpet sound, they rely on a synthesiser that outputs a sawtooth wave.
In synthesiser sound design, a sawtooth wave is represented by an array of integers denoting pitch values. To build up musical energy, a valid sawtooth wave's pitch increases sequentially (or stays flat), then drops sharply to start the next beat.
It is impossible for a sawtooth wave to drop in pitch, and then immediately drop again on the very next step. Formally, an array is a valid sawtooth wave if there is no index
such that
.
Daft Trunk has discovered the art of sampling and found a rough audio sample consisting of integers. In their mixing software, they have the ability to replace any pitch with any integer (even negative ones).
What is the absolute minimum number of replacements needed to make the audio sample a valid sawtooth wave? (If it is already a valid sawtooth wave, output 0).
Input
The first line contains a single integer
, the size of the audio sample.
The second line contains integers
, the recorded pitch values.
Output
Output a single integer, the minimum number of replacements required to make the sample a valid sawtooth wave.
Example
Input 1
6
1 2 3 1 2 3
Output 1
0
The sample is already a valid sawtooth wave. The only drop occurs at , so there are no two consecutive drops. Therefore,
replacements are needed.
Input 2
5
5 4 3 2 1
Output 2
2
The pitch drops continuously. We can replace the with a
, and the
with a
, making the array
5 6 3 4 1. The drops are now and
, which are completely separated by rises. This took
replacements.
Input 3
6
4 3 2 4 3 2
Output 3
2
Input 4
4
10 10 10 10
Output 4
0
Comments
sybau x3
sybau
sybau
hello ❤️️️❤️️️❤️️️❤️️️❤️️️❤️️️❤️️️️️