Submission #676498

#TimeUsernameProblemLanguageResultExecution timeMemory
676498penguin133Hacker (BOI15_hac)C++17
100 / 100
59 ms20404 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int dp[1000005], B[1000005], P[1000005], S[500005]; deque<int>dq; main(){ ios::sync_with_stdio(0);cin.tie(0); int n;cin >> n; for(int i=1;i<=n;i++)cin >> B[i]; for(int i=n+1;i<=n*2;i++)B[i] = B[i-n]; for(int i=1;i<=2*n;i++)P[i] = P[i-1] + B[i]; int x = n / 2; for(int i=1;i<=n-x;i++){ while(!dq.empty() && P[dq.back() + x-1] - P[dq.back()-1] < P[i+x-1] - P[i-1])dq.pop_back(); dq.push_back(i); } int maxi = 1e9; for(int i=1;i<=n;i++){ while(!dq.empty() && P[dq.back() + x-1] - P[dq.back()-1] < P[n+i-1] - P[n+i-x-1])dq.pop_back(); if(!dq.empty() && dq.front() == i)dq.pop_front(); dq.push_back(n+i-x); maxi = min(maxi, P[dq[0] + x - 1] - P[dq[0] - 1]); } cout << P[n] - maxi; }

Compilation message (stderr)

hac.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...