Submission #652382

#TimeUsernameProblemLanguageResultExecution timeMemory
652382dooompyHacker (BOI15_hac)C++17
100 / 100
322 ms15960 KiB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

int v[500005];
int cycle[500005];


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    int needed = ceil(n / 2.0);
    int total = 0;
    for (int i = 0; i < needed; i++) {
        total += v[i];
    }

    cycle[0] = total;

    for (int i = 1; i < n; i++) {
        total -= v[i - 1];
        total += v[(i + needed - 1) % n];
        cycle[i] = total;
    }
    
    multiset<int> calc;
    
    for (int i = 0; i < needed; i++) {
        calc.insert(cycle[i]);
    }
    
    int ans = *calc.begin();
    
    for (int i = 1; i < n; i++) {
        calc.erase(calc.find(cycle[ i - 1]));
        calc.insert(cycle[( i + needed - 1) % n]);
        ans = max(ans, *calc.begin());
    }
    
    cout << ans << endl;

    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...