#include<bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; using vpi = vector<pi>; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ALL(c) (c).begin(), (c).end() #define ALLD(c) (c).rbegin(), (c).rend() #define SIZE(x) ((int)(x).size()) #define pb push_back #define pp emplace_back #define st first #define nd second #define sq(a) (a)*(a) const int inf = 1000000001; const double eps = 1e-9; bool fleq(double a, double b){ return abs(a - b) < eps; } int n, k; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; vi a(n); for(int &x : a)cin >> x; if(k == 2){ vi maksio(n); vi minio(n); maksio[n - 1] = a[n - 1]; minio[0] = a[0]; FOR(i, 1, n - 1){ minio[i] = min(minio[i - 1], a[i]); } FORD(i, n - 2, 0){ maksio[i] = max(maksio[i + 1], a[i]); } REP(i, n - 1){ if(minio[i] >= maksio[i + 1]){ cout << "TAK\n"; cout << i + 1 << '\n'; return 0; } } cout << "NIE\n"; return 0; } if(k == 3){ if(a[0] >= a[1]){ cout << "TAK\n1 2\n"; return 0; } if(a[n - 2] >= a[n - 1]){ cout << "TAK\n" << n - 2 << ' ' << n - 1 << '\n'; return 0; } vi maksio(n); vi minio(n); maksio[n - 1] = a[n - 1]; minio[0] = a[0]; FOR(i, 1, n - 1){ minio[i] = min(minio[i - 1], a[i]); } FORD(i, n - 2, 0){ maksio[i] = max(maksio[i + 1], a[i]); } FOR(i, 1, n - 2){ if(a[i] >= maksio[i]){ cout << "TAK\n"; cout << i << ' ' << i + 1 << '\n'; return 0; } } FOR(i, 1, n - 2){ if(a[i] <= minio[i]){ cout << "TAK\n"; cout << i << ' ' << i + 1 << '\n'; return 0; } } cout << "NIE\n"; return 0; } vector<int>ans; if(a[0] >= a[1]){ cout << "TAK\n"; FOR(i, 1, k - 1){ cout << i << ' '; } return 0; } if(a[n - 2] >= a[n - 1]){ cout << "TAK\n"; FOR(i, 1, k - 1){ cout << n - k + i << ' '; } return 0; } int m = -1; REP(i, n - 1){ if(a[i] >= a[i + 1])m = i; } if(m == -1){ cout << "NIE\n"; return 0; } ans.pb(m); ans.pb(m + 1); ans.pb(m + 2); for(int i = 1; SIZE(ans) < k - 1; i++){ if(i != m && i != m + 1 && i != m + 2)ans.pb(i); } cout << "TAK\n"; sort(ALL(ans)); for(int i : ans)cout << i << ' '; 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 | #include<bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; using vpi = vector<pi>; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ALL(c) (c).begin(), (c).end() #define ALLD(c) (c).rbegin(), (c).rend() #define SIZE(x) ((int)(x).size()) #define pb push_back #define pp emplace_back #define st first #define nd second #define sq(a) (a)*(a) const int inf = 1000000001; const double eps = 1e-9; bool fleq(double a, double b){ return abs(a - b) < eps; } int n, k; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; vi a(n); for(int &x : a)cin >> x; if(k == 2){ vi maksio(n); vi minio(n); maksio[n - 1] = a[n - 1]; minio[0] = a[0]; FOR(i, 1, n - 1){ minio[i] = min(minio[i - 1], a[i]); } FORD(i, n - 2, 0){ maksio[i] = max(maksio[i + 1], a[i]); } REP(i, n - 1){ if(minio[i] >= maksio[i + 1]){ cout << "TAK\n"; cout << i + 1 << '\n'; return 0; } } cout << "NIE\n"; return 0; } if(k == 3){ if(a[0] >= a[1]){ cout << "TAK\n1 2\n"; return 0; } if(a[n - 2] >= a[n - 1]){ cout << "TAK\n" << n - 2 << ' ' << n - 1 << '\n'; return 0; } vi maksio(n); vi minio(n); maksio[n - 1] = a[n - 1]; minio[0] = a[0]; FOR(i, 1, n - 1){ minio[i] = min(minio[i - 1], a[i]); } FORD(i, n - 2, 0){ maksio[i] = max(maksio[i + 1], a[i]); } FOR(i, 1, n - 2){ if(a[i] >= maksio[i]){ cout << "TAK\n"; cout << i << ' ' << i + 1 << '\n'; return 0; } } FOR(i, 1, n - 2){ if(a[i] <= minio[i]){ cout << "TAK\n"; cout << i << ' ' << i + 1 << '\n'; return 0; } } cout << "NIE\n"; return 0; } vector<int>ans; if(a[0] >= a[1]){ cout << "TAK\n"; FOR(i, 1, k - 1){ cout << i << ' '; } return 0; } if(a[n - 2] >= a[n - 1]){ cout << "TAK\n"; FOR(i, 1, k - 1){ cout << n - k + i << ' '; } return 0; } int m = -1; REP(i, n - 1){ if(a[i] >= a[i + 1])m = i; } if(m == -1){ cout << "NIE\n"; return 0; } ans.pb(m); ans.pb(m + 1); ans.pb(m + 2); for(int i = 1; SIZE(ans) < k - 1; i++){ if(i != m && i != m + 1 && i != m + 2)ans.pb(i); } cout << "TAK\n"; sort(ALL(ans)); for(int i : ans)cout << i << ' '; return 0; } |