Submission #696093

# Submission time Handle Problem Language Result Execution time Memory
696093 2023-02-05T11:58:05 Z Kahou Hacker (BOI15_hac) C++14
100 / 100
73 ms 41788 KB
/* In the name of God, aka Allah */
// let this be mytemp.cpp
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 5e5 + 50, LG = 20;
int n, a[N], sum, s[N], sp[LG][N];

int get(int l, int r) {
	int k = 31-__builtin_clz(r-l+1);
	return max(sp[k][l], sp[k][r-(1<<k)+1]);
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 1; i <= 2*n; i++) {
		s[(i-1)%n+1] = s[(i-2)%n+1] + a[(i-1)%n+1];
		if (i > n/2) s[(i-1)%n+1] -= a[(i-n/2-1)%n+1];
	}
	for (int i = 1; i <= n; i++) {
		sp[0][i] = s[i];
	}
	for (int k = 1; k < LG; k++) {
		for (int i = 1; i <= (n-(1<<k)+1); i++) {
			sp[k][i] = max(sp[k-1][i], sp[k-1][i+(1<<(k-1))]);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i + n/2 > n) {
			ans = max(ans, sum-get((i+(n/2)-1)%n+1, i-1));
		}
		else {
			ans = max(ans, sum-max((i > 1? get(1, i-1):0), get(i+(n/2), n)));
		}
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 628 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 324 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 11 ms 6148 KB Output is correct
5 Correct 26 ms 15812 KB Output is correct
6 Correct 33 ms 19936 KB Output is correct
7 Correct 41 ms 24392 KB Output is correct
8 Correct 67 ms 41464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 628 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 620 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 324 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 11 ms 6148 KB Output is correct
36 Correct 26 ms 15812 KB Output is correct
37 Correct 33 ms 19936 KB Output is correct
38 Correct 41 ms 24392 KB Output is correct
39 Correct 67 ms 41464 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 4 ms 1620 KB Output is correct
42 Correct 5 ms 2360 KB Output is correct
43 Correct 35 ms 15820 KB Output is correct
44 Correct 72 ms 41448 KB Output is correct
45 Correct 13 ms 7636 KB Output is correct
46 Correct 40 ms 24276 KB Output is correct
47 Correct 73 ms 41492 KB Output is correct
48 Correct 67 ms 41788 KB Output is correct
49 Correct 63 ms 39900 KB Output is correct
50 Correct 64 ms 40900 KB Output is correct