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
#include <bits/stdc++.h>
using namespace std;

int n;
int T[302];
int K[302];
vector<pair<int, int> >P;

bool F(pair<int, int> A, pair<int, int> B)
{
    return A.first*B.second<B.first*A.second;
}

int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/

    cin>>n;

    for (int i=1; i<=n; ++i)
        cin>>T[i];

    P.push_back(make_pair(T[1], 1));
    K[1]=T[1];

    for (int i=2, j=0; i<=n; ++i, j=0){
        sort(P.begin(), P.end(), F);
        //cout<<P[0].first<<" "<<P[0].second<<"\n";
        int k=i;
        while (k>0){
            //cout<<k<<"\n";
            if (P[j].second<=k){
                K[i]+=P[j].first;
                k-=P[j].second;
            }
            else j++;
        }
        if (T[i]>K[i]){
            cout<<"NIE\n";
            return 0;
        }
        P.push_back(make_pair(T[i], i));
        K[i]=T[i];
    }

    cout<<"TAK\n";
    cout<<n<<"\n";
    cout<<K[1]<<" ";
    for (int i=2; i<=n; ++i)
        cout<<K[i]-K[i-1]<<" ";

    return 0;
}