# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926358 | Ludissey | Hacker (BOI15_hac) | C++14 | 40 ms | 5244 KiB |
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>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n; cin >> n;
int half=((n+1)/2);
vector<int> v(n*2,0);
for (int i = 0; i < v.size(); i++) {
if(i<n) {
cin >> v[i];
v[i+n]=v[i];
}
v[i]+=v[i-1];
}
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=max(v[queue.front()+half-1]-v[queue.front()-1], outp);
}
cout << outp << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |