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;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=5e5+7, INF=1e9+7;
int tr[4*LIM], T[LIM], n, N=1;
int cnt(int l, int r) {
if(l>r) return INF;
l+=N; r+=N;
int ans=min(tr[l], tr[r]);
while(l/2!=r/2) {
if(l%2==0) ans=min(ans, tr[l+1]);
if(r%2==1) ans=min(ans, tr[r-1]);
l/=2; r/=2;
}
return ans;
}
int ile(int x) {
int y=(x+(n+1)/2-1)%n;
if(y<x) return min(cnt(x, n-1), cnt(0, y));
return cnt(x, y);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
while(N<n) N*=2;
rep(i, n) cin >> T[i];
rep(i, (n+1)/2) tr[N]+=T[i];
rep(i, n-1) tr[N+i+1]=tr[N+i]+T[((n+1)/2+i)%n]-T[i];
for(int i=N-1; i>=0; --i) tr[i]=min(tr[2*i], tr[2*i+1]);
int ans=0;
rep(i, n) ans=max(ans, ile(i));
cout << ans << '\n';
}
# | 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... |