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;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,dp[3009],dp2[3009],f[3009],jm[3009],lef,rig,mid;
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a;
for(i=1; i<=a; i++){
cin>>f[i];jm[i]=jm[i-1]+f[i];
}
dp[1]=1;dp2[1]=jm[1];
for(i=2; i<=a; i++){
dp[i]=1;dp2[i]=jm[i];
/*for(j=i-1; j>=1; j--){
if(dp2[j]<=jm[i]-jm[j]){
if(dp[i]<dp[j]+1||(dp[i]==dp[j]+1&&dp2[i]>jm[i]-jm[j])){
dp[i]=dp[j]+1;dp2[i]=jm[i]-jm[j];
}
}
}*/
lef=0;rig=a;
while(1){
if(lef+1>=rig) break;
mid=(lef+rig)/2;
if(dp2[mid]+jm[mid]<=jm[i]){
lef=mid;
}else{
rig=mid;
}
}
if(lef!=0){
dp[i]=dp[lef]+1;dp2[i]=jm[i]-jm[lef];
}
}
cout<<dp[a];
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... |