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
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    cin.sync_with_stdio(0);
    int n;
    vector<int> a;
    cin >> n;
    a.resize(n+1);
    for(int i=1; i<=n; ++i)
    {
        cin >> a[i];
    }

    vector<long long int> result;
    result.reserve(100000);

    result.push_back(a[1]);

    for(int curr_n=2; curr_n<=n; ++curr_n)
    {
        result.push_back(-10'000'000'000'000LL);// separator
        long long int total_sum = 0;
        for(int pos=0; pos<curr_n; ++pos)
        {
            int minimum = a[1];
            int sum = 0;
            for(int j=pos-1, k=2; j>=0; --j,++k)
            {
                sum += result[result.size()-1-(k-2)];
                int new_min = a[k]-sum;
                minimum = min(minimum,new_min);
            }

            result.push_back(minimum);
            total_sum += minimum;
        }
        if(total_sum<a[curr_n])
        {
            cout << "NIE";
            return 0;
        }
        else
        {
            result[result.size()-1] -= total_sum-a[curr_n];
        }
    }
    cout << "TAK" << endl;
    cout << result.size() << endl;
    cout << result[0];
    for(unsigned int i=1; i<result.size(); ++i)
    {
        cout << " " << result[i];
    }

    /////////////////
    /*for(int k=1; k<=n;++k)
    {
        bool max_found = false;
        for(int i=0; i+k-1<result.size(); ++i)
        {
            long long int sum = 0;
            for(int j=i; j<i+k; ++j)
            {
                sum += result[j];
            }
            if(sum>a[k])
            {
                cout << "ERROR" << endl;
                return 1;
            }
            else if(sum==a[k])
            {
                max_found = true;
            }
        }
        if(!max_found)
        {
            cout << "ERROR max not found" << endl;
            return 1;
        }
    }*/
    return 0;
}