제출 #536513

#제출 시각아이디문제언어결과실행 시간메모리
536513fcwHacker (BOI15_hac)C++17
100 / 100
76 ms27708 KiB
#include <bits/stdc++.h> #define st first #define nd second using lint = int64_t; constexpr int mod = int(1e9) + 7; constexpr int inf = 0x3f3f3f3f; constexpr int ninf = 0xcfcfcfcf; constexpr lint linf = 0x3f3f3f3f3f3f3f3f; const long double pi = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; template<typename T, T (*op)(const T&, const T&)> struct monotonic_queue { vector<T> as, aas; vector<T> bs, bbs; void reserve(int N) { as.reserve(N); aas.reserve(N); bs.reserve(N); bbs.reserve(N); } void reduce() { while (!bs.empty()) { as.push_back(bs.back()); aas.push_back(aas.empty() ? bs.back() : op(bs.back(), aas.back())); bs.pop_back(); bbs.pop_back(); } } T get() { if (as.empty()) reduce(); return (bbs.empty() ? aas.back() : op(aas.back(), bbs.back())); } bool empty() const { return (as.empty() && bs.empty()); } int size() const { return int(as.size()) + int(bs.size()); } T front() { if (as.empty()) reduce(); return as.back(); } void push(const T& val) { bs.push_back(val); bbs.push_back(bbs.empty() ? val : op(bbs.back(), val)); } void pop() { if (as.empty()) reduce(); as.pop_back(); aas.pop_back(); } }; // min/max template<typename T> T mapping_max(const T& a, const T& b) { return max(a, b); } template<typename T> using max_monotonic_queue = monotonic_queue<T, mapping_max>; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin>>n; vector<lint>v(n+n), pref(n+n+1); for(int i=0;i<n;i++) cin>>v[i], v[i+n] = v[i]; for(int i=1;i<=n+n;i++){ pref[i] = pref[i-1] + v[i-1]; } max_monotonic_queue<lint>q; for(int i=1;i+n/2<=n;i++){ q.push(pref[i+n/2-1] - pref[i-1]); } lint ans = linf; for(int i=0;i<n;i++){ ans = min(ans, q.get()); q.pop(); q.push(pref[n+i] - pref[n+i-n/2]); } cout<<pref[n] - ans<<"\n"; return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...