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
#include <iostream>
   #include <stdio.h>
   using namespace std;

  int resultSize = 0;
  int result[100001];

  int smaller(int a, int b) {
    return a < b ? a : b;
  }

  int main() {

    int n;
    int limit[301];
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> limit[i];
    }

    for (int targetSize = 1; targetSize <= n; targetSize++) {
      int globalMax = limit[1];

      int sum = 0;
      for (int verify = 2; verify <= targetSize; verify++) {
        sum += result[resultSize - verify + 1];
        int localMax = limit[verify] - sum;
        globalMax = smaller(globalMax, localMax);
      }

      if (sum + globalMax < limit[targetSize]) {
        printf("%s", "NIE");
        return 0;
      }
      result[resultSize++] = globalMax;
    }

    printf("%s\n", "TAK");
    printf("%d\n", resultSize);
    for (int i = 0; i < resultSize; i++) {
      printf("%d ", result[i]);
    }
    return 0;
  }