#include<bits/stdc++.h> #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int MN = 500009, INF = 1000000009; int tab[MN]; int minpref[MN]; int maxsuf[MN]; int n, k; bool inc = 1; void read(){ cin >> n >> k; cin >> tab[1]; minpref[1] = tab[1]; for(int i =2; i <= n; i++){ cin >> tab[i]; if(tab[i-1] >= tab[i]) inc = 0; minpref[i] = min(minpref[i-1], tab[i]); } maxsuf[n] = tab[n]; for(int i = n-1 ; i >0; i--) maxsuf[i] = max(tab[i], maxsuf[i+1]); } set <int> pos; void solveforbigk(){ if(inc){ cout << "NIE"; return; } int ind; for(int i = 1; i < n ; i++){ if(tab[i] >= tab[i+1]){ ind = i; break; } } for(int i = -1; i < 2; i++){ if(ind + i >= 1 && ind + i <= n) pos.insert(ind + i); } pos.insert(n); int zost = k - sz(pos); for(int i = 1; i <= n && zost > 0; i++){ if(pos.find(i) == pos.end() ){ zost--; pos.insert(i); } } cout << "TAK\n"; int put = 0; for(auto x : pos){ cout << x << ' '; if(++put == k-1) break; } } void solvefork2(){ bool found = 0; int gdzie; for(int i = 1; i < n && !found; i++){ if(minpref[i] >= maxsuf[i+1]){ found = 1; gdzie = i; } } if(found){ cout << "TAK\n"; cout << gdzie ; } else cout << "NIE"; } void solvefork3(){ int gdzie; bool found = 0; for(int i = 2; i < n && !found; i++){ if(minpref[i-1] >= tab[i] || minpref[i-1] >= maxsuf[i+1] || tab[i] >= maxsuf[i+1]){ found = 1 ; gdzie = i; } } if(found){ cout << "TAK\n"; cout << gdzie-1 << ' ' << gdzie ; } else cout << "NIE"; } int main(){ BOOST read(); if(k == 2){ solvefork2(); return 0 ; } if(k == 3){ solvefork3(); return 0 ; } if(k >= 4){ solveforbigk(); 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 | #include<bits/stdc++.h> #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); const int MN = 500009, INF = 1000000009; int tab[MN]; int minpref[MN]; int maxsuf[MN]; int n, k; bool inc = 1; void read(){ cin >> n >> k; cin >> tab[1]; minpref[1] = tab[1]; for(int i =2; i <= n; i++){ cin >> tab[i]; if(tab[i-1] >= tab[i]) inc = 0; minpref[i] = min(minpref[i-1], tab[i]); } maxsuf[n] = tab[n]; for(int i = n-1 ; i >0; i--) maxsuf[i] = max(tab[i], maxsuf[i+1]); } set <int> pos; void solveforbigk(){ if(inc){ cout << "NIE"; return; } int ind; for(int i = 1; i < n ; i++){ if(tab[i] >= tab[i+1]){ ind = i; break; } } for(int i = -1; i < 2; i++){ if(ind + i >= 1 && ind + i <= n) pos.insert(ind + i); } pos.insert(n); int zost = k - sz(pos); for(int i = 1; i <= n && zost > 0; i++){ if(pos.find(i) == pos.end() ){ zost--; pos.insert(i); } } cout << "TAK\n"; int put = 0; for(auto x : pos){ cout << x << ' '; if(++put == k-1) break; } } void solvefork2(){ bool found = 0; int gdzie; for(int i = 1; i < n && !found; i++){ if(minpref[i] >= maxsuf[i+1]){ found = 1; gdzie = i; } } if(found){ cout << "TAK\n"; cout << gdzie ; } else cout << "NIE"; } void solvefork3(){ int gdzie; bool found = 0; for(int i = 2; i < n && !found; i++){ if(minpref[i-1] >= tab[i] || minpref[i-1] >= maxsuf[i+1] || tab[i] >= maxsuf[i+1]){ found = 1 ; gdzie = i; } } if(found){ cout << "TAK\n"; cout << gdzie-1 << ' ' << gdzie ; } else cout << "NIE"; } int main(){ BOOST read(); if(k == 2){ solvefork2(); return 0 ; } if(k == 3){ solvefork3(); return 0 ; } if(k >= 4){ solveforbigk(); return 0 ; } } |