#include <cstdio> #include <vector> int main() { int n; scanf("%d", &n); std::vector<int> t; t.reserve(n); int v; for (int i = 0; i < n; ++i) { scanf("%d", &v); t.emplace_back(v); } bool solution = true; for (int i = 1; i < n; ++i) for (int j = i/2; i - j - 1 >= 0; ++j) { if (t[i] > t[j] + t[i-j-1]) { solution = false; // printf("i: %d j: %d t[i]: %d > t[j]: %d + t[i-j-1]: %d\n", i, j, t[i], t[j], t[i-j-1]); goto nosolution; } } printf("TAK\n%d\n", n); printf("%d", t[0]); for (int i = 1; i < n; ++i) { printf(" %d", t[i] - t[i-1]); } printf("\n"); return 0; nosolution: printf("NIE\n"); return 0; }
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 | #include <cstdio> #include <vector> int main() { int n; scanf("%d", &n); std::vector<int> t; t.reserve(n); int v; for (int i = 0; i < n; ++i) { scanf("%d", &v); t.emplace_back(v); } bool solution = true; for (int i = 1; i < n; ++i) for (int j = i/2; i - j - 1 >= 0; ++j) { if (t[i] > t[j] + t[i-j-1]) { solution = false; // printf("i: %d j: %d t[i]: %d > t[j]: %d + t[i-j-1]: %d\n", i, j, t[i], t[j], t[i-j-1]); goto nosolution; } } printf("TAK\n%d\n", n); printf("%d", t[0]); for (int i = 1; i < n; ++i) { printf(" %d", t[i] - t[i-1]); } printf("\n"); return 0; nosolution: printf("NIE\n"); return 0; } |