#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l first
#define r second
const int N=1e3+100;
int a[N];
ll pre[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],pre[i]=pre[i-1]+a[i];
ll ans=0;
ll p=0;
vector<pair<int,int>> rng;
for(int i=1;i<=n;)
{
int sz=rng.size();
// cout<<"RANGES "<<i<<endl;
for(int j=sz-1;j>0;j--)
{
while(rng[j].l<rng[j].r and (pre[rng[j].r]-pre[rng[j].l]) >= (pre[rng[j].l]-pre[rng[j-1].l-1]))
{
rng[j].l++;
rng[j-1].r++;
}
}
// for(int j=0;j<sz;j++)
// {
// cout<<rng[j].l<<' '<<rng[j].r<<endl;
// }
if(rng.size()>0)
p=pre[rng.back().r]-pre[rng.back().l-1];
ll sm=a[i];
int j=i+1;
while(sm<p and j<=n)
{
sm+=a[j];
j++;
}
rng.push_back({i,j-1});// inc inc
if(sm<p)
{
break;
}
else
{
ans++;
p=sm;
i=j;
}
}
cout<<ans<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |