#include <stdio.h> #include <string.h> #define LIMIT 500000 int arr[LIMIT]; int a1[LIMIT], a2[LIMIT]; int ans[LIMIT]; int main() { memset(ans, 0, sizeof(ans)); int n, k; scanf("%d %d", &n, &k); for(int i=0;i<n;i++) { scanf(" %d", arr + i); } if(k == 2) { *a1 = *arr; *a2 = arr[n-1]; for(int i=1;i<n;i++) { a1[i] = arr[i] < a1[i-1] ? arr[i] : a1[i-1]; a2[i] = arr[n-1-i] > a2[i-1] ? arr[n-1-i] : a2[i-1]; } /*for(int i=0;i<n;i++) { printf("%d ", a1[i]); } putchar(10); for(int i=0;i<n;i++) { printf("%d ", a2[n-1-i]); } putchar(10);*/ for(int i=0;i<n-1;i++) { if(a1[i] >= a2[n-2-i]) { puts("TAK"); printf("%d ", i+1); return 0; } } puts("NIE"); } else if(k == 3) { int sat = k-1; int min = *arr; char fg = 0; for(int i = 1; i<n;i++) { if(min > arr[i]) min = arr[i]; if(arr[i] <= min) { ans[i] = 1; sat--; if(i != n-1){ ans[i+1] = 1; sat--; } fg = 1; break; } } int max = arr[n-1]; if(!fg) { fg = 0; for(int i = 1; i<n;i++) { if(max < arr[n-1-i]) max = arr[n-1-i]; if(arr[n-1-i] >= max) { ans[n-1-i] = 1; sat--; if(i != n-1) { ans[n-i-2] = 1; sat--; } fg = 1; break; } } } if(!fg) { puts("NIE"); return 0; } for(int i=0;i<n && sat;i++) { if(!ans[i]) { ans[i] = 1; sat--; } } puts("TAK"); for(int i=0;i<n;i++) { if(ans[i]) printf("%d ", !i ? i+1 : i); } } else { int sat = k-1; char fg = 0; for(int i=0;i<n-1;i++) { if(arr[i] >= arr[i+1]) { if(i) ans[i-1] = 1; ans[i] = 1; ans[i+1] = 1; fg = 1; break; } } if(!fg) { puts("NIE"); return 0; } for(int i=0;i<n && sat;i++) { if(!ans[i]) { ans[i] = 1; sat--; } } puts("TAK"); for(int i=0;i<n;i++) { if(ans[i]) printf("%d ", !i ? i+1 : i); } } 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 | #include <stdio.h> #include <string.h> #define LIMIT 500000 int arr[LIMIT]; int a1[LIMIT], a2[LIMIT]; int ans[LIMIT]; int main() { memset(ans, 0, sizeof(ans)); int n, k; scanf("%d %d", &n, &k); for(int i=0;i<n;i++) { scanf(" %d", arr + i); } if(k == 2) { *a1 = *arr; *a2 = arr[n-1]; for(int i=1;i<n;i++) { a1[i] = arr[i] < a1[i-1] ? arr[i] : a1[i-1]; a2[i] = arr[n-1-i] > a2[i-1] ? arr[n-1-i] : a2[i-1]; } /*for(int i=0;i<n;i++) { printf("%d ", a1[i]); } putchar(10); for(int i=0;i<n;i++) { printf("%d ", a2[n-1-i]); } putchar(10);*/ for(int i=0;i<n-1;i++) { if(a1[i] >= a2[n-2-i]) { puts("TAK"); printf("%d ", i+1); return 0; } } puts("NIE"); } else if(k == 3) { int sat = k-1; int min = *arr; char fg = 0; for(int i = 1; i<n;i++) { if(min > arr[i]) min = arr[i]; if(arr[i] <= min) { ans[i] = 1; sat--; if(i != n-1){ ans[i+1] = 1; sat--; } fg = 1; break; } } int max = arr[n-1]; if(!fg) { fg = 0; for(int i = 1; i<n;i++) { if(max < arr[n-1-i]) max = arr[n-1-i]; if(arr[n-1-i] >= max) { ans[n-1-i] = 1; sat--; if(i != n-1) { ans[n-i-2] = 1; sat--; } fg = 1; break; } } } if(!fg) { puts("NIE"); return 0; } for(int i=0;i<n && sat;i++) { if(!ans[i]) { ans[i] = 1; sat--; } } puts("TAK"); for(int i=0;i<n;i++) { if(ans[i]) printf("%d ", !i ? i+1 : i); } } else { int sat = k-1; char fg = 0; for(int i=0;i<n-1;i++) { if(arr[i] >= arr[i+1]) { if(i) ans[i-1] = 1; ans[i] = 1; ans[i+1] = 1; fg = 1; break; } } if(!fg) { puts("NIE"); return 0; } for(int i=0;i<n && sat;i++) { if(!ans[i]) { ans[i] = 1; sat--; } } puts("TAK"); for(int i=0;i<n;i++) { if(ans[i]) printf("%d ", !i ? i+1 : i); } } return 0; } |