Submission #985890

#TimeUsernameProblemLanguageResultExecution timeMemory
985890hengliaoHacker (BOI15_hac)C++17
100 / 100
272 ms34120 KiB
#include<bits/stdc++.h>
using namespace std;
 
#define F first
#define S second
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
typedef long long ll;
 
const ll inf=1e17;
 
void solve(){
	ll n;
    cin>>n;
    vll a(2*n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        a[i+n]=a[i];
    }
    vll val(2*n, inf);
    ll pre=0;
    ll siz=n/2;
    if(n%2==1) siz++;
    for(ll i=0;i<siz;i++){
        pre+=a[i];
    }
    val[0]=pre;
    ll p1=0;
    ll p2=siz;
    for(ll i=1;i<n;i++){
        pre-=a[p1];
        pre+=a[p2];
        p1++;
        p2++;
        val[i]=pre;
    }
    vll ans(n, inf);
    p1=0;
    p2=1;
    multiset<ll> st;
    st.insert(val[0]);
    for(ll i=0;i<2*n;i++){
        while(p1<i-siz+1){
            st.erase(st.find(val[p1]));
            p1++;
        }
        while(p2<=i){
            st.insert(val[p2]);
            p2++;
        }
        ans[i%n]=min(ans[i%n], *st.begin());
    }
    ll o=0;
    for(ll i=0;i<n;i++){
        o=max(o, ans[i]);
    }
    cout<<o<<'\n';
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
	solve();
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...