#include <iostream> using namespace std; int main() { int n, i, j; long wynik[300], diff[300], sum, a0; cin >> n; cin >> diff[0]; sum = a0 = wynik[i] = diff[i]; for (i = 1; i < n; i++) { cin >> diff[i]; if (diff[i] - diff[i - 1] > a0) { cout << "NIE"; return 0; } wynik[i] = diff[i] - sum; sum += wynik[i]; } for (i = 1; i < n - 1; i++) { sum = wynik[i]; for (j = i + 1; j < n; j++) { sum += wynik[j]; if (sum > diff[j - i]) { cout << "NIE"; return 0; } } } cout << "TAK" << endl; cout << n << endl; for (i = 0; i < n; i++) { cout << wynik[i]; if (i < n -1) cout << " "; } 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 | #include <iostream> using namespace std; int main() { int n, i, j; long wynik[300], diff[300], sum, a0; cin >> n; cin >> diff[0]; sum = a0 = wynik[i] = diff[i]; for (i = 1; i < n; i++) { cin >> diff[i]; if (diff[i] - diff[i - 1] > a0) { cout << "NIE"; return 0; } wynik[i] = diff[i] - sum; sum += wynik[i]; } for (i = 1; i < n - 1; i++) { sum = wynik[i]; for (j = i + 1; j < n; j++) { sum += wynik[j]; if (sum > diff[j - i]) { cout << "NIE"; return 0; } } } cout << "TAK" << endl; cout << n << endl; for (i = 0; i < n; i++) { cout << wynik[i]; if (i < n -1) cout << " "; } return 0; } |