#include <bits/stdc++.h> using namespace std; long long dane[301],wyn[301]; int main() { ios_base::sync_with_stdio(0); int n,mi,i,j,k; long long s; cin >> n; cin >> dane[0]; mi = s = dane[0]; for(i = 1; i < n; i++){ cin >> dane[i]; if(dane[i] - s > mi || dane[i] - s < -10000000000000 ) { cout <<"NIE"; return 0; } s = dane[i]; } wyn[0] = dane[0]; for(i = 1; i < n; i++){ wyn[i] = dane[i] - dane[i-1]; } for(i = 1; i < n; i++){ s = wyn[i]; for(j = i + 1,k = 1; j < n ; j++,k++){ s = s + wyn[j]; if(s > dane[k] ) { cout <<"NIE"; return 0; } } s = wyn[i]; for(j = i - 1,k = 1; j >= 0; j--,k++){ s = s + wyn[j]; if(s > dane[k] ) { cout <<"NIE"; return 0; } } } cout << "TAK" << endl << n << endl; for(i = 0; i < n; i++) cout << wyn[i] <<" "; 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 | #include <bits/stdc++.h> using namespace std; long long dane[301],wyn[301]; int main() { ios_base::sync_with_stdio(0); int n,mi,i,j,k; long long s; cin >> n; cin >> dane[0]; mi = s = dane[0]; for(i = 1; i < n; i++){ cin >> dane[i]; if(dane[i] - s > mi || dane[i] - s < -10000000000000 ) { cout <<"NIE"; return 0; } s = dane[i]; } wyn[0] = dane[0]; for(i = 1; i < n; i++){ wyn[i] = dane[i] - dane[i-1]; } for(i = 1; i < n; i++){ s = wyn[i]; for(j = i + 1,k = 1; j < n ; j++,k++){ s = s + wyn[j]; if(s > dane[k] ) { cout <<"NIE"; return 0; } } s = wyn[i]; for(j = i - 1,k = 1; j >= 0; j--,k++){ s = s + wyn[j]; if(s > dane[k] ) { cout <<"NIE"; return 0; } } } cout << "TAK" << endl << n << endl; for(i = 0; i < n; i++) cout << wyn[i] <<" "; return 0; } |