#include <iostream> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin>>a>>b; int tab[a]; for(int i = 0; i < a; i++) { cin>>tab[i]; } if(b == 2) { int c = tab[0], d = tab[0], ind = 0; for(int i = 1; i < a; i++) { if(tab[i] < d) d = tab[i]; else if(tab[i] > c) { c = d; ind = i; } } if(ind == a - 1) { cout<<"NIE"; } else { cout<<"TAK\n"<<ind + 1; } } else if(b == 3) { int ind = 0; for(int i = 1; i < a - 1; i++) { if(tab[i] <= tab[0] or tab[i] >= tab[a-1]) { ind = i; break; } } if(ind == 0) { cout<<"NIE"; } else { cout<<"TAK\n"<<ind<<" "<<ind + 1; } } else { int ind = -1; { for(int i = 0; i < a - 1; i++) { if(tab[i] >= tab[i + 1]) { ind = i; break; } } if(ind == -1) { cout<<"NIE"; } else { cout<<"TAK\n"; b--; for(int i = 1; i < a; i++) { if(i == ind || i == ind + 1 || i == ind + 2) { cout<<i<<" "; b--; } else if(((i >(ind + 2))&&(b > 0))||((i < ind)&&(b > 3))) { cout<<i<<" "; b--; } if(b == 0) { break; } } } } } }
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 | #include <iostream> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin>>a>>b; int tab[a]; for(int i = 0; i < a; i++) { cin>>tab[i]; } if(b == 2) { int c = tab[0], d = tab[0], ind = 0; for(int i = 1; i < a; i++) { if(tab[i] < d) d = tab[i]; else if(tab[i] > c) { c = d; ind = i; } } if(ind == a - 1) { cout<<"NIE"; } else { cout<<"TAK\n"<<ind + 1; } } else if(b == 3) { int ind = 0; for(int i = 1; i < a - 1; i++) { if(tab[i] <= tab[0] or tab[i] >= tab[a-1]) { ind = i; break; } } if(ind == 0) { cout<<"NIE"; } else { cout<<"TAK\n"<<ind<<" "<<ind + 1; } } else { int ind = -1; { for(int i = 0; i < a - 1; i++) { if(tab[i] >= tab[i + 1]) { ind = i; break; } } if(ind == -1) { cout<<"NIE"; } else { cout<<"TAK\n"; b--; for(int i = 1; i < a; i++) { if(i == ind || i == ind + 1 || i == ind + 2) { cout<<i<<" "; b--; } else if(((i >(ind + 2))&&(b > 0))||((i < ind)&&(b > 3))) { cout<<i<<" "; b--; } if(b == 0) { break; } } } } } } |