# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701649 | lto5 | Bigger segments (IZhO19_segments) | C++14 | 79 ms | 18816 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;
using TNode = pair<int, int64_t>;
int a[500005];
int64_t s[500005];
TNode f[500005];
int64_t get(int l, int r) {
return s[r] - s[l - 1];
}
TNode better(TNode a, TNode b) {
if (a.first != b.first) {
return a.first > b.first ? a : b;
}
return a.second < b.second ? a : b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define task "a"
if (fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
for (int i = 0; i <= n; i++) {
f[i] = {0, 1e18};
}
f[1] = {1, a[1]};
for (int i = 1; i <= n; i++) {
if (f[i].first == 0) {
continue;
}
f[i + 1] = better(f[i + 1], {f[i].first, f[i].second + a[i + 1]});
int lo = i + 1, hi = n;
int pos = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (get(i + 1, mid) >= f[i].second) {
pos = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
if (pos != -1) {
f[pos] = better(f[pos], {f[i].first + 1, get(i + 1, pos)});
}
}
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, f[i].first);
}
cout << best;
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... |