This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+3;
int i,j,p,q,n,m,k;
int uk,dp[maxn],cnt[maxn],a[maxn],sum;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
uk = 1;
dp[1] = a[1];
cnt[1] = 1;
sum = a[1];
for(i=2;i<=n;i++)
{
sum+=a[i];
while(uk<i && sum>=dp[uk-1])
{
sum-=a[uk];
uk++;
}
if(sum<dp[uk-1])
{
uk--;
sum+=a[uk];
}
dp[i] = sum;
cnt[i] = cnt[uk-1]+1;
if(cnt[i-1]>cnt[i])
{
cnt[i] = cnt[i-1];
dp[i] = dp[i-1]+a[i];
}
//cout<<dp[i]<<" "<<cnt[i]<<endl;
}
cout<<cnt[n]<<endl;
return 0;
}
# | 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... |