1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);

    int N;
    vector<int> values_origin;

    cin >> N;

    for(int i = 0; i < N; i++){
        int input;
        cin >> input;
        values_origin.push_back(input);
    }

    // Rising / first original
    int counter = 0;
    int min_counter = 10e8;
    vector<int> values = values_origin;
    for(int i = 1; i < N; i++) {
        if(i%2 == 0){
            if(values[i] >= values[i-1]){
                counter++;
                values[i] = -10e8;
            }
        }
        else {
            if(values[i] <= values[i-1]){
                counter++;
                values[i] = 10e8;
            }
        }
    }
    min_counter = min(min_counter, counter);
    
    // Falling \ first original
    counter = 0;
    values = values_origin;
    for(int i = 1; i < N; i++) {
        if(i%2 == 1){
            if(values[i] >= values[i-1]){
                counter++;
                values[i] = -10e8;
            }
        }
        else {
            if(values[i] <= values[i-1]){
                counter++;
                values[i] = 10e8;
            }
        }
    }
    min_counter = min(min_counter, counter);

    cout << min_counter << endl;

    return 0;
}