제출 #1278101

#제출 시각아이디문제언어결과실행 시간메모리
1278101anarch_yHacker (BOI15_hac)C++20
100 / 100
44 ms13056 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) begin(x), end(x) #define sz(x) (int)x.size() #define pb push_back int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(2*n+1); for(int i=1; i<=n; i++) cin >> a[i]; for(int i=n+1; i<=2*n; i++) a[i] = a[i-n]; vector<int> p(2*n+1); for(int i=1; i<=2*n; i++){ p[i] = a[i] + p[i-1]; } int k = (n+1)/2; vector<int> b(2*n+1); for(int i=k; i<=2*n; i++){ b[i] = p[i] - p[i-k]; } for(int i=1; i<k; i++){ b[i] = b[i+n]; } deque<int> d; int ans = 0; for(int i=1; i<=k; i++){ while(!d.empty() and d.back() > b[i]) d.pop_back(); d.push_back(b[i]); } ans = max(ans, d.front()); for(int i=k+1; i<=2*n; i++){ if(!d.empty() and d.front() == b[i-k]) d.pop_front(); while(!d.empty() and d.back() > b[i]) d.pop_back(); d.push_back(b[i]); ans = max(ans, d.front()); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...