Submission #332440

#TimeUsernameProblemLanguageResultExecution timeMemory
332440dolphingarlicBigger segments (IZhO19_segments)C++14
100 / 100
84 ms20992 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll a[500001], pref[500001]; pair<int, ll> dp[500001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; deque<int> dq = {0}; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; while (dq.size() > 1 && pref[i] - pref[dq[1]] >= dp[dq[1]].second) dq.pop_front(); dp[i] = {dp[dq[0]].first + 1, pref[i] - pref[dq[0]]}; while (dq.size() && dp[dq.back()].second - dp[i].second >= pref[i] - pref[dq.back()]) dq.pop_back(); dq.push_back(i); } // for (int i = 1; i <= n; i++) cout << "(" << dp[i].first << ", " << dp[i].second << ") "; // cout << '\n'; cout << dp[n].first; 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...