// pod.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
int main()
{
int len, divNum;
scanf("%d", &len);
scanf("%d", &divNum);
int* incomes = new int[len + 1];
bool* divisions = new bool[len + 1];
for (int i = 1; i <= len; i++)
{
scanf("%d", incomes + i);
divisions[i] = false;
}
if (divNum == 2)
{
//if 2 divisions min(a1,ai)<max(ai+1,an)
int* maxes = new int[len + 1];
for (int i = len, max = 0; i >= 1; i--)
{
maxes[i] = max = std::max(max, incomes[i]);
}
for (int i = 1, min = 1e9+7; i < len; i++)
{
min = std::min(min, incomes[i]);
if (min >= maxes[i + 1])
{
printf("TAK\n%d", i);
return 0;
}
}
printf("NIE");
return 0;
}
else if (divNum == 3)
{
//if 3 divisions each (a2...an-1)>a1 and <an
for (int i = 2; i < len; i++)
{
if (incomes[1] >= incomes[i] || incomes[i] >= incomes[len])
{
printf("TAK\n%d %d", i - 1, i);
return 0;
}
}
printf("NIE");
return 0;
}
else
{
//if 4 divisions ai<ai+1
int singularity = 0;
for (int i = 2, prev=incomes[1]; i<=len; i++)
{
if (prev >= incomes[i])
{
singularity = i;
break;
}
else
{
prev = incomes[i];
}
}
if (singularity == 0)
{
printf("NIE");
return 0;
}
else
{
if (singularity == len) singularity--;
if (singularity == 2) singularity++;
printf("TAK\n");
int usedDivs = 0;
for (int i = 1; i < singularity-2 && usedDivs < divNum-4; i++)
{
printf("%d ", i);
usedDivs++;
}
printf("%d ", singularity - 2);
usedDivs++;
printf("%d ", singularity - 1);
usedDivs++;
printf("%d ", singularity);
usedDivs++;
for (int i = singularity+1; i < len && usedDivs < divNum-1 ; i++)
{
printf("%d ", i);
usedDivs++;
}
}
}
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 | // pod.cpp : This file contains the 'main' function. Program execution begins and ends there. // #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <algorithm> int main() { int len, divNum; scanf("%d", &len); scanf("%d", &divNum); int* incomes = new int[len + 1]; bool* divisions = new bool[len + 1]; for (int i = 1; i <= len; i++) { scanf("%d", incomes + i); divisions[i] = false; } if (divNum == 2) { //if 2 divisions min(a1,ai)<max(ai+1,an) int* maxes = new int[len + 1]; for (int i = len, max = 0; i >= 1; i--) { maxes[i] = max = std::max(max, incomes[i]); } for (int i = 1, min = 1e9+7; i < len; i++) { min = std::min(min, incomes[i]); if (min >= maxes[i + 1]) { printf("TAK\n%d", i); return 0; } } printf("NIE"); return 0; } else if (divNum == 3) { //if 3 divisions each (a2...an-1)>a1 and <an for (int i = 2; i < len; i++) { if (incomes[1] >= incomes[i] || incomes[i] >= incomes[len]) { printf("TAK\n%d %d", i - 1, i); return 0; } } printf("NIE"); return 0; } else { //if 4 divisions ai<ai+1 int singularity = 0; for (int i = 2, prev=incomes[1]; i<=len; i++) { if (prev >= incomes[i]) { singularity = i; break; } else { prev = incomes[i]; } } if (singularity == 0) { printf("NIE"); return 0; } else { if (singularity == len) singularity--; if (singularity == 2) singularity++; printf("TAK\n"); int usedDivs = 0; for (int i = 1; i < singularity-2 && usedDivs < divNum-4; i++) { printf("%d ", i); usedDivs++; } printf("%d ", singularity - 2); usedDivs++; printf("%d ", singularity - 1); usedDivs++; printf("%d ", singularity); usedDivs++; for (int i = singularity+1; i < len && usedDivs < divNum-1 ; i++) { printf("%d ", i); usedDivs++; } } } return 0; } |
English