Submission #251766

#TimeUsernameProblemLanguageResultExecution timeMemory
251766tutisHacker (BOI15_hac)C++17
20 / 100
64 ms14316 KiB
/*input 4 7 6 8 4 */ #pragma GCC optimize ("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T, typename K> using ordered_map = tree<T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; ll h[n]; for (int i = 0; i < n; i++) cin >> h[i]; ll k = (n + 1) / 2; int sz = n + k; ll s[sz + 1]; s[0] = 0; for (int i = 1; i <= sz; i++) s[i] = s[i - 1] + h[i % n]; vector<ll>X; for (int i = k; i <= sz; i++) X.push_back(s[i] - s[i - k]); deque<pair<ll, ll>>A; for (int i = 0; i < k; i++) { while (!A.empty() && A.back().first >= X[i]) A.pop_back(); A.push_back({X[i], i}); } ll ans = A[0].first; for (int i = k; i < (int)X.size(); i++) { while (!A.empty() && A.back().first >= X[i]) A.pop_back(); A.push_back({X[i], i}); while (A[0].second <= i - k) A.pop_front(); ans = max(ans, A[0].first); } cout << ans << "\n"; 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...