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;
typedef long long LL;
const int maxn=5e5+5;
LL n,a[maxn],f[maxn],sum[maxn],ans;
inline LL rad(){
int ret=0,flg=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-')flg=-1;ch=getchar();}
while (isdigit(ch))ret=ret*10+ch-'0',ch=getchar();
return ret*flg;
}
int main (){
n=rad();
for (int i=1;i<=n;i++)sum[i]=sum[i-1]+rad();
for (int i=1;i<=n;i++){
f[i]=max(f[i],f[i-1]);
LL tmp=sum[i]-sum[f[i]];
int lp=lower_bound(sum+1,sum+1+n,sum[i]+tmp)-sum;
f[lp]=i;
}
for (int i=n;i;i=f[i])ans++;
printf("%lld\n",ans);
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... |