Submission #672657

# Submission time Handle Problem Language Result Execution time Memory
672657 2022-12-17T10:09:37 Z finn__ Hacker (BOI15_hac) C++17
100 / 100
122 ms 9916 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    size_t n;
    cin >> n;

    vector<int> a(n);
    for (int &x : a)
        cin >> x;

    vector<int> p(n, 0);
    for (size_t i = 0; i < (n + 1) / 2; i++)
        p[0] += a[i];
    for (size_t i = 1; i < n; i++)
        p[i] = p[i - 1] + a[(i + (n + 1) / 2 - 1) % n] - a[i - 1];

    deque<pair<int, size_t>> q;

    for (size_t i = 0; i < (n + 1) / 2; i++)
    {
        while (!q.empty() && q.back().first >= p[i])
            q.pop_back();
        q.push_back({p[i], i});
    }
    int max_value = q.front().first;

    for (size_t i = 1; i < n; i++)
    {
        if (!q.empty() && q.front().second == i - 1)
            q.pop_front();
        while (!q.empty() && q.back().first >= p[(i + (n + 1) / 2 - 1) % n])
            q.pop_back();
        q.push_back({p[(i + (n + 1) / 2 - 1) % n], (i + (n + 1) / 2 - 1) % n});
        max_value = max(max_value, q.front().first);
    }

    cout << max_value << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 316 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 304 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 20 ms 1212 KB Output is correct
5 Correct 47 ms 2620 KB Output is correct
6 Correct 60 ms 3276 KB Output is correct
7 Correct 74 ms 4036 KB Output is correct
8 Correct 122 ms 6416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 316 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 304 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 312 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 20 ms 1212 KB Output is correct
36 Correct 47 ms 2620 KB Output is correct
37 Correct 60 ms 3276 KB Output is correct
38 Correct 74 ms 4036 KB Output is correct
39 Correct 122 ms 6416 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 8 ms 680 KB Output is correct
43 Correct 48 ms 2720 KB Output is correct
44 Correct 120 ms 6464 KB Output is correct
45 Correct 22 ms 1364 KB Output is correct
46 Correct 81 ms 3884 KB Output is correct
47 Correct 120 ms 6400 KB Output is correct
48 Correct 122 ms 6616 KB Output is correct
49 Correct 96 ms 9916 KB Output is correct
50 Correct 96 ms 9916 KB Output is correct