#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <complex>
#include <stack>
#include <set>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define cd complex<double>
#define ld long double
#define pld pair<ld,ld>
#define iii pair<ii,int>
const int INF = 1e9+10;
using namespace std;
const int MAXN = 1000*100*2+10;
const int MAXVAL = 1e9+10;
inline int modVal(int v,int n){
if(v < 0)return v+2*n;
else if(v >= 2*n)return v-2*n;
else return n;
}
int main(){
int n;
cin >> n;
int arr[3*n];
FOR(i,n){
cin >> arr[i];
arr[i+n] = arr[i];
arr[i+2*n] = arr[i];
}
//FOR(i,3*n)cout << arr[i] << " ";cout << endl;
int k = (n+1)/2;
int sum = 0;
int sumst[3*n];
FOR(i,k){
sum += arr[i];
}
sumst[0] = sum;
FORE(i,k,3*n-1){
sum += arr[i]-arr[i-k];
sumst[i-k+1] = sum;
}
int mx = 0;
//FOR(i,3*n)cout << arr[i] << " ";cout << endl;
//FOR(i,3*n)cout << sumst[i] << " ";cout << endl;
deque<ii> dq;
FORE(j,0-k+1,0-1){
ii e = {sumst[j+n],j+n};
while(!dq.empty() and dq.front().ff >= e.ff)dq.pop_front();
dq.push_front(e);
}
FOR(i,n){
int mn = INF;
ii e = {sumst[i+n],i+n};
while(!dq.empty() and dq.front().ff >= e.ff)dq.pop_front();
dq.push_front(e);
/*
FORE(j,i-k+1,i){
//int jj = modVal(j,n);
mn = min(mn,sumst[j+n]);
}
*/
//for(auto ee:dq)cout << ee.ff << ":" << ee.ss-n << " ";cout << endl;
mn = min(mn,dq.back().ff);
while(!dq.empty() and dq.back().ss-n <= i-k+1)dq.pop_back();
mx = max(mx,mn);
}
cout << mx << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
24 ms |
2424 KB |
Output is correct |
5 |
Correct |
52 ms |
5572 KB |
Output is correct |
6 |
Correct |
71 ms |
6884 KB |
Output is correct |
7 |
Correct |
83 ms |
8196 KB |
Output is correct |
8 |
Correct |
134 ms |
13324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
24 ms |
2424 KB |
Output is correct |
36 |
Correct |
52 ms |
5572 KB |
Output is correct |
37 |
Correct |
71 ms |
6884 KB |
Output is correct |
38 |
Correct |
83 ms |
8196 KB |
Output is correct |
39 |
Correct |
134 ms |
13324 KB |
Output is correct |
40 |
Correct |
5 ms |
640 KB |
Output is correct |
41 |
Correct |
7 ms |
768 KB |
Output is correct |
42 |
Correct |
12 ms |
1152 KB |
Output is correct |
43 |
Correct |
55 ms |
5496 KB |
Output is correct |
44 |
Correct |
137 ms |
13424 KB |
Output is correct |
45 |
Correct |
27 ms |
2808 KB |
Output is correct |
46 |
Correct |
83 ms |
8060 KB |
Output is correct |
47 |
Correct |
138 ms |
13304 KB |
Output is correct |
48 |
Correct |
175 ms |
13564 KB |
Output is correct |
49 |
Correct |
122 ms |
14712 KB |
Output is correct |
50 |
Correct |
123 ms |
14712 KB |
Output is correct |