이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void minSelf(int64_t &x, int64_t y) {
if (y < x) {
x = y;
}
}
void maxSelf(int &x, int y) {
if (x < y) {
x = y;
}
}
void testCase() {
int n;
cin >> n;
vector<int> a(n + 1);
vector<int64_t> pref(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
vector<int64_t> minSum = pref;
vector<int> maxSeg(n + 1, 1);
for (int i = 1; i <= n; ++i) {
minSelf(minSum[i], minSum[i - 1] + a[i]);
maxSelf(maxSeg[i], maxSeg[i - 1]);
int j = distance(pref.begin(), lower_bound(pref.begin() + 1, pref.end(), minSum[i] + pref[i]));
if (j <= n) {
maxSeg[j] = maxSeg[i] + 1;
minSum[j] = pref[j] - pref[i];
}
}
cout << maxSeg[n] << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# | 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... |