제출 #706894

#제출 시각아이디문제언어결과실행 시간메모리
706894ld_minh4354Bigger segments (IZhO19_segments)C++17
73 / 100
32 ms7892 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define debug(x) cout<<#x<<": "<<x<<"\n" signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // freopen("input.000","r",stdin); // freopen("output.000","w",stdout); // srand((unsigned)time(NULL)); // rand() int n,i,a[100005],opt; long long pre[100005]; pair<int,long long> dp[100005]; priority_queue<pair<long long,int>> q; cin>>n; for (i=1;i<n+1;i++) cin>>a[i]; pre[1]=a[1]; for (i=2;i<n+1;i++) pre[i]=pre[i-1]+a[i]; q.push({-1e18,0}); dp[1]={1,-a[1]}; q.push({-a[1]-pre[1], 1}); opt=0; for (i=2;i<n+1;i++) { dp[i]={1,-pre[i]}; while (abs(q.top().fi)<=pre[i]) { opt=max(q.top().se, opt); q.pop(); } if (opt!=0) dp[i]=max(dp[i], {dp[opt].fi+1, -pre[i]+pre[opt]}); q.push({dp[i].se-pre[i], i}); } // for (i=1;i<n+1;i++) cout<<dp[i].fi<<" "<<dp[i].se<<"\n"; cout<<dp[n].fi; }
#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...