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
#include <bits/stdc++.h>
using namespace std;
int ciag[50007];
int rosnace[50007];
int malejace[50007];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int wynik_m = 0;
    int wynik_r = 0;
    for (int i = 0; i < n; ++i){
        cin >> ciag[i];
        rosnace[i] = ciag[i];
        malejace[i] = ciag[i];
    }
    for (int i = 1; i < n; ++i){
        if (i % 2 == 0){
            if (rosnace[i - 1] <= rosnace[i]){
                    rosnace[i] = -1e9;
                    wynik_r++;
                    //cout << i << "R1" << "\n";
            }
            if (malejace[i - 1] >= malejace[i]){
                    malejace[i] = 1e9;
                    wynik_m++;
                    //cout << i << "M1" << "\n";
            }
        }
        else if (i % 2 == 1){
            if (rosnace[i - 1] >= rosnace[i]){
                    rosnace[i] = 1e9;
                    wynik_r++;
                    //cout << i << "R2" << "\n";
            }
            if (malejace[i - 1] <= malejace[i]){
                    malejace[i] = -1e9;
                    wynik_m++;
                    //cout << i << "M2" << "\n";
            }
        }
    }
    cout << min(wynik_m, wynik_r);
}