#include <iostream> using namespace std; const int MAX_N = 500009; const int INF = 1020000009; int min_val_from_left[MAX_N]; int input[MAX_N]; int fast_read(){ char c; int w = 0; c = getchar_unlocked(); while(c < '0' or c > '9') c = getchar_unlocked(); while('9'>= c and c>= '0'){ w = w * 10 + (c - '0'); c = getchar_unlocked(); } return w; } int main() { int n,k; //cin>>n>>k; n = fast_read(); k = fast_read(); int last, cur; if(k >= 4){ //cin>>last; last = fast_read(); bool FIRE_HIM = false; int first, second; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); if(last >= cur){ FIRE_HIM = true; first = i; second = i+1; break; } last = cur; } if(!FIRE_HIM) cout<<"NIE"; else{ cout<<"TAK\n"; for(int i = 1; i <= k - 4; i++){ cout<<i<<" "; } if(k - 3 < first){ cout<<first - 1<<" "<<first<<" "<<second; } else if(k - 3 == first){ cout<<first<<" "<<second<<" "<<second + 1; } else if(k - 3 == second){ cout<<second<<" "<<second + 1<<" "<<second + 2; } else{ cout<<k-3<<" "<<k - 2<<" "<<k - 1; } } } else if(k == 2){ int maxx, minn; int cur; int poz; maxx = -INF; bool FIRE_HIM = false; //cin>>cur; cur = fast_read(); input[0] = cur; min_val_from_left[0] = cur; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); input[i] = cur; min_val_from_left[i] = min(min_val_from_left[i - 1], cur); } for(int i = n - 1; i > 0; i--){ maxx = max(input[i], maxx); if(maxx <= min_val_from_left[i - 1]){ FIRE_HIM =true; poz = i; break; } } if(!FIRE_HIM) cout<<"NIE"; else{ cout<<"TAK\n"; cout<<poz; } } else{/// K = 3 int minn = INF; int maxx = -INF; int cur; bool FIRE_HIM = false; //cin>>cur; cur = fast_read(); minn = min(minn, cur); input[0] = cur; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); input[i] = cur; if(cur <= minn){ FIRE_HIM = true; cout<<"TAK\n"; cout<<i<<" "<<i+1; return 0; } minn = min(minn, cur); } maxx = input[n - 1]; for(int i = n - 2; i >= 0; i--){ //cin>>cur; cur = input[i]; if(cur >= maxx){ FIRE_HIM = true; cout<<"TAK\n"; cout<<i<<" "<<i + 1; return 0; } maxx = max(maxx, cur); } cout<<"NIE"; } 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 157 158 159 160 161 162 163 164 165 | #include <iostream> using namespace std; const int MAX_N = 500009; const int INF = 1020000009; int min_val_from_left[MAX_N]; int input[MAX_N]; int fast_read(){ char c; int w = 0; c = getchar_unlocked(); while(c < '0' or c > '9') c = getchar_unlocked(); while('9'>= c and c>= '0'){ w = w * 10 + (c - '0'); c = getchar_unlocked(); } return w; } int main() { int n,k; //cin>>n>>k; n = fast_read(); k = fast_read(); int last, cur; if(k >= 4){ //cin>>last; last = fast_read(); bool FIRE_HIM = false; int first, second; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); if(last >= cur){ FIRE_HIM = true; first = i; second = i+1; break; } last = cur; } if(!FIRE_HIM) cout<<"NIE"; else{ cout<<"TAK\n"; for(int i = 1; i <= k - 4; i++){ cout<<i<<" "; } if(k - 3 < first){ cout<<first - 1<<" "<<first<<" "<<second; } else if(k - 3 == first){ cout<<first<<" "<<second<<" "<<second + 1; } else if(k - 3 == second){ cout<<second<<" "<<second + 1<<" "<<second + 2; } else{ cout<<k-3<<" "<<k - 2<<" "<<k - 1; } } } else if(k == 2){ int maxx, minn; int cur; int poz; maxx = -INF; bool FIRE_HIM = false; //cin>>cur; cur = fast_read(); input[0] = cur; min_val_from_left[0] = cur; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); input[i] = cur; min_val_from_left[i] = min(min_val_from_left[i - 1], cur); } for(int i = n - 1; i > 0; i--){ maxx = max(input[i], maxx); if(maxx <= min_val_from_left[i - 1]){ FIRE_HIM =true; poz = i; break; } } if(!FIRE_HIM) cout<<"NIE"; else{ cout<<"TAK\n"; cout<<poz; } } else{/// K = 3 int minn = INF; int maxx = -INF; int cur; bool FIRE_HIM = false; //cin>>cur; cur = fast_read(); minn = min(minn, cur); input[0] = cur; for(int i = 1; i < n; i++){ //cin>>cur; cur = fast_read(); input[i] = cur; if(cur <= minn){ FIRE_HIM = true; cout<<"TAK\n"; cout<<i<<" "<<i+1; return 0; } minn = min(minn, cur); } maxx = input[n - 1]; for(int i = n - 2; i >= 0; i--){ //cin>>cur; cur = input[i]; if(cur >= maxx){ FIRE_HIM = true; cout<<"TAK\n"; cout<<i<<" "<<i + 1; return 0; } maxx = max(maxx, cur); } cout<<"NIE"; } return 0; } |