//dzien1 - B #include <bits/stdc++.h> using namespace std; int tab1[50005]; int tab2[50005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int result1 = 0, result2 = 0; for(int i=0; i<n; i++) { int a; cin >> a; tab1[i] = a; tab2[i] = a; } for(int i=1; i<n; i++) { if(i%2 == 0) { if(tab2[i] <= tab2[i-1]) {result2++; tab2[i] = 1000002;} if(tab1[i] >= tab1[i-1]) {result1++; tab1[i] = -1000002;} } if(i%2 == 1) { if(tab1[i] <= tab1[i-1]) {result1++; tab1[i] = 1000002;} if(tab2[i] >= tab2[i-1]) {result2++; tab2[i] = -1000002;} } } cout<<min(result1, result2); 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 | //dzien1 - B #include <bits/stdc++.h> using namespace std; int tab1[50005]; int tab2[50005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int result1 = 0, result2 = 0; for(int i=0; i<n; i++) { int a; cin >> a; tab1[i] = a; tab2[i] = a; } for(int i=1; i<n; i++) { if(i%2 == 0) { if(tab2[i] <= tab2[i-1]) {result2++; tab2[i] = 1000002;} if(tab1[i] >= tab1[i-1]) {result1++; tab1[i] = -1000002;} } if(i%2 == 1) { if(tab1[i] <= tab1[i-1]) {result1++; tab1[i] = 1000002;} if(tab2[i] >= tab2[i-1]) {result2++; tab2[i] = -1000002;} } } cout<<min(result1, result2); return 0; } |