#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
if(k == 2){
// two multisets
multiset<int> l, r;
for(int i = 0; i < n; i++){
r.insert(a[i]);
}
for(int i = 0; i + 1 < n; i++){
r.erase(r.find(a[i]));
l.insert(a[i]);
if(*l.begin() >= *r.rbegin()){
cout << "TAK\n" << i + 1 << '\n';
return 0;
}
}
cout << "NIE\n";
}else if(k == 3){
// two multisets and middle element
multiset<int> l, r;
for(int i = 2; i < n; i++){
r.insert(a[i]);
}
l.insert(a[0]);
for(int i = 1; i + 1 < n; i++){
if(*l.begin() >= a[i] or a[i] >= *r.rbegin()){
cout << "TAK\n" << i << ' ' << i + 1 << '\n';
return 0;
}
l.insert(a[i]);
r.erase(r.find(a[i + 1]));
}
cout << "NIE\n";
}else{
// two elements
int ans = -1;
for(int i = 1; i < n; i++){
if(a[i - 1] >= a[i]){
cout << "TAK\n";
ans = i;
break;
}
}
if(ans == -1){
cout << "NIE\n";
return 0;
}
set<int> s;
if(ans == 1){
s.insert(1);
s.insert(2);
}else{
s.insert(ans - 1);
s.insert(ans);
s.insert(ans + 1);
}
int x = 1;
while(s.size() < k - 1){
s.insert(x);
x++;
}
for(int i : s){
cout << i << ' ';
}
cout << '\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 | #include <bits/stdc++.h> using namespace std; int main(){ int n, k; cin >> n >> k; vector<int> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } if(k == 2){ // two multisets multiset<int> l, r; for(int i = 0; i < n; i++){ r.insert(a[i]); } for(int i = 0; i + 1 < n; i++){ r.erase(r.find(a[i])); l.insert(a[i]); if(*l.begin() >= *r.rbegin()){ cout << "TAK\n" << i + 1 << '\n'; return 0; } } cout << "NIE\n"; }else if(k == 3){ // two multisets and middle element multiset<int> l, r; for(int i = 2; i < n; i++){ r.insert(a[i]); } l.insert(a[0]); for(int i = 1; i + 1 < n; i++){ if(*l.begin() >= a[i] or a[i] >= *r.rbegin()){ cout << "TAK\n" << i << ' ' << i + 1 << '\n'; return 0; } l.insert(a[i]); r.erase(r.find(a[i + 1])); } cout << "NIE\n"; }else{ // two elements int ans = -1; for(int i = 1; i < n; i++){ if(a[i - 1] >= a[i]){ cout << "TAK\n"; ans = i; break; } } if(ans == -1){ cout << "NIE\n"; return 0; } set<int> s; if(ans == 1){ s.insert(1); s.insert(2); }else{ s.insert(ans - 1); s.insert(ans); s.insert(ans + 1); } int x = 1; while(s.size() < k - 1){ s.insert(x); x++; } for(int i : s){ cout << i << ' '; } cout << '\n'; } return 0; } |
English