/* ----------------------- Autor: Tomasz Boguslawski -------------------------- */ #include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<iomanip> #include<string> #include<sstream> #include<cstring> #include<map> #include<vector> #include<set> #include<queue> #include<algorithm> #include <fstream> #include<math.h> #define LL long long #define FOR(x, b, e) for(LL x = b; x <= (e); x++) #define FORS(x, b, e, s) for(LL x = b; x <= (e); x+=s) #define FORD(x, b, e) for(LL x = b; x >= (e); x--) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define DEBUG if (debug) #define MIN(a,b) ((a>b)?b:a) #define MAX(a,b) ((a>b)?a:b) using namespace std; LL a[500007]; LL n, k; void read() { cin >> n; cin >> k; FOR(i,1,n) cin >> a[i]; } LL block[500007]; LL max2[500007]; bool solve2() { max2[n]=a[n]; FORD(i,n-1,1) { if (a[i]>max2[i+1]) max2[i]=a[i]; else max2[i]=max2[i+1]; } LL min1=a[1]; FOR(i,1,n-1) { if (a[i]<min1) min1=a[i]; if (min1>=max2[i+1]) { block[1]=i; return true; } } return false; } bool solve3() { if (a[1]>=a[n]) { block[1]=1; block[2]=n-1; return true; } LL min1=a[1]; FOR(i,1,n-2) { if (a[i]<min1) min1=a[i]; if (a[i+1]<=min1) { block[1]=i; block[2]=i+1; return true; } } LL max3=a[n]; FORD(i,n,3) { if (a[i]>max3) max3=a[i]; if (a[i-1]>=max3) { block[1]=i-2; block[2]=i-1; return true; } } return false; } bool solve4() { FOR(i,1,n-1) if (a[i]>=a[i+1]) { if (i==1) { block[1]=1; block[2]=2; FOR(j,1,k-3) block[2+j]=2+j; } else if (i==n-1) { FOR(j,1,k-3) block[j]=j; block[k-2]=n-2; block[k-1]=n-1; } else { LL mam=4; LL num=0; FOR(j,1,i-2) { if (k-mam==0) break; num++; block[j]=j; mam++; } num++; block[num]=i-1; num++; block[num]=i; num++; block[num]=i+1; LL ind=i+2; while (k-mam>0) { num++; block[num]=ind; ind++; mam++; } } return true; } return false; } /// MAIN int main(int argc, char* argv[]) { // magic formula, which makes streams work faster: ios_base::sync_with_stdio(0); read(); bool good; if (k==2) good=solve2(); else if (k==3) good=solve3(); else good=solve4(); if (good) { cout << "TAK\n"; FOR(i,1,k-1) cout << block[i] << ' '; cout << '\n'; } else cout << "NIE\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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | /* ----------------------- Autor: Tomasz Boguslawski -------------------------- */ #include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<iomanip> #include<string> #include<sstream> #include<cstring> #include<map> #include<vector> #include<set> #include<queue> #include<algorithm> #include <fstream> #include<math.h> #define LL long long #define FOR(x, b, e) for(LL x = b; x <= (e); x++) #define FORS(x, b, e, s) for(LL x = b; x <= (e); x+=s) #define FORD(x, b, e) for(LL x = b; x >= (e); x--) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define DEBUG if (debug) #define MIN(a,b) ((a>b)?b:a) #define MAX(a,b) ((a>b)?a:b) using namespace std; LL a[500007]; LL n, k; void read() { cin >> n; cin >> k; FOR(i,1,n) cin >> a[i]; } LL block[500007]; LL max2[500007]; bool solve2() { max2[n]=a[n]; FORD(i,n-1,1) { if (a[i]>max2[i+1]) max2[i]=a[i]; else max2[i]=max2[i+1]; } LL min1=a[1]; FOR(i,1,n-1) { if (a[i]<min1) min1=a[i]; if (min1>=max2[i+1]) { block[1]=i; return true; } } return false; } bool solve3() { if (a[1]>=a[n]) { block[1]=1; block[2]=n-1; return true; } LL min1=a[1]; FOR(i,1,n-2) { if (a[i]<min1) min1=a[i]; if (a[i+1]<=min1) { block[1]=i; block[2]=i+1; return true; } } LL max3=a[n]; FORD(i,n,3) { if (a[i]>max3) max3=a[i]; if (a[i-1]>=max3) { block[1]=i-2; block[2]=i-1; return true; } } return false; } bool solve4() { FOR(i,1,n-1) if (a[i]>=a[i+1]) { if (i==1) { block[1]=1; block[2]=2; FOR(j,1,k-3) block[2+j]=2+j; } else if (i==n-1) { FOR(j,1,k-3) block[j]=j; block[k-2]=n-2; block[k-1]=n-1; } else { LL mam=4; LL num=0; FOR(j,1,i-2) { if (k-mam==0) break; num++; block[j]=j; mam++; } num++; block[num]=i-1; num++; block[num]=i; num++; block[num]=i+1; LL ind=i+2; while (k-mam>0) { num++; block[num]=ind; ind++; mam++; } } return true; } return false; } /// MAIN int main(int argc, char* argv[]) { // magic formula, which makes streams work faster: ios_base::sync_with_stdio(0); read(); bool good; if (k==2) good=solve2(); else if (k==3) good=solve3(); else good=solve4(); if (good) { cout << "TAK\n"; FOR(i,1,k-1) cout << block[i] << ' '; cout << '\n'; } else cout << "NIE\n"; return 0; } |