Submission #926369

#TimeUsernameProblemLanguageResultExecution timeMemory
926369LudisseyHacker (BOI15_hac)C++14
100 / 100
45 ms5364 KiB
#include <bits/stdc++.h>

int main() {
	int n; scanf("%d",&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) {
            scanf("%d",&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::printf("%d\n", outp);
    return 0;
}

Compilation message (stderr)

hac.cpp: In function 'int main()':
hac.cpp:4:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 |  int n; scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
hac.cpp:9:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |             scanf("%d",&v[i]);
      |             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...