#include <stdio.h> #include <string> #include <iostream> using namespace std; int main(){ long long int n; scanf("%lld\n", &n); long long int values [n]; long long int results [n]; scanf("%lld", &values[0]); results[0] = values[0]; // generate for (int idx = 1; idx < n; ++idx) { scanf("%lld", &values[idx]); results[idx] = values[idx] - values[idx-1]; } //check for (int idx = 0; idx < n; ++idx) { long long int val = 0; for (int inIdx = 0; inIdx <= idx; ++inIdx){ val += results[inIdx]; } if (val > values[idx]) { printf("NIE\n"); return 0; } for (int inIdx = idx + 1; inIdx < n; ++inIdx){ val += results[inIdx]; val -= results[inIdx-idx-1]; if (val > values[idx]) { printf("NIE\n"); return 0; } } } // print printf("TAK\n"); printf("%lld\n", n); for (int idx = 0; idx < n; ++idx) { printf("%lld ", results[idx]); } printf("\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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <stdio.h> #include <string> #include <iostream> using namespace std; int main(){ long long int n; scanf("%lld\n", &n); long long int values [n]; long long int results [n]; scanf("%lld", &values[0]); results[0] = values[0]; // generate for (int idx = 1; idx < n; ++idx) { scanf("%lld", &values[idx]); results[idx] = values[idx] - values[idx-1]; } //check for (int idx = 0; idx < n; ++idx) { long long int val = 0; for (int inIdx = 0; inIdx <= idx; ++inIdx){ val += results[inIdx]; } if (val > values[idx]) { printf("NIE\n"); return 0; } for (int inIdx = idx + 1; inIdx < n; ++inIdx){ val += results[inIdx]; val -= results[inIdx-idx-1]; if (val > values[idx]) { printf("NIE\n"); return 0; } } } // print printf("TAK\n"); printf("%lld\n", n); for (int idx = 0; idx < n; ++idx) { printf("%lld ", results[idx]); } printf("\n"); return 0; } |