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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define fio cin.tie(0);ios_base::sync_with_stdio(0);
int sounds[50005];
int sounds2[50005];
int main()
{
    fio;
    bool upordown=0; ///0-down   1-up
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>sounds[i];
        sounds2[i]=sounds[i];
    }
    int ans1=0;
    int ans2=0;

    //druga w gore
    upordown=1;
    for(int i=1;i<n;i++)
    {
        if(upordown==1)
        {
            if(sounds[i]>sounds[i-1])
            {
                //git
            }
            else
            {
                //nie git
                sounds[i]=2000000;
                ans1++;
            }
        }
        else
        {
            if(sounds[i]<sounds[i-1])
            {
                //gicior
            }
            else
            {
                sounds[i]=-2000000;
                ans1++;
            }
        }
        upordown=!upordown;
    }
    //druga w dol
    upordown=0;
    for(int i=1;i<n;i++)
    {
        if(upordown==1)
        {
            if(sounds2[i]>sounds2[i-1])
            {
                //git
            }
            else
            {
                //nie git
                sounds2[i]=2000000;
                ans2++;
            }
        }
        else
        {
            if(sounds2[i]<sounds2[i-1])
            {
                //gicior
            }
            else
            {
                sounds2[i]=-2000000;
                ans2++;
            }
        }
        upordown=!upordown;
    }

    cout<<min(ans1,ans2);
    return 0;
}