// orn: Ornitolog 2 | 2022-12-12 | Solution by Mikołaj Zabłocki (Dominik Korsa)
// https://sio2.mimuw.edu.pl/c/pa-2022-1/p/orn/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INFTY = 420'2137;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int incPrev = INFTY;
int incCost = 0;
int decPrev = -INFTY;
int decCost = 0;
while (n--) {
swap(incPrev, decPrev);
swap(incCost, decCost);
int a;
cin >> a;
if (a <= incPrev) {
++incCost;
incPrev = INFTY;
} else incPrev = a;
if (a >= decPrev) {
++decCost;
decPrev = -INFTY;
} else decPrev = a;
}
cout << min(incCost, decCost) << 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 | // orn: Ornitolog 2 | 2022-12-12 | Solution by Mikołaj Zabłocki (Dominik Korsa) // https://sio2.mimuw.edu.pl/c/pa-2022-1/p/orn/ #include <iostream> #include <vector> #include <algorithm> using namespace std; const int INFTY = 420'2137; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int incPrev = INFTY; int incCost = 0; int decPrev = -INFTY; int decCost = 0; while (n--) { swap(incPrev, decPrev); swap(incCost, decCost); int a; cin >> a; if (a <= incPrev) { ++incCost; incPrev = INFTY; } else incPrev = a; if (a >= decPrev) { ++decCost; decPrev = -INFTY; } else decPrev = a; } cout << min(incCost, decCost) << endl; return 0; } |
English