#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define TEST false
ll test(const vector<ll>& a, ll x) {
vector<ll> b;
b.reserve(a.size());
b.push_back(a[0]);
auto ret = true;
for (auto i=1; i<a.size(); i++) {
b.push_back(a[i] - a[i-1] + (i>=x?b[i-x]:0));
if (b.back()<0) {
ret = false;
#if !TEST
return false;
#endif
}
}
#if TEST
cout<<"Elements: "; for (auto i=1; i<a.size(); i++) { cout<<a[i]<<' '; } cout<<'\n';
cout<<"Begins : "; for (auto i=1; i<a.size(); i++) { cout<<b[i]<<' '; } cout<<'\n';
#endif
return ret;
}
vector<ll> podziel(ll x, ll m){
vector<ll> ret;
for (ll p=1; p*p<=x && p<=m; p++) {
if (x%p==0) {
ret.push_back(p);
if (m*p>=x) {ret.push_back(x/p);}
}
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, max=0, sum=0;
vector<ll> a;
cin >> n;
a.reserve(n+2);
a.push_back(0);
for (auto i=1;i<=n;i++) {
ll ax;
cin>>ax;
a.push_back(ax);
sum += ax;
if (ax>max) max = ax;
}
a.push_back(0);
vector<ll> dzielniki = podziel(sum, sum/max);
reverse(dzielniki.begin(), dzielniki.end());
for (auto i: dzielniki) {
auto wyn = test(a, i);
#if TEST
cout<<"TESTING: "<<i<<'\n';
cout<<wyn<<'\n';
cout<<'\n';
#endif
if (wyn) {
cout<<i<<'\n';
break;
}
}
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; #define TEST false ll test(const vector<ll>& a, ll x) { vector<ll> b; b.reserve(a.size()); b.push_back(a[0]); auto ret = true; for (auto i=1; i<a.size(); i++) { b.push_back(a[i] - a[i-1] + (i>=x?b[i-x]:0)); if (b.back()<0) { ret = false; #if !TEST return false; #endif } } #if TEST cout<<"Elements: "; for (auto i=1; i<a.size(); i++) { cout<<a[i]<<' '; } cout<<'\n'; cout<<"Begins : "; for (auto i=1; i<a.size(); i++) { cout<<b[i]<<' '; } cout<<'\n'; #endif return ret; } vector<ll> podziel(ll x, ll m){ vector<ll> ret; for (ll p=1; p*p<=x && p<=m; p++) { if (x%p==0) { ret.push_back(p); if (m*p>=x) {ret.push_back(x/p);} } } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, max=0, sum=0; vector<ll> a; cin >> n; a.reserve(n+2); a.push_back(0); for (auto i=1;i<=n;i++) { ll ax; cin>>ax; a.push_back(ax); sum += ax; if (ax>max) max = ax; } a.push_back(0); vector<ll> dzielniki = podziel(sum, sum/max); reverse(dzielniki.begin(), dzielniki.end()); for (auto i: dzielniki) { auto wyn = test(a, i); #if TEST cout<<"TESTING: "<<i<<'\n'; cout<<wyn<<'\n'; cout<<'\n'; #endif if (wyn) { cout<<i<<'\n'; break; } } return 0; } |
English