#include <bits/stdc++.h> using namespace std; #define A 1000000000 int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for(auto &&e : a) cin >> e; int sol = INT_MAX; for(int s = 0; s < 2; ++s) { bool korekta = false; int r = 0; for(int i = 0; i < n-1; ++i) { int c = i%2 == s ? 1 : -1; int l = korekta ? c * A : a[i]; korekta = false; if(c*l <= c*a[i+1]) { korekta = true; ++r; } } sol = min(sol, r); } cout << sol << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; #define A 1000000000 int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for(auto &&e : a) cin >> e; int sol = INT_MAX; for(int s = 0; s < 2; ++s) { bool korekta = false; int r = 0; for(int i = 0; i < n-1; ++i) { int c = i%2 == s ? 1 : -1; int l = korekta ? c * A : a[i]; korekta = false; if(c*l <= c*a[i+1]) { korekta = true; ++r; } } sol = min(sol, r); } cout << sol << '\n'; } |