# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
860747 | Halym2007 | Bigger segments (IZhO19_segments) | C++11 | 1 ms | 348 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>
#define ll long long
using namespace std;
const int N = 5e5 + 5;
ll o, a[N], seg[N], sum;
int main () {
freopen("input.txt", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
o++;
seg[o] = a[1];
for (int i = 2; i <= n; ++i) {
sum = 0;
int r = i;
while (r <= n and sum < seg[o]) {
sum += a[r];
r++;
}
if (sum >= seg[o]) {
o++;
seg[o] = sum;
while (i <= n and sum - a[i] >= seg[o - 1] + a[i]) {
seg[o - 1] += a[i];
seg[o] -= a[i];
i++;
}
}
else {
seg[o] += sum;
break;
}
i = max(r - 1, i - 1);
}
cout << o << endl;
}
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... |