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
#include <iostream>
#include <vector>

int main() {
  std::uint32_t n;
  std::cin >> n;

  std::vector<std::int32_t> max_diff(n + 1);
  for (std::uint32_t i = 1; i <= n; ++i) {
    std::cin >> max_diff[i];
  }

  std::vector<std::int32_t> height(n + 1);
  height[0] = 0;
  for (std::uint32_t i = 1; i <= n; ++i) {
    height[i] = [&]() {
      std::int32_t min = 1e6;
      for (std::uint32_t j = 1; j <= i; ++j) {
        min = std::min(min, height[i - j] + max_diff[j]);
      }
      return min;
    }();

    if (height[i] < max_diff[i]) {
      std::cout << "NIE\n";
      return 0;
    }
  }

  std::cout << "TAK\n";
  std::cout << n;
  for (std::uint32_t i = 1; i <= n; ++i) {
    std::cout << (height[i] - height[i - 1]) << '\n';
  }

  return 0;
}