Submission #746896

#TimeUsernameProblemLanguageResultExecution timeMemory
746896DenkataBigger segments (IZhO19_segments)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 5e5+3; int i,j,p,q,n,m,k; int uk,dp[maxn],cnt[maxn],a[maxn],sum; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; } uk = 1; dp[1] = a[1]; cnt[1] = 1; sum = a[1]; for(i=2;i<=n;i++) { sum+=a[i]; while(uk<=i && sum>=dp[uk-1]) { sum-=a[uk]; uk++; } uk--; sum+=a[uk]; dp[i] = sum; cnt[i] = cnt[uk-1]+1; // cout<<dp[i]<<" "<<cnt[i]<<endl; } cout<<cnt[n]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...