#include <bits/stdc++.h> using namespace std; const int NMAX = 5e4, inf = 1e9 + 7; int n, ans1, ans2; int a[NMAX + 7]; int32_t main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = 1; i < n; i++){ if ((i & 1) != (a[i] < a[i + 1]) || a[i] == a[i + 1]){ ans1++; i++; } } for (int i = 1; i < n; i++){ if ((i & 1) != (a[i] > a[i + 1]) || a[i] == a[i + 1]){ ans2++; i++; } } cout << min(ans1, ans2); return 0; } // DAWID PAWELEC
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 | #include <bits/stdc++.h> using namespace std; const int NMAX = 5e4, inf = 1e9 + 7; int n, ans1, ans2; int a[NMAX + 7]; int32_t main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = 1; i < n; i++){ if ((i & 1) != (a[i] < a[i + 1]) || a[i] == a[i + 1]){ ans1++; i++; } } for (int i = 1; i < n; i++){ if ((i & 1) != (a[i] > a[i + 1]) || a[i] == a[i + 1]){ ans2++; i++; } } cout << min(ans1, ans2); return 0; } // DAWID PAWELEC |