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 fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,i,a[100005],opt;
long long pre[100005];
pair<int,long long> dp[100005];
priority_queue<pair<long long,int>> q;
cin>>n;
for (i=1;i<n+1;i++) cin>>a[i];
pre[1]=a[1];
for (i=2;i<n+1;i++) pre[i]=pre[i-1]+a[i];
q.push({-1e18,0});
dp[1]={1,-a[1]};
q.push({-a[1]-pre[1], 1});
opt=0;
for (i=2;i<n+1;i++)
{
dp[i]={1,-pre[i]};
while (abs(q.top().fi)<=pre[i])
{
opt=max(q.top().se, opt);
q.pop();
}
if (opt!=0) dp[i]=max(dp[i], {dp[opt].fi+1, -pre[i]+pre[opt]});
q.push({dp[i].se-pre[i], i});
}
// for (i=1;i<n+1;i++) cout<<dp[i].fi<<" "<<dp[i].se<<"\n";
cout<<dp[n].fi;
}
# | 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... |