Submission #990044

# Submission time Handle Problem Language Result Execution time Memory
990044 2024-05-29T12:11:49 Z OAleksa Hacker (BOI15_hac) C++14
100 / 100
42 ms 25936 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 1e6 + 69;
int n, a[N], p[N], c[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n;
  	for (int i = 1;i <= n;i++)
  		cin >> a[i];
  	for (int i = n + 1;i <= 2 * n;i++)
  		a[i] = a[i - n];
  	int all = 0;
  	for (int i = 1;i <= n;i++)
  		all += a[i];
  	for (int i = 1;i <= 2 * n;i++)
  		p[i] = p[i - 1] + a[i];
  	auto Get = [&](int l, int r) {
  		if (l > r)
  			return p[n] - p[l - 1] + p[r];
  		return p[r] - p[l - 1];
  	};
  	int k = (n + 1) / 2, ans = 0;
  	for (int i = 1;i <= n;i++) {
  		int j = i - k + 1;
  		if (j <= 0)
  			j += n;
  		c[i] = Get(j, i);
  	}
  	deque<pair<int, int>> st;
  	for (int i = n - k + 2;i <= n;i++) {
  		while (!st.empty() && st.back().s >= c[i])
  			st.pop_back();
  		st.push_back({i, c[i]});
  	}
  	for (int i = 1;i <= n;i++) {
  		while (!st.empty() && st.back().s >= c[i])
  			st.pop_back();
  		st.push_back({i, c[i]});
  		ans = max(ans, st.front().s);
  		int j = i - k + 1;
  		if (j <= 0)
  			j += n;
  		if (st.front().f == j)
  			st.pop_front();
  	}
  	cout << ans << '\n';
  }
  return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 7 ms 9564 KB Output is correct
5 Correct 15 ms 14156 KB Output is correct
6 Correct 19 ms 14428 KB Output is correct
7 Correct 23 ms 18780 KB Output is correct
8 Correct 38 ms 22352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2508 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 7 ms 9564 KB Output is correct
36 Correct 15 ms 14156 KB Output is correct
37 Correct 19 ms 14428 KB Output is correct
38 Correct 23 ms 18780 KB Output is correct
39 Correct 38 ms 22352 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 2 ms 2904 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 16 ms 14172 KB Output is correct
44 Correct 37 ms 22336 KB Output is correct
45 Correct 8 ms 9564 KB Output is correct
46 Correct 24 ms 18756 KB Output is correct
47 Correct 42 ms 22356 KB Output is correct
48 Correct 33 ms 22612 KB Output is correct
49 Correct 32 ms 25936 KB Output is correct
50 Correct 32 ms 25856 KB Output is correct