# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
32018 | chonka | Hacker (BOI15_hac) | C++98 | 99 ms | 32368 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<iostream>
#include<stdio.h>
#include<queue>
using namespace std ;
#define MAXN 500007
int n ;
int a[ 3 * MAXN ] ;
long long pref[ 3 * MAXN ] ;
long long val[ 3 * MAXN ] ;
int len ;
void input ( ) {
scanf ( "%d" , &n ) ;
len = ( n / 2 ) + ( n % 2 ) ;
int i ;
for ( i = 1 ; i <= n ; i ++ ) {
scanf ( "%d" , &a[ i ] ) ;
a[ n + i ] = a[ i ] ;
a[ 2 * n + i ] = a[ i ] ;
}
for ( i = 1 ; i <= 3 * n ; i ++ ) {
pref[ i ] = ( pref[ i - 1 ] + a[ i ] ) ;
}
for ( i = 1 ; i + len - 1 <= 3 * n ; i ++ ) {
val[ i ] = pref[ i + len - 1 ] - pref[ i - 1 ] ;
}
}
void solve ( ) {
int i ;
deque < int > q ;
long long ans = 0 ;
for ( i = 1 ; i <= 3 * n ; i ++ ) {
while ( q.empty ( ) == false && val[ q.back ( ) ] >= val[ i ] ) {
q.pop_back ( ) ;
}
q.push_back ( i ) ;
while ( q.empty ( ) == false && q.front ( ) + len - 1 < i ) {
q.pop_front ( ) ;
}
if ( i > n && i <= 2 * n ) {
ans = max ( ans , val[ q.front ( ) ] ) ;
}
}
printf ( "%lld\n" , ans ) ;
}
int main ( ) {
input ( ) ;
solve ( ) ;
return 0 ;
}
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... |