Submission #1356271

#TimeUsernameProblemLanguageResultExecution timeMemory
1356271OwstinHacker (BOI15_hac)C++20
0 / 100
0 ms352 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define all(x) begin(x), end(x)
#define space " "
#define TEST_CASES int a; cin >> a; for (int i = 0; i < a; i++) {solve(); cout << endl;}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n; cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
    }
    vector<int> pref(n);
    for (int i = 0; i < n; i++) {
        pref[i] = vec[i];
        if (i) {
            pref[i] += pref[i - 1];
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        int left;
        if (i < (n - 1) / 2) {
            left = pref[i] + pref[n - 1] - pref[n - 1 - (n - 1) / 2 + i];
        }
        else {
            left = pref[i] - (i == (n - 1) / 2 ? 0 : pref[i - (n - 1) / 2 - 1]);
        }
        int right;
        if (i + (n + 1) / 2 - 1 >= n) {
            right = pref.back() - pref[i - 1] + pref[(n + 1) / 2 - (n - i) - 1];
        }
        else {
            right = pref[i + (n + 1) / 2 - 1] - (i ? pref[i - 1] : 0);
        }
        res = max(res, min(left, right));
    }
    cout << res;
}

int main() {
    FAST_IO;
    //freopen("fortmoo.in", "r", stdin);
    //freopen("fortmoo.out", "w", stdout);
    //TEST_CASES;
    solve(); //cout << endl;
    /*int a; cin >> a;
    for (int i = 1; i <= a; i++){
        cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }*/
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...