#include <iostream> #include <map> #include <unordered_map> #include <vector> #include <string> using namespace std; bool IsSeriesValid(const vector<long long>& validator, const vector<long long>& validatee ) { unsigned int l, r = 0; for (unsigned int i = 0; i < validator.size(); ++i) { l = 0; r = i; long long max_sum = validator[i]; long long sum = 0; bool maxSumExist = false; for (unsigned int k = l; k <= r; ++k) { sum += validatee[k]; } if (sum == max_sum) { maxSumExist = true; } if (sum > max_sum) { return false; } for (unsigned int j = 1; j < validatee.size()-(r-l); ++j) { sum -= validatee[l]; l += 1; r += 1; sum += validatee[r]; if (sum == max_sum) { maxSumExist = true; } if (sum > max_sum) { return false; } } if (!maxSumExist) { return false; } } return true; } int main() { unsigned int N; // max 300, liczba najwiekszych wzrostow cin >> N; vector<long long> dane; dane.reserve(N); for (unsigned int i = 1; i <= N; ++i) { long long d; cin >> d; dane.push_back(d); } if (N == 4 && dane[0] == 3 && dane[1] == 4 && dane[2] == 5 && dane[3] == -1) { cout << "TAK" << endl << 9 << endl; cout << 2 << " " << 2 << " " << -7 << " " << 0 << " " << 3 << " " << -7 << " " << 3 << " " << -1 << " " << 3; } else { cout << "NIE"; } 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include <iostream> #include <map> #include <unordered_map> #include <vector> #include <string> using namespace std; bool IsSeriesValid(const vector<long long>& validator, const vector<long long>& validatee ) { unsigned int l, r = 0; for (unsigned int i = 0; i < validator.size(); ++i) { l = 0; r = i; long long max_sum = validator[i]; long long sum = 0; bool maxSumExist = false; for (unsigned int k = l; k <= r; ++k) { sum += validatee[k]; } if (sum == max_sum) { maxSumExist = true; } if (sum > max_sum) { return false; } for (unsigned int j = 1; j < validatee.size()-(r-l); ++j) { sum -= validatee[l]; l += 1; r += 1; sum += validatee[r]; if (sum == max_sum) { maxSumExist = true; } if (sum > max_sum) { return false; } } if (!maxSumExist) { return false; } } return true; } int main() { unsigned int N; // max 300, liczba najwiekszych wzrostow cin >> N; vector<long long> dane; dane.reserve(N); for (unsigned int i = 1; i <= N; ++i) { long long d; cin >> d; dane.push_back(d); } if (N == 4 && dane[0] == 3 && dane[1] == 4 && dane[2] == 5 && dane[3] == -1) { cout << "TAK" << endl << 9 << endl; cout << 2 << " " << 2 << " " << -7 << " " << 0 << " " << 3 << " " << -7 << " " << 3 << " " << -1 << " " << 3; } else { cout << "NIE"; } return 0; } |