Submission #723601

#TimeUsernameProblemLanguageResultExecution timeMemory
723601Mr_HusanboyHacker (BOI15_hac)C++17
100 / 100
367 ms14344 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; void solve(){ int n; cin >> n; vector<int> p(n); for(int i = 0; i < n; i ++) cin >> p[i]; int ans = 0; for(int i = 1; i < n; i ++){ p[i] += p[i - 1]; } auto get = [&](int l, int r)->int{ if(l > r){ return p[r] + p[n - 1] - (l ? p[l - 1] : 0); } return p[r] - (l ? p[l - 1] : 0); }; multiset<int> st; int k = (n + 1) / 2; for(int i = 0; i < n; i ++){ for(int j = i; j < i + k; j ++){ int r = j % n; int l = ((r - k + 1) % n + n) % n; st.insert(get(l, r)); } ans = max(ans, *st.begin()); break; } for(int i = 1; i < n; i ++){ int del = get(((i - k) % n + n) % n, i - 1); int add = get(i, (i + k - 1) % n); //cout << del << ' ' << add << endl; st.erase(st.find(del)); st.insert(add); ans = max(ans, *st.begin()); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int testcases = 1; while(testcases --){ solve(); if(testcases) cout << '\n'; #ifdef LOCAL else cout << '\n'; cout << "__________________________" << endl; #endif } 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...