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>
#define ll long long
#define f first
#define s second
const int N=5e5+10;
using namespace std;
int n,pre[N],dp[N];
ll a[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=1; i<=n; i++)
{
pre[i]=max(pre[i],pre[i-1]);
dp[i]=dp[pre[i]]+1;
ll val=a[i]-a[pre[i]];
int nxt=lower_bound(a+1,a+n+1,val+a[i])-a;
pre[nxt]=i;
}
cout<<dp[n];
}
# | 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... |