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;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab (int x ) { return (x>0?x:-x); }
const int N = 500005 ;
int a[N] , pref[N],n,st[N*4];
void update(int uL , int uR , int i , int j , int u , int val ){
// cout << i << " " << j <<endl;
if( i > j )return ;
if( i >= uL && j <= uR ){
st[u] = min ( st[u] , val ) ;
return ;
}
if( i > uR || j < uL )return ;
int l = u*2 + 1 , r = u*2+2 , mid = (i+j)/2 ;
update(uL,uR,i,mid,l,val) ;
update(uL,uR,mid+1,j,r,val) ;
}
int query (int i , int x , int y , int u){
// cout << "querey"<<endl;
if( x > y )return 1e9;
if( x == y ){
return st[u];
}
int l = u*2+1 , r = u*2+2 , mid = (x+y)/2 ;
if( i <= mid )return min(st[u],query(i,x,mid,l));
return min ( st[u] , query(i,mid+1,y,r));
}
int sum(int l , int r ){
if( l > r )return 0;
if( l == 0 )return pref[r];
return pref[r]-pref[l-1] ;
}
int main(){
cin >> n ;
for(int i = 0 ; i < 4*N ; i++ )st[i]=1e9;
for(int i= 0 ; i< n ; i++ )cin >> a[i] ;
pref[0] = a[0] ;
for(int i = 1 ; i < n ; i++ ){
pref[i] = pref[i-1] + a[i] ;
}
int ans = 0;
for(int start = 0 ; start < n ; start ++ ){
int end = min(n-1,start+(n/2)-!(n%2));
int v0 = sum(start,end);
int res = (n/2+n%2) - (n-start) ;
int v1 = sum(0,res-1) ;
update(start,end,0,n-1,0,v1+v0) ;
update(0,res-1,0,n-1,0,v1+v0) ;
}
for(int i = 0 ; i < n ; i++ ){
ans = max ( ans , query(i,0,n-1,0));
}
cout << ans << endl ;
}
# | 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... |