답안 #723790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723790 2023-04-14T10:05:07 Z The_Samurai Hacker (BOI15_hac) C++17
100 / 100
377 ms 21576 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int INF = 2e9;

void solve() {
    int n;
    cin >> n;
    vector<int> a(2 * n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    int sum = 0;
    for (int i = 0; i < n / 2; i++) sum += a[i];
    vector<int> range(2 * n);
    range[0] = sum;
    multiset<int, greater<int>> st;
    int all_sum = 0, ans = 0, l = 1, r = 1;
    for (int i = n / 2; i < 2 * n; i++) {
        sum += a[i] - a[i - n / 2];
        range[i - n / 2 + 1] = sum;
        if (i < n) {
            st.insert(sum);
            r = i - n / 2 + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        all_sum += a[i];
    }
    for (int i = 0; i < n; i++) {
        ans = max(ans, all_sum - *st.begin());
        st.erase(st.find(range[l++]));
        st.insert(range[++r]);
    }
    cout << ans;

}

int main() {
    ::srand(::time(0));
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 284 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 35 ms 3708 KB Output is correct
5 Correct 132 ms 8784 KB Output is correct
6 Correct 128 ms 11188 KB Output is correct
7 Correct 166 ms 13424 KB Output is correct
8 Correct 366 ms 21320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 284 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 35 ms 3708 KB Output is correct
36 Correct 132 ms 8784 KB Output is correct
37 Correct 128 ms 11188 KB Output is correct
38 Correct 166 ms 13424 KB Output is correct
39 Correct 366 ms 21320 KB Output is correct
40 Correct 4 ms 704 KB Output is correct
41 Correct 8 ms 1108 KB Output is correct
42 Correct 15 ms 1608 KB Output is correct
43 Correct 109 ms 9012 KB Output is correct
44 Correct 291 ms 21452 KB Output is correct
45 Correct 45 ms 4556 KB Output is correct
46 Correct 169 ms 13352 KB Output is correct
47 Correct 377 ms 21576 KB Output is correct
48 Correct 230 ms 21564 KB Output is correct
49 Correct 210 ms 21488 KB Output is correct
50 Correct 217 ms 21340 KB Output is correct