Submission #705357

# Submission time Handle Problem Language Result Execution time Memory
705357 2023-03-04T06:23:27 Z LittleCube Hacker (BOI15_hac) C++14
20 / 100
48 ms 10240 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll n, h, v[500005], s[500005], sum, ans;

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    h = n / 2;
    for (int i = 0; i < n; i++)
        cin >> v[i];
    for (int i = 0; i < n; i++)
        sum += v[i];
    for (int i = 0; i < h; i++)
        s[0] += v[i];
    for (int i = 1; i < n; i++)
        s[i] = s[i - 1] - v[i - 1] + v[(i + h - 1) % n];
    deque<pll> dq;
    for (int i = 1; i < n - h + 1; i++)
    {
        while (!dq.empty() && dq.back().F < s[i])
            dq.pop_back();
        dq.push_back(pll(s[i], i));
    }
    for (int i = 0; i < h; i++)
    {
        ans = max(ans, sum - dq.front().F);
        if (dq.front().S == i + 1)
            dq.pop_front();
        int j = (i - h + 1 + n) % n;
        while (!dq.empty() && dq.back().F < s[j])
            dq.pop_back();
        dq.push_back(pll(s[j], j));
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 1940 KB Output is correct
5 Correct 18 ms 4116 KB Output is correct
6 Correct 26 ms 5292 KB Output is correct
7 Correct 29 ms 6328 KB Output is correct
8 Correct 48 ms 10240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -