#include <iostream> #include <vector> using namespace std; #pragma GCC optimization_level 3 #pragma GCC optimize("Ofast") int tab[1000005]; int maxx[1000005]; int minn[1000005]; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> tab[i]; if (k == 2) { minn[0] = 1e9 + 5; for (int i = 1; i < n; i++) { minn[i] = min(minn[i - 1], tab[i]); } for (int i = n; i >= 2; i--) { maxx[i] = max(tab[i], maxx[i + 1]); } for (int i = 1; i <= n - 1; i++) { if (minn[i] >= maxx[i + 1]) { cout << "TAK\n"; cout << i; return 0; } } } cout << "NIE"; 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 | #include <iostream> #include <vector> using namespace std; #pragma GCC optimization_level 3 #pragma GCC optimize("Ofast") int tab[1000005]; int maxx[1000005]; int minn[1000005]; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> tab[i]; if (k == 2) { minn[0] = 1e9 + 5; for (int i = 1; i < n; i++) { minn[i] = min(minn[i - 1], tab[i]); } for (int i = n; i >= 2; i--) { maxx[i] = max(tab[i], maxx[i + 1]); } for (int i = 1; i <= n - 1; i++) { if (minn[i] >= maxx[i + 1]) { cout << "TAK\n"; cout << i; return 0; } } } cout << "NIE"; return 0; } |