#include <bits/stdc++.h> using namespace std; int a[500005]; int vis[500005],mn[500005],mx[500005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin >> n >> k; for(int i=1;i<=n;i++) cin >> a[i]; int flag=1; for(int i=2;i<=n;i++) if(a[i]<=a[i-1]) flag=0; if(flag) { cout << "NIE"; return 0; } mn[1]=a[1],mx[n]=a[n]; for(int i=2;i<=n;i++) mn[i]=min(mn[i-1],a[i]); for(int i=n-1;i>=1;i--) mx[i]=max(mx[i+1],a[i]); for(int i=1;i<n;i++) { if(mn[i]>mx[i+1]) { cout << "TAK\n"; vis[i]=1,k-=2; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } if(k==2) { cout << "NIE"; return 0; } for(int i=2;i<n;i++) { if(a[i]>=mx[i+1]||a[i]<=mn[i-1]) { cout << "TAK\n"; vis[i-1]=vis[i]=1,k-=3; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } for(int i=1;i<n;i++) { if(a[i]>=a[i+1]) { cout << "TAK\n"; vis[i]=1,k-=2; if(i+1<n) vis[i+1]=1,--k; if(i+2<n) vis[i+2]=1,--k; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } 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 | #include <bits/stdc++.h> using namespace std; int a[500005]; int vis[500005],mn[500005],mx[500005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin >> n >> k; for(int i=1;i<=n;i++) cin >> a[i]; int flag=1; for(int i=2;i<=n;i++) if(a[i]<=a[i-1]) flag=0; if(flag) { cout << "NIE"; return 0; } mn[1]=a[1],mx[n]=a[n]; for(int i=2;i<=n;i++) mn[i]=min(mn[i-1],a[i]); for(int i=n-1;i>=1;i--) mx[i]=max(mx[i+1],a[i]); for(int i=1;i<n;i++) { if(mn[i]>mx[i+1]) { cout << "TAK\n"; vis[i]=1,k-=2; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } if(k==2) { cout << "NIE"; return 0; } for(int i=2;i<n;i++) { if(a[i]>=mx[i+1]||a[i]<=mn[i-1]) { cout << "TAK\n"; vis[i-1]=vis[i]=1,k-=3; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } for(int i=1;i<n;i++) { if(a[i]>=a[i+1]) { cout << "TAK\n"; vis[i]=1,k-=2; if(i+1<n) vis[i+1]=1,--k; if(i+2<n) vis[i+2]=1,--k; for(int j=1;j<n;j++) if(k&&!vis[j]) vis[j]=1,--k; for(int j=1;j<=n;j++) if(vis[j]) cout << j << " "; return 0; } } return 0; } |