#include <bits/stdc++.h> using namespace std; const int MAXX = 1e6+5; const int INF = 1e9+5; int tab[MAXX]; int minL[MAXX]; int maxP[MAXX]; int n, k; bool odp[MAXX]; void filll() { int minn = INF; for (int i=0; i<n; i++) minL[i] = min(tab[i], minn), minn = minL[i]; int maxx = 0; for (int i=n-1; i>=0; i--) maxP[i] = max(tab[i], maxx), maxx = maxP[i]; /*for (int i=0; i<n; i++) cout << minL[i] << " "; cout << '\n'; for (int i=0; i<n; i++) cout << maxP[i] << " "; cout << '\n';*/ } void dwa() { filll(); for (int i=0; i<n-2; i++) if (minL[i] >= maxP[i+1]) { cout << "TAK" << '\n' << i+1; return; } cout << "NIE"; } void trzy() { filll(); for (int i=1; i<n-2; i++) if (minL[i-1] >= tab[i] || tab[i] >= maxP[i+1]) { cout << "TAK" << '\n'<< i+1 << " " << i+2; return; } cout << "NIE"; } int main() { cin >> n >> k; for (int i=0; i<n; i++) cin >> tab[i]; if (k == 2) {dwa(); return 0;} if (k == 3) {trzy(); return 0;} int w = tab[0], l = 0; for (int i=1; i<n; i++) { if (tab[i] <= tab[i-1]) { if (i == 1) { l += 2; odp[i] = 1; odp[i+1] = 1; break; } l += 3; odp[i] = 1; odp[i-1] = 1; odp[i-2] = 1; break; } } if (l == 0) {cout << "NIE"; return 0; } cout << "TAK" << '\n'; for (int i=0; i < n; i++) { if (odp[i] == 1) cout << i+1 << " "; if (odp[i] != 1 && l < k) cout << i+1 << " ", l++; } 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> using namespace std; const int MAXX = 1e6+5; const int INF = 1e9+5; int tab[MAXX]; int minL[MAXX]; int maxP[MAXX]; int n, k; bool odp[MAXX]; void filll() { int minn = INF; for (int i=0; i<n; i++) minL[i] = min(tab[i], minn), minn = minL[i]; int maxx = 0; for (int i=n-1; i>=0; i--) maxP[i] = max(tab[i], maxx), maxx = maxP[i]; /*for (int i=0; i<n; i++) cout << minL[i] << " "; cout << '\n'; for (int i=0; i<n; i++) cout << maxP[i] << " "; cout << '\n';*/ } void dwa() { filll(); for (int i=0; i<n-2; i++) if (minL[i] >= maxP[i+1]) { cout << "TAK" << '\n' << i+1; return; } cout << "NIE"; } void trzy() { filll(); for (int i=1; i<n-2; i++) if (minL[i-1] >= tab[i] || tab[i] >= maxP[i+1]) { cout << "TAK" << '\n'<< i+1 << " " << i+2; return; } cout << "NIE"; } int main() { cin >> n >> k; for (int i=0; i<n; i++) cin >> tab[i]; if (k == 2) {dwa(); return 0;} if (k == 3) {trzy(); return 0;} int w = tab[0], l = 0; for (int i=1; i<n; i++) { if (tab[i] <= tab[i-1]) { if (i == 1) { l += 2; odp[i] = 1; odp[i+1] = 1; break; } l += 3; odp[i] = 1; odp[i-1] = 1; odp[i-2] = 1; break; } } if (l == 0) {cout << "NIE"; return 0; } cout << "TAK" << '\n'; for (int i=0; i < n; i++) { if (odp[i] == 1) cout << i+1 << " "; if (odp[i] != 1 && l < k) cout << i+1 << " ", l++; } return 0; } |