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 seg[2000005], a[500005], b[500005], n, mx;
void build(int i, int l, int r)
{
if (l==r)
{
if (l>n/2)
seg[i]=b[n-1]-b[l-1]+b[l-n/2-1];
else
seg[i]=b[l+(n-1)/2]-b[l-1];
return;
}
int m=(l+r)/2;
build(i*2, l, m);
build(i*2+1, m+1, r);
seg[i]=min(seg[i*2], seg[i*2+1]);
}
int qry(int i, int l, int r, int ql, int qr)
{
if (ql<=l && r<=qr)
return seg[i];
int m=(l+r)/2, res=1e9;
if (l<=qr && ql<=m)
res=min(res, qry(i*2, l, m, ql, qr));
if (m<qr && ql<=r)
res=min(res, qry(i*2+1, m+1, r, ql, qr));
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> a[0];
b[0]=a[0];
for (int i=1; i<n; i++)
{
cin >> a[i];
b[i]=b[i-1]+a[i];
}
build(1, 0, n-1);
for (int i=0; i<n; i++)
{
if (i>n/2)
mx=max(mx, min(qry(1, 0, n-1, i, n-1), qry(1, 0, n-1, 0, i-n/2-1)));
else
mx=max(mx, qry(1, 0, n-1, i, i+(n-1)/2));
}
cout << mx;
}
# | 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... |