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;
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
int main(){
fastio;
int n;
cin>>n;
ll pre[n+1];
pre[0]=0;
for(int i=1;i<=n;i++){
ll x;
cin>>x;
pre[i]=pre[i-1]+x;
}
ll ans=1;
for(int i=1;i<=n;i++){
ll last=pre[i],idx=i,cnt=1;
while(idx<n && last<=pre[n]-pre[idx]){
int lo=idx+1,hi=n;
while(hi-lo>1){
int mid=(lo+hi)>>1;
if(pre[mid]-pre[idx]>=last) hi=mid;
else lo=mid;
}
if(pre[lo]-pre[idx]>=last){
last=pre[lo]-pre[idx];
idx=lo;
cnt++;
}else if(pre[hi]-pre[idx]>=last){
last=pre[hi]-pre[idx];
idx=hi;
cnt++;
}else{
cnt++;
break;
}
}
ans=max(ans,cnt);
}
cout<<ans<<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... |