Submission #374119

#TimeUsernameProblemLanguageResultExecution timeMemory
374119mariowongBigger segments (IZhO19_segments)C++14
13 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; long long n,a[500005]; pair <long long,long long> dp[500005]; long long ps[500005],now; deque <long long> q; int main(){ ios::sync_with_stdio(false); cin >> n; for (int i=1;i<=n;i++){ cin >> a[i]; ps[i]=ps[i-1]+a[i]; } for (int i=1;i<=n;i++){ while (!q.empty() && dp[q.front()].first <= ps[i]-ps[q.front()]){ now=q.front(); q.pop_front(); } dp[i]=make_pair(ps[i]-ps[now],dp[now].second+1); while (!q.empty() && dp[q.back()].first >= ps[i]-ps[now]){ q.pop_back(); } q.push_back(i); } cout << dp[n].second << "\n"; 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...