#P9253. [PA 2022] Ornitolog 2
[PA 2022] Ornitolog 2
Problem Description
This problem is translated from PA 2022 Round 1 Ornitolog 2.
The alternate wagtail (Motacilla alterna) is a bird species in the wagtail genus. It is special because of its unique song, in which consecutive pitches alternately increase and decrease. For example, if we use integers to represent pitches, then the song can be and , but it cannot be or . To record this fascinating creature, the ornithologist Byteasar left his recorder in the forest for several days. He now wants to know whether the recorded sound resembles the wagtail's song.
Write a program that, given a sequence of pitches, determines the minimum number of integers that must be changed to any integers within the range in order to make the sequence a valid alternate wagtail song pitch sequence.
Input Format
The first line contains an integer , the length of the pitch sequence.
The second line contains integers , representing the pitch sequence.
Output Format
Output the minimum number of integers that need to be modified so that the sequence becomes a valid alternate wagtail song pitch sequence.
5
4 1 3 3 1
1
4
-1000000 -1000000 -1000000 -1000000
2
Hint
For of the testdata, the following constraints hold:
, .
Translated by ChatGPT 5