This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("inline","03")
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define ins insert
#define pb push_back
#define int long long
#define endl '\n'
/*
m : 11059739 -> l ~23
p : 4567896467
*/
const int mod = 1e9 +7, sze=2*1e5,inf=LLONG_MAX, prime = 2333;
void gkd(){
int n;
cin>>n;
vector<int> ps(n+1);
vector<int> arr(n+1);
for(int i=1;i<=n;i++){
cin>>arr[i];
ps[i]+=ps[i-1]+arr[i];
}
vector<int> dp(n+10),from(n+10);
for(int i=1;i<=n;i++){
from[i]=max(from[i],from[i-1]);
dp[i]=dp[from[i]]+1;
int t= lower_bound(all(ps),ps[i]*2 - ps[from[i]]) -ps.begin();
// cout<<t<<" -> "<<i<<" "<<dp[i]<<" ! "<<ps[i]*2 <<" "<< ps[from[i]]<<endl;
from[t]=i;
}
cout<<dp[n]<<endl;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int tt=1;
// cin>>tt;
while(tt--) gkd();
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... |