#include <bits/stdc++.h>
using namespace std;
long long n;
long long s;
vector<long long> a;
vector<long long> pot;
bool check(long long x) {
vector<long long> us(2 * n, 0);
long long cur = 0;
for (long long i = 0; i < n; i++) {
if (a[i] > cur) {
if (i + x > n) return 0;
us[i + x - 1] = (a[i] - cur);
cur = a[i];
}
else if (cur > a[i]) return 0;
cur -= us[i];
}
return 1;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (long long i = 0; i < n; i++) {
long long b;
cin >> b;
s += b;
a.push_back(b);
}
for (long long i = 1; i <= n; i++) {
if (s % i == 0) {
pot.push_back(i);
}
}
while (pot.size()) {
long long tp = pot.back();
pot.pop_back();
if (check(tp)) {
cout << tp;
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 | #include <bits/stdc++.h> using namespace std; long long n; long long s; vector<long long> a; vector<long long> pot; bool check(long long x) { vector<long long> us(2 * n, 0); long long cur = 0; for (long long i = 0; i < n; i++) { if (a[i] > cur) { if (i + x > n) return 0; us[i + x - 1] = (a[i] - cur); cur = a[i]; } else if (cur > a[i]) return 0; cur -= us[i]; } return 1; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (long long i = 0; i < n; i++) { long long b; cin >> b; s += b; a.push_back(b); } for (long long i = 1; i <= n; i++) { if (s % i == 0) { pot.push_back(i); } } while (pot.size()) { long long tp = pot.back(); pot.pop_back(); if (check(tp)) { cout << tp; return 0; } } } |
English