# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91741 | Mercenary | Hacker (BOI15_hac) | C++14 | 72 ms | 15608 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;
#define taskname "TEST"
#define pb push_back
typedef long double ld;
typedef long long ll;
const int maxn = 2e6 + 5;
int n , a[maxn] , len , b[maxn];
void enter()
{
cin >> n;
for(int i = 1 ; i <= n ; ++i)
{
cin >> a[i];
a[i + n] = a[i + n + n] = a[i];
}
len = n / 2 + n % 2;
int sum = 0;
for(int i = 1 ; i <= 3 * n ; ++i)
{
sum += a[i];
if(i > len)sum -= a[i - len];
b[i] = sum;
// cout << b[i] << endl;
}
}
void solve()
{
int res = 0;
deque<int> d;
for(int i = 1 ; i <= n * 3 ; ++i)
{
while(!d.empty() && b[d.back()] >= b[i])d.pop_back();
d.push_back(i);
if(d.front() + len <= i)d.pop_front();
res = max(res , b[d.front()]);
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r"))
freopen(taskname".INP", "r",stdin) ,
freopen(taskname".OUT", "w",stdout);
enter();solve();
}
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... |