Submission #723559

#TimeUsernameProblemLanguageResultExecution timeMemory
723559dxz05Hacker (BOI15_hac)C++17
100 / 100
200 ms10296 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define MP make_pair const int N = 500500; int n; int a[N], p[N]; int get_sum(int l, int r){ if (l <= r){ return p[r] - (l == 0 ? 0 : p[l - 1]); } else { return p[r] + (p[n - 1] - p[l - 1]); } } int t[4 * N]; int val[N]; void build(int v, int tl, int tr){ if (tl == tr){ t[v] = val[tl]; return; } int tm = (tl + tr) >> 1; build(v << 1, tl, tm); build(v << 1 | 1, tm + 1, tr); t[v] = max(t[v << 1], t[v << 1 | 1]); } int get(int v, int tl, int tr, int l, int r){ if (l <= tl && tr <= r) return t[v]; if (tl > r || tr < l) return 0; int tm = (tl + tr) >> 1; return max(get(v << 1, tl, tm, l, r), get(v << 1 | 1, tm + 1, tr, l, r)); } int get(int l, int r){ if (l <= r){ return get(1, 0, n - 1, l, r); } else { return max(get(1, 0, n - 1, l, n - 1), get(1, 0, n - 1, 0, r)); } } void solve(){ cin >> n; for (int i = 0; i < n; i++){ cin >> a[i]; p[i] = a[i] + (i > 0 ? p[i - 1] : 0); } for (int i = 0; i < n; i++){ int l = (i - n / 2 + 1 + n) % n; val[i] = get_sum(l, i); } build(1, 0, n - 1); int ans = 0; for (int i = 0; i < n; i++){ int l = (i + n / 2) % n, r = (i + n - 1) % n; int mx = get(l, r); ans = max(ans, get_sum(0, n - 1) - mx); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...