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;
typedef long long ll;
int n;
struct date
{
ll maxseg,maxprev;
} dp[500005];
ll v[500005],s[500005];
void update(int a,int b)
{
if(dp[a].maxseg<dp[b].maxseg)
dp[a]=dp[b];
else if(dp[a].maxseg==dp[b].maxseg&&dp[a].maxprev<dp[b].maxprev)
dp[a]=dp[b];
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>v[i];
s[i]=s[i-1]+v[i];
}
dp[1].maxseg=1;
dp[1].maxprev=1;
for(int i=1;i<=n;i++)
{
update(i,i-1);
int st=i+1;
int dr=n;
ll pozmin=n+1;
while(st<=dr)
{
int mij=(st+dr)/2;
ll suma=s[mij]-s[i];
if(suma>=s[i]-s[dp[i].maxprev-1])
{
pozmin=mij;
dr=mij-1;
}
else
st=mij+1;
}
if(pozmin<=n)
{
dp[n+1].maxseg=dp[i].maxseg+1;
dp[n+1].maxprev=i+1;
update(pozmin,n+1);
}
}
cout<<dp[n].maxseg;
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... |