#include<bits/stdc++.h> using namespace std; bool debug = false; int main() { ios_base::sync_with_stdio(0); int n,q; cin >> n >> q; vector<int> vec(n); for(int k=0;k<n;k++) { cin >> vec[k]; } if(debug) { cout << n << " " << q <<endl; for(auto t:vec) cout << t << " "; cout << endl; } if(q == 2) { int preMin = vec[0]; vector<int> sufixMax(n+1,INT_MIN); for(int k=n-1;k>=0;k--) { sufixMax[k] = max(vec[k],sufixMax[k+1]); } for(int k=0;k<n-1;k++) { //cout << preMin << " " << sufixMax[k+1] <<endl; if(preMin >= sufixMax[k+1]) { cout << "TAK" <<endl; cout << k+1 <<endl; return 0; } preMin = min(preMin,vec[k+1]); } cout << "NIE" <<endl; return 0; } int candidate = -1; set<int> result; for(int k=0;k<n-1;k++) { if(vec[k] >= vec[k+1]) { candidate = k; if(k!= 0) result.insert(k); result.insert(k+1); if(k!= n-2) result.insert(k+2); break; } } if(candidate == -1) { cout << "NIE" <<endl; return 0; } if(result.size() > q-1 && q == 3) { result.clear(); int mini = 0; int maxi = n-1; for(int k=0;k<n;k++) { if(vec[mini] >= vec[k]) mini = k; if(vec[maxi] < vec[k]) maxi =k; } if(mini == 0 && maxi == n-1) { cout << "NIE" <<endl; return 0; } if(mini != 0 ) { result.insert(mini); if(mini + 1 != n) result.insert(mini+1); } else if(maxi != n-1) { result.insert(maxi+1); if(maxi != 0) result.insert(maxi); } } for(int k = 1;result.size()<q-1;k++) result.insert(k); cout << "TAK"<<endl; for(auto &t:result) cout << t << " "; }
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 | #include<bits/stdc++.h> using namespace std; bool debug = false; int main() { ios_base::sync_with_stdio(0); int n,q; cin >> n >> q; vector<int> vec(n); for(int k=0;k<n;k++) { cin >> vec[k]; } if(debug) { cout << n << " " << q <<endl; for(auto t:vec) cout << t << " "; cout << endl; } if(q == 2) { int preMin = vec[0]; vector<int> sufixMax(n+1,INT_MIN); for(int k=n-1;k>=0;k--) { sufixMax[k] = max(vec[k],sufixMax[k+1]); } for(int k=0;k<n-1;k++) { //cout << preMin << " " << sufixMax[k+1] <<endl; if(preMin >= sufixMax[k+1]) { cout << "TAK" <<endl; cout << k+1 <<endl; return 0; } preMin = min(preMin,vec[k+1]); } cout << "NIE" <<endl; return 0; } int candidate = -1; set<int> result; for(int k=0;k<n-1;k++) { if(vec[k] >= vec[k+1]) { candidate = k; if(k!= 0) result.insert(k); result.insert(k+1); if(k!= n-2) result.insert(k+2); break; } } if(candidate == -1) { cout << "NIE" <<endl; return 0; } if(result.size() > q-1 && q == 3) { result.clear(); int mini = 0; int maxi = n-1; for(int k=0;k<n;k++) { if(vec[mini] >= vec[k]) mini = k; if(vec[maxi] < vec[k]) maxi =k; } if(mini == 0 && maxi == n-1) { cout << "NIE" <<endl; return 0; } if(mini != 0 ) { result.insert(mini); if(mini + 1 != n) result.insert(mini+1); } else if(maxi != n-1) { result.insert(maxi+1); if(maxi != 0) result.insert(maxi); } } for(int k = 1;result.size()<q-1;k++) result.insert(k); cout << "TAK"<<endl; for(auto &t:result) cout << t << " "; } |