#include <cstdio> #include <vector> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) int n; vector<int> M, S; int main() { scanf("%d", &n); M.resize(n+1); FOR(i,1,n+1) scanf("%d", &M[i]); FOR(i,1,n+1) { int origin = M[i]; FOR(j,1,i) M[i] = min(M[i], M[j] + M[i-j]); if (origin != M[i]) { printf("NIE\n"); return 0; } } int sum = M[1]; S.push_back(M[1]); FOR(i,2,n+1) S.push_back(M[i] - M[i-1]); printf("TAK\n"); printf("%d\n", S.size()); FOR(i,0,S.size()) printf("%d ", S[i]); printf("\n"); }
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 | #include <cstdio> #include <vector> using namespace std; #define FOR(i,a,b) for(int (i)=(int)(a); (i)!=(int)(b); ++(i)) int n; vector<int> M, S; int main() { scanf("%d", &n); M.resize(n+1); FOR(i,1,n+1) scanf("%d", &M[i]); FOR(i,1,n+1) { int origin = M[i]; FOR(j,1,i) M[i] = min(M[i], M[j] + M[i-j]); if (origin != M[i]) { printf("NIE\n"); return 0; } } int sum = M[1]; S.push_back(M[1]); FOR(i,2,n+1) S.push_back(M[i] - M[i-1]); printf("TAK\n"); printf("%d\n", S.size()); FOR(i,0,S.size()) printf("%d ", S[i]); printf("\n"); } |