Submission #589683

# Submission time Handle Problem Language Result Execution time Memory
589683 2022-07-05T06:24:00 Z penguinhacker Hacker (BOI15_hac) C++17
100 / 100
66 ms 13640 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=5e5;
int n, a[2*mxN], p[2*mxN+1], val[2*mxN+1];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> a[i];
		a[i+n]=a[i];
	}
	for (int i=0; i<2*n; ++i)
		p[i+1]=p[i]+a[i];
	for (int i=1; i+n/2<=2*n; ++i)
		val[i]=p[i+n/2]-p[i];
	int ans=0;
	/*for (int i=0; i<n; ++i) {
		int mx=0;
		for (int j=1; j<=(n+1)/2; ++j)
			mx=max(mx, val[i+j]);
		ans=max(ans, p[n]-mx);
	}*/
	deque<int> dq;
	for (int i=1; i<=n-1+(n+1)/2; ++i) {
		while(dq.size()&&val[i]>=val[dq.back()])
			dq.pop_back();
		dq.push_back(i);
		if (i-dq[0]>=(n+1)/2)
			dq.pop_front();
		assert(dq.size());
		if (i>=(n+1)/2)
			ans=max(ans, p[n]-val[dq[0]]);
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 8 ms 2004 KB Output is correct
5 Correct 20 ms 5536 KB Output is correct
6 Correct 26 ms 6732 KB Output is correct
7 Correct 38 ms 8156 KB Output is correct
8 Correct 66 ms 13312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 8 ms 2004 KB Output is correct
36 Correct 20 ms 5536 KB Output is correct
37 Correct 26 ms 6732 KB Output is correct
38 Correct 38 ms 8156 KB Output is correct
39 Correct 66 ms 13312 KB Output is correct
40 Correct 1 ms 588 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 4 ms 1044 KB Output is correct
43 Correct 21 ms 5472 KB Output is correct
44 Correct 51 ms 13152 KB Output is correct
45 Correct 14 ms 2772 KB Output is correct
46 Correct 35 ms 8092 KB Output is correct
47 Correct 56 ms 13132 KB Output is correct
48 Correct 46 ms 13432 KB Output is correct
49 Correct 43 ms 13640 KB Output is correct
50 Correct 40 ms 13576 KB Output is correct