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 pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define N 500005
#define INF 1e9+5
#define sp " "
#define nl "\n"
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) (x).begin(),(x).end()
#define ll long long
#define int ll
using namespace std;
int n,a[N],pre[N],dp[N],mx[N],idx;
int32_t main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
pre[i]=pre[i-1]+a[i];
}
for(int i=1;i<=n;i++){
mx[i]=max(mx[i],mx[i-1]);
dp[i]=max(dp[i-1],dp[mx[i]]+1);
idx=lower_bound(pre,pre+n+1,2*pre[i]-pre[mx[i]])-pre;
mx[idx]=max(mx[idx],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... |