#include<bits/stdc++.h> using namespace std; int tab[50010]; int tab2[50010]; int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>tab[i]; tab2[i]=tab[i]; } int wyn1=0,wyn2=0; if(n%2==0)tab[n]=1e9+7; for(int i=1;i<n;i+=2){ if(tab[i]>=tab[i-1]){ tab[i]=-1e9; wyn1++; } if(tab[i]>=tab[i+1]){ tab[i+1]=1e9; wyn1++; } //cout<<tab[i-1]<<" "<<tab[i]<<" "; } //cout<<"\n"<<wyn1<<"\n"; if(n%2==0)tab2[n]=-1e9-7; for(int i=1;i<n;i+=2){ if(tab2[i]<=tab2[i-1]){ tab2[i]=1e9; wyn2++; } if(tab2[i]<=tab2[i+1]){ tab2[i+1]=-1e9; wyn2++; } //cout<<tab2[i-1]<<" "<<tab2[i]<<" "; } cout<<min(wyn1,wyn2)<<"\n"; return 0; }
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; int tab[50010]; int tab2[50010]; int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>tab[i]; tab2[i]=tab[i]; } int wyn1=0,wyn2=0; if(n%2==0)tab[n]=1e9+7; for(int i=1;i<n;i+=2){ if(tab[i]>=tab[i-1]){ tab[i]=-1e9; wyn1++; } if(tab[i]>=tab[i+1]){ tab[i+1]=1e9; wyn1++; } //cout<<tab[i-1]<<" "<<tab[i]<<" "; } //cout<<"\n"<<wyn1<<"\n"; if(n%2==0)tab2[n]=-1e9-7; for(int i=1;i<n;i+=2){ if(tab2[i]<=tab2[i-1]){ tab2[i]=1e9; wyn2++; } if(tab2[i]<=tab2[i+1]){ tab2[i+1]=-1e9; wyn2++; } //cout<<tab2[i-1]<<" "<<tab2[i]<<" "; } cout<<min(wyn1,wyn2)<<"\n"; return 0; } |