Submission #31601

#TimeUsernameProblemLanguageResultExecution timeMemory
31601huynd2001Hacker (BOI15_hac)C++14
100 / 100
106 ms15844 KiB
/*huypheu 5 1 1 1 1 1 */ #include <bits/stdc++.h> #define int long long using namespace std; int a[500007]; int su[500007]; int ar[500007]; signed main() { int n; scanf("%lld",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); } int k=(n/2)+(n%2!=0); for(int i=1;i<=n;i++) { su[i]=su[i-1]+a[i]; } for(int i=1;i<=n;i++) { if(i+k-1<=n) { ar[i]=su[i+k-1]-su[i-1]; } else { ar[i]=su[n]-su[i-1]+su[k-(n-i+1)]; } } // for(int i=1;i<=n;i++) cout << ar[i] << endl; for(int i=n+1;i<=2*n;i++) { ar[i]=ar[i-n]; } deque <int> deq; int ans=0; for(int i=1;i<=2*n;i++) { while(!deq.empty() && deq.front()<=(i-k)) deq.pop_front(); while(!deq.empty() && ar[deq.back()]>ar[i]) deq.pop_back(); deq.push_back(i); if(i>=k) ans=max(ans,ar[deq.front()]); } printf("%lld",ans); // int mi=0; // for(int i=2;i<=n-la+1;i++) // { // mi=max(mi,su[i+la-1]-su[i-1]); // } // printf("%lld",su[n]-mi); return 0; }

Compilation message (stderr)

hac.cpp: In function 'int main()':
hac.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
hac.cpp:20:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[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...