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
#include<bits/stdc++.h>
using namespace std;
const int big=1100000000;
int main()
{
    int a,b1,b2,c1,c2,w1=0,w2=0;
    cin >> a;
    cin >> c1;
    c2=c1;
    for(int i=1;i<a;i++)
    {
        cin >> b1;
        b2=b1;
        if(i%2==1)
        {
            if(b1>=c1) /// w ciagu 1 najpierw ma maleć a potem rosnąć, a w ciągu 2 na odwrót
            {
                b1=-big;
                w1++;
            }
            if(b2<=c2)
            {
                b2=big;
                w2++;
            }

        }
        else
        {
            if(b1<=c1)
            {
                b1=big;
                w1++;
            }
            if(b2>=c2)
            {
                b2=-big;
                w2++;
            }
        }
        ///cout << b1 << " " << b2 << " " << c1 << " " << c2 << "\n";
        c1=b1,c2=b2;
    }
    cout << min(w1,w2);
}