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<iostream>
#include<vector>
#include<utility>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<ll> vec(n),pre(n+1);
for(int i=0;i<n;i++) cin>>vec[i];
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+vec[i-1];
vector<pair<ll,int> > dp(n);
dp[0]=make_pair(vec[0],1);
int l=-1;
for(int i=1;i<n;i++){
while(l<i-1&&dp[l+1].first<=pre[i+1]-pre[l+2]) l++;
if(l==-1) dp[i]=make_pair(pre[i+1],1);
else dp[i]=make_pair(pre[i+1]-pre[l+1],dp[l].second+1);
//cout<<l<<" "<<dp[i].first<<" "<<dp[i].second<<"\n";
}
cout<<dp[n-1].second;
}
# | 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... |