Submission #334175

#TimeUsernameProblemLanguageResultExecution timeMemory
334175vipghn2003Bigger segments (IZhO19_segments)C++14
100 / 100
298 ms74732 KiB
#include<bits/stdc++.h> #define ll long long #define fi first #define se second #define pii pair<int,int> #define mp make_pair using namespace std; const int N=5e5+5; int n; ll a[N]; map<int,int>dp[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; a[i]+=a[i-1]; } dp[1][0]=0; for(int i=1;i<n;i++) { while(dp[i].size()>2) dp[i].erase(dp[i].begin()); for(auto&x:dp[i]) { dp[i+1][x.fi]=max(dp[i+1][x.fi],x.se); int v=lower_bound(a+1,a+n+1,2*a[i]-a[x.se])-a; if(v<=n) dp[v][x.fi+1]=max(dp[v][x.fi+1],i); } } while(dp[n].size()>1) dp[n].erase(dp[n].begin()); auto res=*dp[n].begin(); cout<<res.fi+1; }
#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...