Submission #92916

# Submission time Handle Problem Language Result Execution time Memory
92916 2019-01-05T15:08:15 Z popovicirobert Hacker (BOI15_hac) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 5e5 + 5;

int arr[MAXN + 1], n;
int pref[MAXN + 1], suff[MAXN + 1];

inline int get(int l, int r) {
    if(l <= 0) {
        return suff[n + l] + pref[r];
    }
    if(r > n) {
        return suff[l] + pref[r - n];
    }
    return pref[r] - pref[l - 1];
}

inline int get(multiset <int> &mst, int x) {
    if(mst.count(x) > 1) {
        return x;
    }
    return *prev(mst.find(x));
}

/*inline bool ok(int l, int r) {
    return min(l, r)
}

inline bool check(int val, int len) {
    queue <int> q;
    int i, l;
    for(i = 1; i <= len; i++) {
        if(get(i - len + 1, i) > val) {
            l = ;
            q.push();
        }
    }
    if(ok(l, q.front())) {
        return 1;
    }
    for(i = 2; i <= n; i++) {

    }
    return 0;
}*/

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        pref[i] = pref[i - 1] + arr[i];
    }
    for(i = n; i >= 1; i--) {
        suff[i] = suff[i + 1] + arr[i];
    }
    multiset <int> mst;
    int len = (n + 1) / 2;
    for(i = 1; i <= len; i++) {
        mst.insert(get(i - len + 1, i));
    }
    int ans = get(mst, max(get(1 - len + 1, 1), get(1, len)));
    for(i = 2; i <= n; i++) {
        mst.erase(mst.find(get(i - 1 - len + 1, i - 1)));
        mst.insert(get(i, i + len - 1));
        ans = max(ans, get(mst, max(get(i - len + 1, i), get(i, i + len - 1))));
    }
    cout << ans;
    /*int res = 0;
    for(int step = 1 << 30; step; step >>= 1) {
        if(check(res + step, (n + 1) / 2)) {
            res += step;
        }
    }
    cout << res;*/
    //cin.close();
    //cout.close();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -