#include <iostream> #include <vector> #include <algorithm> #include <set> #include <functional> #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; const int MAX_N = 5e5; const int LUCKY_NUM = 13; bool res_exists; int n, k, indexToPush, leftMin, rightMax; int revenue[MAX_N + LUCKY_NUM]; vector<int> result; multiset<int> lft; multiset<int, greater<int> > rgt; void solve2() { for (int i = 1; i <= n; i++) { rgt.insert(revenue[i]); } for (int i = 1; i <= n - 1; i++) { lft.insert(revenue[i]); rgt.erase(rgt.find(revenue[i])); leftMin = *lft.begin(); rightMax = *rgt.begin(); if (leftMin >= rightMax) { res_exists = true; result.push_back(i); return; } } } void set3Result(int i) { res_exists = true; result.push_back(i - 1); result.push_back(i); } void solve3() { for (int i = 2; i <= n - 1; i++) { if (revenue[i] <= revenue[1]) { return set3Result(i); } } for (int i = n - 1; i >= 2; i--) { if (revenue[i] >= revenue[n]) { return set3Result(i); } } } int findNonIncreasingIndex() { for (int i = 2; i <= n; i++) { if (revenue[i] <= revenue[i - 1]) return i; } return -1; } void solve4AndLarger() { int index = findNonIncreasingIndex(); if (index != -1) { res_exists = true; for (int i = 0; i < k - 1; i++) { indexToPush = index - 2 + i + (index == 2); if (indexToPush >= n) { indexToPush -= n - 1; } result.push_back(indexToPush); } sort(result.begin(), result.end()); } } void readInput() { boost; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> revenue[i]; } } void solve() { switch (k) { case 2: return solve2(); case 3: return solve3(); default: return solve4AndLarger(); } } void printResult() { cout << (res_exists ? "TAK" : "NIE") << endl; if (res_exists) { for (auto value: result) { cout << value << " "; } cout << endl; } } int32_t main() { readInput(); solve(); printResult(); }
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 | #include <iostream> #include <vector> #include <algorithm> #include <set> #include <functional> #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; const int MAX_N = 5e5; const int LUCKY_NUM = 13; bool res_exists; int n, k, indexToPush, leftMin, rightMax; int revenue[MAX_N + LUCKY_NUM]; vector<int> result; multiset<int> lft; multiset<int, greater<int> > rgt; void solve2() { for (int i = 1; i <= n; i++) { rgt.insert(revenue[i]); } for (int i = 1; i <= n - 1; i++) { lft.insert(revenue[i]); rgt.erase(rgt.find(revenue[i])); leftMin = *lft.begin(); rightMax = *rgt.begin(); if (leftMin >= rightMax) { res_exists = true; result.push_back(i); return; } } } void set3Result(int i) { res_exists = true; result.push_back(i - 1); result.push_back(i); } void solve3() { for (int i = 2; i <= n - 1; i++) { if (revenue[i] <= revenue[1]) { return set3Result(i); } } for (int i = n - 1; i >= 2; i--) { if (revenue[i] >= revenue[n]) { return set3Result(i); } } } int findNonIncreasingIndex() { for (int i = 2; i <= n; i++) { if (revenue[i] <= revenue[i - 1]) return i; } return -1; } void solve4AndLarger() { int index = findNonIncreasingIndex(); if (index != -1) { res_exists = true; for (int i = 0; i < k - 1; i++) { indexToPush = index - 2 + i + (index == 2); if (indexToPush >= n) { indexToPush -= n - 1; } result.push_back(indexToPush); } sort(result.begin(), result.end()); } } void readInput() { boost; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> revenue[i]; } } void solve() { switch (k) { case 2: return solve2(); case 3: return solve3(); default: return solve4AndLarger(); } } void printResult() { cout << (res_exists ? "TAK" : "NIE") << endl; if (res_exists) { for (auto value: result) { cout << value << " "; } cout << endl; } } int32_t main() { readInput(); solve(); printResult(); } |