#include <bits/stdc++.h> using namespace std; vector <int> v; priority_queue <int> res; int mini, minw, mina, minb, minc = 1000000009, minma=1000000009, minmai, k, n; int main() { cin>>k>>n; n-=1; v.push_back(0); for (int i=1; i<k; i++) { int x; cin>>x; if (x<minc) minc=x; if (x>=minw and i!=k) { minb=minc; minw=x; mini=i; mina=0; minma=1000000009; } else if (x>mina) mina=x; if (x<minma) { minma=x; minmai=i; } v.push_back(x); } int x; cin>>x; v.push_back(x); if (v[mini-1]==minw) { res.push(-1*(mini-1)); if (n>1) res.push(-1*mini); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if ((k==2 and v[1]<v[2]) or (v[k]>minw and minb<minma and v[k-1]!=minw and k-1!=minmai) or (mini==k-1 and minw<v[k]) or (minw<v[k] and mini!=k-2)) k=k; else if (mina<minw and v[k]>minw and n>1) { res.push(-1*mini); res.push(-1*(k-1)); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if (v[k]>minw and minb>=minma) { res.push(-1*mini); res.push(-1*minmai); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if (mini==1) { res.push(-1*mini); for (int i=1; i<=n; i++) res.push(-1*(mini+i)); } else if (mini!=k and n>1 and v[mini-1]!=minw) { res.push(-1*(mini-1)); res.push(-1*mini); for (int i=2; i<=n; i++) res.push(-1*(mini+1)); } else if (n==1 and minb>=mina) { res.push(-1*mini); } if (res.empty()) { cout<<"NIE\n"; return 0; } cout<<"TAK\n"; while (not res.empty()) { cout<<(-1*res.top())<<' '; res.pop(); } }
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 | #include <bits/stdc++.h> using namespace std; vector <int> v; priority_queue <int> res; int mini, minw, mina, minb, minc = 1000000009, minma=1000000009, minmai, k, n; int main() { cin>>k>>n; n-=1; v.push_back(0); for (int i=1; i<k; i++) { int x; cin>>x; if (x<minc) minc=x; if (x>=minw and i!=k) { minb=minc; minw=x; mini=i; mina=0; minma=1000000009; } else if (x>mina) mina=x; if (x<minma) { minma=x; minmai=i; } v.push_back(x); } int x; cin>>x; v.push_back(x); if (v[mini-1]==minw) { res.push(-1*(mini-1)); if (n>1) res.push(-1*mini); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if ((k==2 and v[1]<v[2]) or (v[k]>minw and minb<minma and v[k-1]!=minw and k-1!=minmai) or (mini==k-1 and minw<v[k]) or (minw<v[k] and mini!=k-2)) k=k; else if (mina<minw and v[k]>minw and n>1) { res.push(-1*mini); res.push(-1*(k-1)); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if (v[k]>minw and minb>=minma) { res.push(-1*mini); res.push(-1*minmai); for (int i=1; res.size()!=n; i++) if (i!=mini and i!=minmai) res.push(-1*i); } else if (mini==1) { res.push(-1*mini); for (int i=1; i<=n; i++) res.push(-1*(mini+i)); } else if (mini!=k and n>1 and v[mini-1]!=minw) { res.push(-1*(mini-1)); res.push(-1*mini); for (int i=2; i<=n; i++) res.push(-1*(mini+1)); } else if (n==1 and minb>=mina) { res.push(-1*mini); } if (res.empty()) { cout<<"NIE\n"; return 0; } cout<<"TAK\n"; while (not res.empty()) { cout<<(-1*res.top())<<' '; res.pop(); } } |