// #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #include <iostream> #include <vector> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { FAST int n, k; cin >> n >> k; vector<int> nums(n); vector<int> maxs(n); vector<int> mins(n); int minIdx = 0; int maxIdx = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; } switch (k) { case 2: mins[0] = nums[0]; for (int i = 1; i < n; i++) { mins[i] = nums[i]; if (mins[i - 1] < mins[i]) { mins[i] = mins[i - 1]; } } maxs[n - 1] = nums[n - 1]; for (int i = n - 2; i >= 0; i--) { maxs[i] = nums[i]; if (maxs[i + 1] > maxs[i]) { maxs[i] = maxs[i + 1]; } } for (int i = 0; i < n - 1; i++) { if (!(mins[i] < maxs[i + 1])) { cout << "TAK" << endl; cout << i + 1 << endl; return 0; } } cout << "NIE" << endl; return 0; case 3: minIdx = 0; maxIdx = 0; // check for min for (int i = 0; i < n; i++) { if (nums[i] <= nums[minIdx]) { minIdx = i; } if (nums[i] > nums[maxIdx]) { maxIdx = i; } } if (minIdx != 0) { cout << "TAK" << endl; if (minIdx == n - 1) { cout << minIdx - 1 << " " << minIdx << endl; } else { cout << minIdx << " " << minIdx + 1 << endl; } return 0; } if (maxIdx != n - 1) { cout << "TAK" << endl; if (maxIdx == 0) { cout << 1 << " " << 2 << endl; } else { cout << maxIdx << " " << maxIdx + 1 << endl; } return 0; } cout << "NIE" << endl; return 0; default: for (int i = 0; i < n - 1; i++) { if (nums[i] >= nums[i + 1]) { cout << "TAK" << endl; if (i + 1 == n - 1) { for (int j = n - k; j < n - 1; j++) { cout << j + 1 << " "; } cout << endl; return 0; } else { int from = max(i - k + 3, 0); for (int j = from; j < from + k - 1; j++) { cout << j + 1 << " "; } cout << endl; return 0; } } } cout << "NIE" << 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 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | // #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #include <iostream> #include <vector> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { FAST int n, k; cin >> n >> k; vector<int> nums(n); vector<int> maxs(n); vector<int> mins(n); int minIdx = 0; int maxIdx = 0; for (int i = 0; i < n; i++) { cin >> nums[i]; } switch (k) { case 2: mins[0] = nums[0]; for (int i = 1; i < n; i++) { mins[i] = nums[i]; if (mins[i - 1] < mins[i]) { mins[i] = mins[i - 1]; } } maxs[n - 1] = nums[n - 1]; for (int i = n - 2; i >= 0; i--) { maxs[i] = nums[i]; if (maxs[i + 1] > maxs[i]) { maxs[i] = maxs[i + 1]; } } for (int i = 0; i < n - 1; i++) { if (!(mins[i] < maxs[i + 1])) { cout << "TAK" << endl; cout << i + 1 << endl; return 0; } } cout << "NIE" << endl; return 0; case 3: minIdx = 0; maxIdx = 0; // check for min for (int i = 0; i < n; i++) { if (nums[i] <= nums[minIdx]) { minIdx = i; } if (nums[i] > nums[maxIdx]) { maxIdx = i; } } if (minIdx != 0) { cout << "TAK" << endl; if (minIdx == n - 1) { cout << minIdx - 1 << " " << minIdx << endl; } else { cout << minIdx << " " << minIdx + 1 << endl; } return 0; } if (maxIdx != n - 1) { cout << "TAK" << endl; if (maxIdx == 0) { cout << 1 << " " << 2 << endl; } else { cout << maxIdx << " " << maxIdx + 1 << endl; } return 0; } cout << "NIE" << endl; return 0; default: for (int i = 0; i < n - 1; i++) { if (nums[i] >= nums[i + 1]) { cout << "TAK" << endl; if (i + 1 == n - 1) { for (int j = n - k; j < n - 1; j++) { cout << j + 1 << " "; } cout << endl; return 0; } else { int from = max(i - k + 3, 0); for (int j = from; j < from + k - 1; j++) { cout << j + 1 << " "; } cout << endl; return 0; } } } cout << "NIE" << endl; return 0; } } |