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
#include <iostream>
#include <algorithm>

using namespace std;
int n, ans, ans2;
int t[50005],t2[50005];
const int MX=1e9, MN=1e9*(-1);

int main()
{
    cin>>n;
    for(int i=1;i<=n; i++){
        cin>>t[i];
        t2[i]=t[i];
    }
    for(int i=2; i<=n; i++){
        if(n%2==0 and i==n and t[i-1]<=t[i]){
            t[i]=MN;
            ans++;
        }
        else if(i%2==0)
        {
            if(t[i-1]<=t[i]){
                t[i]=MN;
                ans++;
            }
            if(t[i+1]<=t[i]){
                t[i+1]=MX;
                ans++;
            }
            
        }
    }
    for(int i=2; i<=n; i++){
        if(n%2==0 and i==n and t2[i-1]>=t2[i]){
            t2[i]=MX;
            ans2++;
        }
        else if(i%2==0)
        {
            if(t2[i-1]>=t2[i]){
                t2[i]=MX;
                ans2++;
            }
            if(t2[i+1]>=t2[i]){
                t2[i+1]=MN;
                ans2++;
            }
        }
    }
    ans=min(ans,ans2);
    cout<<ans;
}