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
#include <iostream>
using namespace std;
long long n, tab[100005],wyn,cur,stare;
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> tab[i];
    stare = -5;
    for (int i = 1; i < n; i++) {
        if (i % 2 == 0) {
            if (tab[i] >= tab[i - 1] && stare != i - 1) {
                cur++;
                stare = i;
              //  cout << "ZLE" << i << endl;
            }
        }
        else if (tab[i] <= tab[i - 1] && stare != i - 1) {
            cur++;
            stare = i;
            // cout << "zle" << i << endl;
        }
    }
    wyn = cur;
    cur = 0;
    stare = -5;
    for (int i = 1; i < n; i++) {
        if (i % 2 == 1) {
            if (tab[i] >= tab[i - 1] && stare != i - 1) {
                cur++;
                stare = i;
               // cout << "zle" << i << endl;
            }
        }
        else if (tab[i] <= tab[i - 1] && stare != i - 1) {
                cur++;
                stare = i;
               // cout << "ZLE" << i << endl;
            }
    }
    wyn = min(wyn, cur);
    cout << wyn;
}