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 <stdio.h>
#define N 100000
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long aa[N + 1];
long long solve2(int l, int r) {
int lower = l, upper = r;
while (upper - lower > 1) {
int j = (lower + upper) / 2;
if (aa[j] - aa[l] < aa[r] - aa[j])
lower = j;
else
upper = j;
}
return l == r ? 0 : max(aa[lower] - aa[l], aa[r] - aa[upper]);
}
int main() {
int n, i, l, r;
long long ans;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &aa[i]);
aa[i] += aa[i - 1];
}
ans = 0;
for (l = 0, r = 0; l < n; l++) {
while (r < n && solve2(l, r) < aa[n] + aa[l] - aa[r])
r++;
ans = max(ans, solve2(l, r - 1));
if (r < n)
ans = max(ans, aa[n] + aa[l] - aa[r]);
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
2014_ho_t3.c: In function 'main':
2014_ho_t3.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
2014_ho_t3.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%lld", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~~~
# | 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... |