//============================================================================ // Name : 1b-orn.cpp // Author : poz // Version : // Description : https://sio2.mimuw.edu.pl/c/pa-2022-1/p/orn/ //============================================================================ #include <bits/stdc++.h> using namespace std; int main() { const int D = 2'097'152; int n; cin >> n; vector<int> tones_up(n); vector<int> tones_down(n); for (int i = 0; i < n; i++) { cin >> tones_up[i]; tones_down[i] = tones_up[i]; } int result_up = 0; int result_down = 0; for (int i = 1; i < n; i++) { if (i % 2 == 0) { if (tones_up[i - 1] <= tones_up[i]) { tones_up[i] -= D; result_up++; } if (tones_down[i - 1] >= tones_down[i]) { tones_down[i] += D; result_down++; } } else { if (tones_up[i - 1] >= tones_up[i]) { tones_up[i] += D; result_up++; } if (tones_down[i - 1] <= tones_down[i]) { tones_down[i] -= D; result_down++; } } } cout << min(result_up, result_down) << endl; 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 46 47 | //============================================================================ // Name : 1b-orn.cpp // Author : poz // Version : // Description : https://sio2.mimuw.edu.pl/c/pa-2022-1/p/orn/ //============================================================================ #include <bits/stdc++.h> using namespace std; int main() { const int D = 2'097'152; int n; cin >> n; vector<int> tones_up(n); vector<int> tones_down(n); for (int i = 0; i < n; i++) { cin >> tones_up[i]; tones_down[i] = tones_up[i]; } int result_up = 0; int result_down = 0; for (int i = 1; i < n; i++) { if (i % 2 == 0) { if (tones_up[i - 1] <= tones_up[i]) { tones_up[i] -= D; result_up++; } if (tones_down[i - 1] >= tones_down[i]) { tones_down[i] += D; result_down++; } } else { if (tones_up[i - 1] >= tones_up[i]) { tones_up[i] += D; result_up++; } if (tones_down[i - 1] <= tones_down[i]) { tones_down[i] -= D; result_down++; } } } cout << min(result_up, result_down) << endl; return 0; } |