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>
#include<vector>
#define endl '\n'
using namespace std;
long long n,dp[500005],a,pr[500005],s[500005];
vector<long long> sum;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
sum.push_back(0);
for(int i=1;i<=n;i++)
{
cin>>a;
pr[i]=pr[i-1]+a;
sum.push_back(pr[i]);
s[i]=1000000000000000;
}
dp[1]=1;
s[1]=pr[1];
for(int i=1;i<=n;i++)
{
dp[i]=max(dp[i],dp[i-1]);
s[i]=min(s[i],s[i-1]+pr[i]-pr[i-1]);
long long in = lower_bound(sum.begin(),sum.end(),pr[i]+s[i])- sum.begin();
if(dp[in]==dp[i]+1)
{
s[in]=min(s[in],pr[in]-pr[i]);
}
else if(dp[in]<dp[i]+1)
{
dp[in]=dp[i]+1;
s[in]=pr[in]-pr[i];
}
}
cout<<dp[n]<<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... |