/*
File created on 06/14/2021 at 12:41:02.
Link to problem:
Description:
Time complexity: O()
Space complexity: O()
Status: DEV
Copyright: Ⓒ 2021 Francois Vogel
*/
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ins insert
#define cls clear
#define ll long long
const int p2 = 1<<20;
const int inf = 1e9;
int bt [p2*2];
void btCls() { for (int i = 0; i < p2*2; i++) bt[i] = inf; }
void btUpd(int rb, int re, int rv, int qn = 1, int qb = 0, int qe = p2-1) {
if (rb > qe or qb > re) return;
else if (rb <= qb and qe <= re) bt[qn] = min(bt[qn], rv);
else {
int qm = (qb+qe)/2;
btUpd(rb, re, rv, qn*2, qb, qm);
btUpd(rb, re, rv, qn*2+1, qm+1, qe);
}
}
int btGet(int idx) {
int mnv = inf;
for (idx += p2; idx != 0; idx /= 2) mnv = min(mnv, bt[idx]);
return mnv;
}
signed main() {
cin.tie(0);
// ios_base::sync_with_stdio(0);
int n;
cin >> n;
int b [n];
for (int i = 0; i < n; i++) cin >> b[i];
btCls();
int divS = (n+1)/2;
int curSum = 0;
for (int i = 0; i < divS; i++) curSum += b[i];
for (int i = 0; i < n; i++) {
int start = i;
int end = (i+divS-1)%n;
if (start < end) {
btUpd(start, end, curSum);
}
else {
btUpd(start, n-1, curSum);
btUpd(0, end, curSum);
}
curSum -= b[i];
curSum += b[(i+divS)%n];
}
int mxv = 0;
for (int i = 0; i < n; i++) {
mxv = max(mxv, btGet(i));
}
cout << mxv;
int d = 0;
d++;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8396 KB |
Output is correct |
2 |
Correct |
5 ms |
8396 KB |
Output is correct |
3 |
Correct |
5 ms |
8496 KB |
Output is correct |
4 |
Correct |
5 ms |
8456 KB |
Output is correct |
5 |
Correct |
5 ms |
8396 KB |
Output is correct |
6 |
Correct |
5 ms |
8492 KB |
Output is correct |
7 |
Correct |
6 ms |
8396 KB |
Output is correct |
8 |
Correct |
5 ms |
8396 KB |
Output is correct |
9 |
Correct |
5 ms |
8396 KB |
Output is correct |
10 |
Correct |
5 ms |
8500 KB |
Output is correct |
11 |
Correct |
5 ms |
8396 KB |
Output is correct |
12 |
Correct |
5 ms |
8396 KB |
Output is correct |
13 |
Correct |
5 ms |
8396 KB |
Output is correct |
14 |
Correct |
5 ms |
8396 KB |
Output is correct |
15 |
Correct |
5 ms |
8424 KB |
Output is correct |
16 |
Correct |
5 ms |
8396 KB |
Output is correct |
17 |
Correct |
5 ms |
8396 KB |
Output is correct |
18 |
Correct |
6 ms |
8492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8396 KB |
Output is correct |
2 |
Correct |
5 ms |
8396 KB |
Output is correct |
3 |
Correct |
5 ms |
8496 KB |
Output is correct |
4 |
Correct |
5 ms |
8456 KB |
Output is correct |
5 |
Correct |
5 ms |
8396 KB |
Output is correct |
6 |
Correct |
5 ms |
8492 KB |
Output is correct |
7 |
Correct |
6 ms |
8396 KB |
Output is correct |
8 |
Correct |
5 ms |
8396 KB |
Output is correct |
9 |
Correct |
5 ms |
8396 KB |
Output is correct |
10 |
Correct |
5 ms |
8500 KB |
Output is correct |
11 |
Correct |
5 ms |
8396 KB |
Output is correct |
12 |
Correct |
5 ms |
8396 KB |
Output is correct |
13 |
Correct |
5 ms |
8396 KB |
Output is correct |
14 |
Correct |
5 ms |
8396 KB |
Output is correct |
15 |
Correct |
5 ms |
8424 KB |
Output is correct |
16 |
Correct |
5 ms |
8396 KB |
Output is correct |
17 |
Correct |
5 ms |
8396 KB |
Output is correct |
18 |
Correct |
6 ms |
8492 KB |
Output is correct |
19 |
Correct |
5 ms |
8396 KB |
Output is correct |
20 |
Correct |
6 ms |
8396 KB |
Output is correct |
21 |
Correct |
6 ms |
8396 KB |
Output is correct |
22 |
Correct |
7 ms |
8524 KB |
Output is correct |
23 |
Correct |
10 ms |
8528 KB |
Output is correct |
24 |
Correct |
7 ms |
8396 KB |
Output is correct |
25 |
Correct |
8 ms |
8524 KB |
Output is correct |
26 |
Correct |
9 ms |
8524 KB |
Output is correct |
27 |
Correct |
5 ms |
8396 KB |
Output is correct |
28 |
Correct |
5 ms |
8396 KB |
Output is correct |
29 |
Correct |
5 ms |
8396 KB |
Output is correct |
30 |
Correct |
8 ms |
8524 KB |
Output is correct |
31 |
Correct |
8 ms |
8508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8396 KB |
Output is correct |
2 |
Correct |
5 ms |
8396 KB |
Output is correct |
3 |
Correct |
8 ms |
8524 KB |
Output is correct |
4 |
Correct |
51 ms |
9132 KB |
Output is correct |
5 |
Correct |
125 ms |
10024 KB |
Output is correct |
6 |
Correct |
153 ms |
10536 KB |
Output is correct |
7 |
Correct |
186 ms |
10908 KB |
Output is correct |
8 |
Correct |
308 ms |
12604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8396 KB |
Output is correct |
2 |
Correct |
5 ms |
8396 KB |
Output is correct |
3 |
Correct |
5 ms |
8496 KB |
Output is correct |
4 |
Correct |
5 ms |
8456 KB |
Output is correct |
5 |
Correct |
5 ms |
8396 KB |
Output is correct |
6 |
Correct |
5 ms |
8492 KB |
Output is correct |
7 |
Correct |
6 ms |
8396 KB |
Output is correct |
8 |
Correct |
5 ms |
8396 KB |
Output is correct |
9 |
Correct |
5 ms |
8396 KB |
Output is correct |
10 |
Correct |
5 ms |
8500 KB |
Output is correct |
11 |
Correct |
5 ms |
8396 KB |
Output is correct |
12 |
Correct |
5 ms |
8396 KB |
Output is correct |
13 |
Correct |
5 ms |
8396 KB |
Output is correct |
14 |
Correct |
5 ms |
8396 KB |
Output is correct |
15 |
Correct |
5 ms |
8424 KB |
Output is correct |
16 |
Correct |
5 ms |
8396 KB |
Output is correct |
17 |
Correct |
5 ms |
8396 KB |
Output is correct |
18 |
Correct |
6 ms |
8492 KB |
Output is correct |
19 |
Correct |
5 ms |
8396 KB |
Output is correct |
20 |
Correct |
6 ms |
8396 KB |
Output is correct |
21 |
Correct |
6 ms |
8396 KB |
Output is correct |
22 |
Correct |
7 ms |
8524 KB |
Output is correct |
23 |
Correct |
10 ms |
8528 KB |
Output is correct |
24 |
Correct |
7 ms |
8396 KB |
Output is correct |
25 |
Correct |
8 ms |
8524 KB |
Output is correct |
26 |
Correct |
9 ms |
8524 KB |
Output is correct |
27 |
Correct |
5 ms |
8396 KB |
Output is correct |
28 |
Correct |
5 ms |
8396 KB |
Output is correct |
29 |
Correct |
5 ms |
8396 KB |
Output is correct |
30 |
Correct |
8 ms |
8524 KB |
Output is correct |
31 |
Correct |
8 ms |
8508 KB |
Output is correct |
32 |
Correct |
5 ms |
8396 KB |
Output is correct |
33 |
Correct |
5 ms |
8396 KB |
Output is correct |
34 |
Correct |
8 ms |
8524 KB |
Output is correct |
35 |
Correct |
51 ms |
9132 KB |
Output is correct |
36 |
Correct |
125 ms |
10024 KB |
Output is correct |
37 |
Correct |
153 ms |
10536 KB |
Output is correct |
38 |
Correct |
186 ms |
10908 KB |
Output is correct |
39 |
Correct |
308 ms |
12604 KB |
Output is correct |
40 |
Correct |
11 ms |
8524 KB |
Output is correct |
41 |
Correct |
16 ms |
8652 KB |
Output is correct |
42 |
Correct |
23 ms |
8744 KB |
Output is correct |
43 |
Correct |
121 ms |
10136 KB |
Output is correct |
44 |
Correct |
303 ms |
12720 KB |
Output is correct |
45 |
Correct |
60 ms |
9212 KB |
Output is correct |
46 |
Correct |
182 ms |
10916 KB |
Output is correct |
47 |
Correct |
304 ms |
12612 KB |
Output is correct |
48 |
Correct |
303 ms |
12884 KB |
Output is correct |
49 |
Correct |
280 ms |
12000 KB |
Output is correct |
50 |
Correct |
284 ms |
12084 KB |
Output is correct |