Submission #1098751

#TimeUsernameProblemLanguageResultExecution timeMemory
1098751TurkhuuBigger segments (IZhO19_segments)C++17
100 / 100
74 ms24264 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (auto &i : a) { cin >> i; } vector<ll> pfs(n + 1); vector<pair<int, ll>> dp(n + 1, {0, 0}); priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; for (int i = 0, j = 0; i < n; i++) { pfs[i + 1] = pfs[i] + a[i]; while (!pq.empty()) { auto [x, y] = pq.top(); if (x > pfs[i + 1]) { break; } pq.pop(); j = max(j, y); } auto [x, y] = dp[j]; dp[i + 1] = {x + 1, pfs[i + 1] - pfs[j]}; pq.emplace(dp[i + 1].second + pfs[i + 1], i + 1); } cout << dp[n].first; return 6/22; }
#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...