#include <iostream>
#include <vector>
using namespace std;
// symulator
bool solve(const vector<long long>& p, int k)
{
int n = p.size();
vector<long long> diff(n + 1, 0);
long long active = 0;
for(int i = 0; i < n; i++)
{
active += diff[i];
if (i + k <= n)
{
if (active > p[i])
return false;
long long need = p[i] - active;
active += need;
diff[i + k] -= need;
}
else
{
if (active != p[i])
return false;
}
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<long long> p(n);
long long total_sum = 0;
for(int i = 0; i < n; i++)
{
cin >> p[i];
total_sum += p[i];
}
// fala k daje k bursztynow
// czyli musi byc dzielikiem
for (int k = n; k >= 1; k--)
{
if (total_sum % k != 0)
continue; // k nie jest dzielnikiem
if (solve(p, k))
{
cout << k << endl;
return 0;
}
}
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 | #include <iostream> #include <vector> using namespace std; // symulator bool solve(const vector<long long>& p, int k) { int n = p.size(); vector<long long> diff(n + 1, 0); long long active = 0; for(int i = 0; i < n; i++) { active += diff[i]; if (i + k <= n) { if (active > p[i]) return false; long long need = p[i] - active; active += need; diff[i + k] -= need; } else { if (active != p[i]) return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<long long> p(n); long long total_sum = 0; for(int i = 0; i < n; i++) { cin >> p[i]; total_sum += p[i]; } // fala k daje k bursztynow // czyli musi byc dzielikiem for (int k = n; k >= 1; k--) { if (total_sum % k != 0) continue; // k nie jest dzielnikiem if (solve(p, k)) { cout << k << endl; return 0; } } return 0; } |
English