This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);
int n; std::cin >> n;
int half=((n+1)/2);
std::vector<int> v(n*2,0);
for (int i = 0; i < (int)v.size(); i++) {
if(i<n) {
std::cin >> v[i];
v[i+n]=v[i];
}
v[i]+=v[i-1];
}
std::deque<int> queue;
for (int i = 0; i < half; i++)
{
while(!queue.empty()&&v[queue.back()+half-1]-v[queue.back()-1]>(v[i+half-1]-v[i-1])) queue.pop_back();
queue.push_back(i);
}
int outp=v[queue.front()+half-1]-v[queue.front()-1];
for (int i = half; i < (n*2)-half; i++)
{
if(!queue.empty()&&queue.front()==i-half) queue.pop_front();
while(!queue.empty()&&v[queue.back()+half-1]-v[queue.back()-1]>(v[i+half-1]-v[i-1])) queue.pop_back();
queue.push_back(i);
outp=std::max(v[queue.front()+half-1]-v[queue.front()-1], outp);
}
std::cout << outp << "\n";
return 0;
}
# | 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... |