#include <bits/stdc++.h> #include <stdlib.h> using namespace std; int n,k; vector<int> a; vector<int> res; vector<int> minV; int spad = -1; int globalMax = 0; int globalMin = 1; void rozw1(){ int ind = 1; int ciach = k-1; while(ind < spad && ciach > 3){ res.push_back(ind); ind++; ciach--; } if(spad == 0) ciach++; else res.push_back(spad); res.push_back(spad+1); res.push_back(spad+2); ind = spad+3; ciach-=3; while(ind <= n && ciach > 0){ res.push_back(ind); ind++; ciach--; } } void rozw2(){ int maxV = -1; for(int i = n; i > 1; i--){ maxV = max(maxV, a[i]); if(minV[i-1] >= maxV){ res.push_back(i-1); return; } } } void rozw3(){ if(globalMax == 1){ res = {1,2}; }else if(globalMax != n){ res = {globalMax-1,globalMax}; }else if(globalMin != 1){ res = {globalMin-1,globalMin}; } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>k; a.assign(n+1,0); minV.assign(n+1,0); bool rosnacy = 1; a[0] = -1; minV[0] = 1e9 + 7; for(int i = 1; i<=n; i++){ cin>>a[i]; minV[i] = min(minV[i-1], a[i]); if(a[globalMax] < a[i]) globalMax = i; if(a[globalMin] >= a[i]) globalMin = i; if(a[i] <= a[i-1]){ rosnacy = 0; spad = i-2; } } if(k >= 4)rozw1(); else if(k == 2)rozw2(); else if(k == 3)rozw3(); if(rosnacy || (res.size() != k-1))cout<<"NIE\n"; else{ cout<<"TAK\n"; for(int r:res)cout<<r<<" "; cout<<"\n"; } 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 | #include <bits/stdc++.h> #include <stdlib.h> using namespace std; int n,k; vector<int> a; vector<int> res; vector<int> minV; int spad = -1; int globalMax = 0; int globalMin = 1; void rozw1(){ int ind = 1; int ciach = k-1; while(ind < spad && ciach > 3){ res.push_back(ind); ind++; ciach--; } if(spad == 0) ciach++; else res.push_back(spad); res.push_back(spad+1); res.push_back(spad+2); ind = spad+3; ciach-=3; while(ind <= n && ciach > 0){ res.push_back(ind); ind++; ciach--; } } void rozw2(){ int maxV = -1; for(int i = n; i > 1; i--){ maxV = max(maxV, a[i]); if(minV[i-1] >= maxV){ res.push_back(i-1); return; } } } void rozw3(){ if(globalMax == 1){ res = {1,2}; }else if(globalMax != n){ res = {globalMax-1,globalMax}; }else if(globalMin != 1){ res = {globalMin-1,globalMin}; } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>k; a.assign(n+1,0); minV.assign(n+1,0); bool rosnacy = 1; a[0] = -1; minV[0] = 1e9 + 7; for(int i = 1; i<=n; i++){ cin>>a[i]; minV[i] = min(minV[i-1], a[i]); if(a[globalMax] < a[i]) globalMax = i; if(a[globalMin] >= a[i]) globalMin = i; if(a[i] <= a[i-1]){ rosnacy = 0; spad = i-2; } } if(k >= 4)rozw1(); else if(k == 2)rozw2(); else if(k == 3)rozw3(); if(rosnacy || (res.size() != k-1))cout<<"NIE\n"; else{ cout<<"TAK\n"; for(int r:res)cout<<r<<" "; cout<<"\n"; } return 0; } |