Submission #92923

# Submission time Handle Problem Language Result Execution time Memory
92923 2019-01-05T17:13:35 Z popovicirobert Hacker (BOI15_hac) C++14
100 / 100
547 ms 20344 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));
}

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 = *mst.begin();
    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, *mst.begin());
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 43 ms 3576 KB Output is correct
5 Correct 144 ms 8248 KB Output is correct
6 Correct 186 ms 10232 KB Output is correct
7 Correct 195 ms 12280 KB Output is correct
8 Correct 547 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 4 ms 504 KB Output is correct
35 Correct 43 ms 3576 KB Output is correct
36 Correct 144 ms 8248 KB Output is correct
37 Correct 186 ms 10232 KB Output is correct
38 Correct 195 ms 12280 KB Output is correct
39 Correct 547 ms 20216 KB Output is correct
40 Correct 6 ms 888 KB Output is correct
41 Correct 11 ms 1144 KB Output is correct
42 Correct 15 ms 1500 KB Output is correct
43 Correct 137 ms 8312 KB Output is correct
44 Correct 430 ms 20188 KB Output is correct
45 Correct 51 ms 4216 KB Output is correct
46 Correct 218 ms 12280 KB Output is correct
47 Correct 526 ms 20216 KB Output is correct
48 Correct 271 ms 20344 KB Output is correct
49 Correct 254 ms 19584 KB Output is correct
50 Correct 250 ms 19576 KB Output is correct