Submission #632038

# Submission time Handle Problem Language Result Execution time Memory
632038 2022-08-19T10:37:30 Z BhavayGoyal Hacker (BOI15_hac) C++14
100 / 100
392 ms 22312 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const int linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

// -------------------------------------------------- Main Code --------------------------------------------------

void sol() {
    int n; cin >> n;
    int mid = (n+1)/2;
    int arr[2*n];
    for (int i = 0; i < n; i++) {cin >> arr[i]; arr[i+n] = arr[i];}    
    for (int i = 1; i < 2*n; i++) arr[i] += arr[i-1];
    multiset<int> st;
    for (int i = mid-1; i < n-1; i++) { int pSum = arr[i]; if (i >= mid) pSum -= arr[i-mid]; st.insert(pSum);}
    int ans = *st.begin();
    for (int i = n-1; i < 2*n; i++) {
        int idx = i-mid; 
        if (idx >= mid-1) st.erase(st.find(arr[idx]-(idx >= mid?arr[idx-mid]:0)));
        int pSum = arr[i] - arr[i-mid];
        st.insert(pSum);
        ans = max(ans, *st.begin());
    }
    cout << ans << endl;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 320 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 0 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 320 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 0 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 452 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 316 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 468 KB Output is correct
31 Correct 2 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 30 ms 3412 KB Output is correct
5 Correct 89 ms 8116 KB Output is correct
6 Correct 110 ms 9988 KB Output is correct
7 Correct 136 ms 12040 KB Output is correct
8 Correct 300 ms 19912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 320 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 0 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 452 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 316 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 468 KB Output is correct
31 Correct 2 ms 456 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 30 ms 3412 KB Output is correct
36 Correct 89 ms 8116 KB Output is correct
37 Correct 110 ms 9988 KB Output is correct
38 Correct 136 ms 12040 KB Output is correct
39 Correct 300 ms 19912 KB Output is correct
40 Correct 4 ms 724 KB Output is correct
41 Correct 8 ms 1100 KB Output is correct
42 Correct 11 ms 1620 KB Output is correct
43 Correct 126 ms 8996 KB Output is correct
44 Correct 246 ms 22028 KB Output is correct
45 Correct 37 ms 4564 KB Output is correct
46 Correct 132 ms 13244 KB Output is correct
47 Correct 392 ms 21984 KB Output is correct
48 Correct 237 ms 22312 KB Output is correct
49 Correct 219 ms 21560 KB Output is correct
50 Correct 211 ms 21444 KB Output is correct