이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
size_t n;
cin >> n;
vector<int> a(n);
for (int &x : a)
cin >> x;
vector<int> p(n, 0);
for (size_t i = 0; i < (n + 1) / 2; i++)
p[0] += a[i];
for (size_t i = 1; i < n; i++)
p[i] = p[i - 1] + a[(i + (n + 1) / 2 - 1) % n] - a[i - 1];
deque<pair<int, size_t>> q;
for (size_t i = 0; i < (n + 1) / 2; i++)
{
while (!q.empty() && q.back().first >= p[i])
q.pop_back();
q.push_back({p[i], i});
}
int max_value = q.front().first;
for (size_t i = 1; i < n; i++)
{
if (!q.empty() && q.front().second == i - 1)
q.pop_front();
while (!q.empty() && q.back().first >= p[(i + (n + 1) / 2 - 1) % n])
q.pop_back();
q.push_back({p[(i + (n + 1) / 2 - 1) % n], (i + (n + 1) / 2 - 1) % n});
max_value = max(max_value, q.front().first);
}
cout << max_value << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |