#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> v;
long max;
scanf("%ld", &max);
cout << max << endl;
vector<long> orig;
v.push_back(max);
long prev = max;
for (int i = 2; i <= n; i++) {
long diff;
scanf("%ld", &diff);
orig.push_back(diff);
long curr = diff - prev;
if (curr > max) {
cout << "NIE" << '\n';
return 0;
}
v.push_back(curr);
prev = diff;
}
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
if (v[j] - v[i] > orig[j-i]) {
cout << "NIE" << '\n';
return 0;
}
}
}
printf("TAK\n%zu\n", v.size());
for (long el : v) {
printf("%ld ", el);
}
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 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long n; cin >> n; vector<long> v; long max; scanf("%ld", &max); cout << max << endl; vector<long> orig; v.push_back(max); long prev = max; for (int i = 2; i <= n; i++) { long diff; scanf("%ld", &diff); orig.push_back(diff); long curr = diff - prev; if (curr > max) { cout << "NIE" << '\n'; return 0; } v.push_back(curr); prev = diff; } for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { if (v[j] - v[i] > orig[j-i]) { cout << "NIE" << '\n'; return 0; } } } printf("TAK\n%zu\n", v.size()); for (long el : v) { printf("%ld ", el); } printf("\n"); } |
English