# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376952 | joelau | Bigger segments (IZhO19_segments) | C++14 | 81 ms | 12272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int N,ans[500001];
long long A[500001], sz[500001];
deque<int> dq;
int main() {
scanf("%d", &N);
A[0] = 0;
for (int i = 1; i <= N; ++i) {
scanf("%lld", &A[i]);
A[i] += A[i-1];
}
ans[0] = 0, sz[0] = 0;
for (int i = 1; i <= N; ++i) {
while (dq.size() > 1 && sz[dq[1]] + A[dq[1]] <= A[i]) dq.pop_front();
if (!dq.empty() && sz[dq.front()] + A[dq.front()] <= A[i]) ans[i] = ans[dq.front()]+1, sz[i] = A[i] - A[dq.front()];
else ans[i] = 1, sz[i] = A[i];
while (!dq.empty() && sz[i] + A[i] <= sz[dq.back()] + A[dq.back()]) dq.pop_back();
dq.push_back(i);
}
printf("%d", ans[N]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |