Submission #91741

#TimeUsernameProblemLanguageResultExecution timeMemory
91741MercenaryHacker (BOI15_hac)C++14
100 / 100
72 ms15608 KiB
#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)

hac.cpp: In function 'int main()':
hac.cpp:50:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(taskname".INP", "r",stdin) ,
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
         freopen(taskname".OUT", "w",stdout);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
hac.cpp:50:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...