#include<bits/stdc++.h> #define poly vector<int> #define IOS ios::sync_with_stdio(false) #define ll long long #define mp make_pair #define mt make_tuple #define pa pair < int,int > #define fi first #define se second #define inf 1e9 #define mod 998244353 #define int ll #define N 1000005 using namespace std; int n,m,pre[N],suf[N],a[N]; void BellaKira() { cin>>n>>m; pre[0]=inf; for (int i=1;i<=n;i++) { cin>>a[i]; pre[i]=min(pre[i-1],a[i]); } for (int i=n;i>=1;i--) suf[i]=max(suf[i+1],a[i]); if (m==2) { for (int i=1;i<n;i++) if (pre[i]>=suf[i+1]) { cout<<"TAK\n"; cout<<i<<'\n'; return; } cout<<"NIE\n"; return; } for (int i=n-1;i>=1;i--) if (a[i]==suf[i]) { cout<<"TAK\n"; int x=m-3; if (i==1) x++; for (int j=1;j+1<i;j++) if (x) { cout<<j<<" "; x--; } if (i!=1) cout<<i-1<<" "; cout<<i<<" "; for (int j=i+1;j<n;j++) if (x) { cout<<j<<" "; x--; } return; } cout<<"NIE\n"; } signed main() { IOS; cin.tie(0); int T=1; while (T--) { BellaKira(); } }
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 | #include<bits/stdc++.h> #define poly vector<int> #define IOS ios::sync_with_stdio(false) #define ll long long #define mp make_pair #define mt make_tuple #define pa pair < int,int > #define fi first #define se second #define inf 1e9 #define mod 998244353 #define int ll #define N 1000005 using namespace std; int n,m,pre[N],suf[N],a[N]; void BellaKira() { cin>>n>>m; pre[0]=inf; for (int i=1;i<=n;i++) { cin>>a[i]; pre[i]=min(pre[i-1],a[i]); } for (int i=n;i>=1;i--) suf[i]=max(suf[i+1],a[i]); if (m==2) { for (int i=1;i<n;i++) if (pre[i]>=suf[i+1]) { cout<<"TAK\n"; cout<<i<<'\n'; return; } cout<<"NIE\n"; return; } for (int i=n-1;i>=1;i--) if (a[i]==suf[i]) { cout<<"TAK\n"; int x=m-3; if (i==1) x++; for (int j=1;j+1<i;j++) if (x) { cout<<j<<" "; x--; } if (i!=1) cout<<i-1<<" "; cout<<i<<" "; for (int j=i+1;j<n;j++) if (x) { cout<<j<<" "; x--; } return; } cout<<"NIE\n"; } signed main() { IOS; cin.tie(0); int T=1; while (T--) { BellaKira(); } } |