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

using namespace std;

bool sprawdz( vector< int > const& sumy_wspak, vector< int > zadane ) {
	for( int i = 0; i < sumy_wspak.size(); ++i ) {
		int j = sumy_wspak.size() - 1 - i;
		if(sumy_wspak[j] > zadane[i]) {
			return false;
		}
	}
	return true;
}

bool wstaw(vector< int >& ciag, vector< int >& zadane, vector< int >& sumy_wspak, int zmiana) {
	int potrzebuje = (sumy_wspak.size() == 0) ? zmiana : zmiana - sumy_wspak[0];

	zadane.push_back( zmiana );
	sumy_wspak.push_back(0);
	for( auto& s : sumy_wspak ) {
		s += potrzebuje;
	}

	bool ok = sprawdz( sumy_wspak, zadane );
	if( ok ) {
		ciag.push_back( potrzebuje );
	}

	return ok;
}

int main() {
	int ile; cin >> ile;
	vector< int > zadane;
	vector< int > ciag;
	vector< int > sumy_wspak;

	for (int i = 0; i < ile; ++i) {
		int zmiana; cin >> zmiana;

		if(! wstaw(ciag, zadane, sumy_wspak, zmiana) ) {
			break;
		};
	}

	if( ciag.size() == ile ) {
		cout << "TAK\n";
		cout << ciag.size() << "\n";
		for( int i = 0; i < ciag.size(); ++i ) {
			cout << ciag[i];
			cout << ( (i < ciag.size() - 1) ? " " : "\n" );
		}
	}
	else {
		cout << "NIE\n";
	}

	return 0;
}