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 ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n;
cin>>n;
ll a[n+1],pre[n+1];
pre[0]=0;
for(int i=0;i<n;i++){
cin>>a[i+1];
pre[i+1]=pre[i]+a[i+1];
}
ll dp[n+1][n+1];
int idx[n+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
dp[i][j]=1e18;
}
idx[i]=1e9;
}
dp[0][0]=0;
idx[0]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(idx[j-1]>=i)continue;
if(pre[i]-pre[idx[j-1]]<dp[idx[j-1]][j-1])continue;
int l=1,r=i-idx[j-1];
while(l<r){
int m=(l+r)/2;
if(pre[i]-pre[i-m]>=dp[i-m][j-1])r=m;
else l=m+1;
}
dp[i][j]=pre[i]-pre[i-l];
idx[j]=min(idx[j],i);
}
}
ll ans=0;
for(int i=1;i<=n;i++){
if(dp[n][i]<1e18)ans=i;
}
cout<<ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | 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... |