#include <iostream> using namespace std; int main() { long n, k; cin >> n >> k; long *a = new long[n]; long *b = new long[n]; long *c = new long[n]; for (long i=0; i<n; i++) { cin >> a[i]; } b[0] = a[0]; for (long i=1; i<n; i++) { b[i] = min(a[i], b[i-1]); } c[n-1] = a[n-1]; for (long i=n-2; i>=0; i--) { c[i] = max(a[i], c[i+1]); } if (k == 2) { for (long i=1; i<n; i++) { if (b[i-1] >= c[i]) { cout << "TAK" << endl; cout << i << endl; return 0; } } } if (k > 2) { for (long i=1; i<n-1; i++) { if (b[i-1] >= a[i] || a[i] >= c[i+1]) { cout << "TAK" << endl; for (long j=0; k>3 && j<i-1; j++, k--) { cout << j+1 << " "; } cout << i << " " << i+1; k--; k--; for (long j=i+1; k>1; j++, k--) { cout << " " << j+1; } cout << endl; return 0; } } } cout << "NIE" << endl; 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 | #include <iostream> using namespace std; int main() { long n, k; cin >> n >> k; long *a = new long[n]; long *b = new long[n]; long *c = new long[n]; for (long i=0; i<n; i++) { cin >> a[i]; } b[0] = a[0]; for (long i=1; i<n; i++) { b[i] = min(a[i], b[i-1]); } c[n-1] = a[n-1]; for (long i=n-2; i>=0; i--) { c[i] = max(a[i], c[i+1]); } if (k == 2) { for (long i=1; i<n; i++) { if (b[i-1] >= c[i]) { cout << "TAK" << endl; cout << i << endl; return 0; } } } if (k > 2) { for (long i=1; i<n-1; i++) { if (b[i-1] >= a[i] || a[i] >= c[i+1]) { cout << "TAK" << endl; for (long j=0; k>3 && j<i-1; j++, k--) { cout << j+1 << " "; } cout << i << " " << i+1; k--; k--; for (long j=i+1; k>1; j++, k--) { cout << " " << j+1; } cout << endl; return 0; } } } cout << "NIE" << endl; return 0; } |