제출 #288046

#제출 시각아이디문제언어결과실행 시간메모리
288046bensonlzlBigger segments (IZhO19_segments)C++14
100 / 100
127 ms25952 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pl; typedef pair<ll,pl> pll; ll N, A[500005], P[500005], dp[500005]; pl bestr; priority_queue<pll,vector<pll>,greater<pll> > pq; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; for (int i = 1; i <= N; ++i){ cin >> A[i]; P[i] = A[i] + P[i-1]; } bestr = pl(0,0); for (int i = 1; i <= N; ++i){ while (!pq.empty()){ pll x = pq.top(); if (x.first <= P[i]){ bestr = max(bestr,x.second); pq.pop(); } else break; } dp[i] = bestr.first+1; pq.push(pll(2*P[i]-P[bestr.second],pl(dp[i],i))); } cout << dp[N] << '\n'; }
#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...