#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <set>
#include <list>
#include <queue>
#include <map>
#include <vector>
#include <stack>
constexpr int N = 1e6 + 7;
int t[N];
int zlicz[N];
std::set<int>s;
int main()
{
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n, k;
std::cin >> n >> k >> t[1];
bool bul = 1;
for (int i = 2; i <= n; ++i)
{
std::cin >> t[i];
if (t[i] <= t[i - 1])
{
bul = 0;
}
}
if (bul = 0 || k > n)
{
std::cout << "NIE";
return 0;
}
if (k >= 3)
{
int maks = 0;
int ind = -1;
for (int i = 1; i < n; ++i)
{
if (t[i] > maks)
{
maks = t[i];
ind = i;
}
}
if (ind != 1)
{
s.insert(ind - 1);
--k;
}
s.insert(ind);
k -= 2;
if (maks >= t[n])
{
int i = 1;
while (k > 0)
{
if (i != ind)
{
s.insert(i);
}
++i;
--k;
}
std::cout << "TAK\n";
for (auto i : s)
{
std::cout << i << ' ';
}
}
else
std::cout << "NIE";
}
else if (k == 2)
{
int mini = t[n];
int maks = mini;
int ind = -1;
std::set<int>sett;
for (int i = 1; i < n; ++i)
{
++zlicz[t[i]];
sett.insert(t[i]);
}
for (int i = n - 1; i >= 1; --i)
{
auto itk = sett.end();
--itk;
auto itp = sett.begin();
if ( maks <= *itp)
{
ind = i;
break;
}
else
{
int x = t[i];
--zlicz[t[i]];
if (zlicz[t[i]] == 0)
{
sett.erase(x);
}
mini = std::min(mini, x);
maks = std::max(maks, x);
}
}
if (ind != -1)
std::cout << "TAK\n" << ind;
else
std::cout << "NIE";
}
}
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 | #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <iomanip> #include <set> #include <list> #include <queue> #include <map> #include <vector> #include <stack> constexpr int N = 1e6 + 7; int t[N]; int zlicz[N]; std::set<int>s; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int n, k; std::cin >> n >> k >> t[1]; bool bul = 1; for (int i = 2; i <= n; ++i) { std::cin >> t[i]; if (t[i] <= t[i - 1]) { bul = 0; } } if (bul = 0 || k > n) { std::cout << "NIE"; return 0; } if (k >= 3) { int maks = 0; int ind = -1; for (int i = 1; i < n; ++i) { if (t[i] > maks) { maks = t[i]; ind = i; } } if (ind != 1) { s.insert(ind - 1); --k; } s.insert(ind); k -= 2; if (maks >= t[n]) { int i = 1; while (k > 0) { if (i != ind) { s.insert(i); } ++i; --k; } std::cout << "TAK\n"; for (auto i : s) { std::cout << i << ' '; } } else std::cout << "NIE"; } else if (k == 2) { int mini = t[n]; int maks = mini; int ind = -1; std::set<int>sett; for (int i = 1; i < n; ++i) { ++zlicz[t[i]]; sett.insert(t[i]); } for (int i = n - 1; i >= 1; --i) { auto itk = sett.end(); --itk; auto itp = sett.begin(); if ( maks <= *itp) { ind = i; break; } else { int x = t[i]; --zlicz[t[i]]; if (zlicz[t[i]] == 0) { sett.erase(x); } mini = std::min(mini, x); maks = std::max(maks, x); } } if (ind != -1) std::cout << "TAK\n" << ind; else std::cout << "NIE"; } } |
English