Submission #168427

#TimeUsernameProblemLanguageResultExecution timeMemory
168427IldarKABigger segments (IZhO19_segments)C++14
100 / 100
518 ms44280 KiB
#include <bits/stdc++.h> using namespace std; int n, a[500001], dp[500001]; long long pr[500001], seg[500001]; int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; pr[i] = pr[i - 1] + a[i]; } set < pair < long long, int > > s; s.insert({0, 0}); for(int i = 1; i <= n; i++){ int j = 0; while(!s.empty()){ if((s.begin()->first) > pr[i]) break; j = max(j, s.begin() -> second); s.erase(s.begin()); } dp[i] = dp[j] + 1; seg[i] = pr[i] - pr[j]; s.insert({pr[j] + seg[j], j}); s.insert({pr[i] + seg[i], i}); } cout << dp[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...