Submission #256616

# Submission time Handle Problem Language Result Execution time Memory
256616 2020-08-03T02:25:34 Z super_j6 Hacker (BOI15_hac) C++14
100 / 100
80 ms 18808 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

struct mque{
	stack<pi> s1, s2;
	
	ll mn(stack<pi> &s){
		return s.empty() ? 0x3f3f3f3f3f3f3f3f : s.top().s;
	}
	
	void add(ll x){
		s1.push({x, min(x, mn(s1))});
	}
	
	void del(){
		if(s2.empty()) for(; !s1.empty(); s1.pop()) s2.push({s1.top().f, min(s1.top().f, mn(s2))});
		s2.pop();
	}
	
	ll qry(){
		return min(mn(s1), mn(s2));
	}
};

const int mxn = 1500001;
int n;
ll a[mxn];
mque q;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		for(int j = 1; j < 3; j++) a[j * n + i] = a[i];
		a[i] += a[i - 1];
	}
	
	ll ret = 0;
	for(int i = n + 1; i <= 3 * n; i++){
		a[i] += a[i - 1];
		q.add(a[i] - a[i - (n + 1) / 2]);
		if(i - n > (n + 1) / 2) q.del(), ret = max(ret, q.qry());
	}
	
	cout << ret << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 416 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 14 ms 2944 KB Output is correct
5 Correct 30 ms 6784 KB Output is correct
6 Correct 40 ms 8312 KB Output is correct
7 Correct 44 ms 9976 KB Output is correct
8 Correct 80 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 416 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 14 ms 2944 KB Output is correct
36 Correct 30 ms 6784 KB Output is correct
37 Correct 40 ms 8312 KB Output is correct
38 Correct 44 ms 9976 KB Output is correct
39 Correct 80 ms 16376 KB Output is correct
40 Correct 2 ms 768 KB Output is correct
41 Correct 3 ms 1024 KB Output is correct
42 Correct 5 ms 1408 KB Output is correct
43 Correct 30 ms 7672 KB Output is correct
44 Correct 75 ms 18552 KB Output is correct
45 Correct 15 ms 3840 KB Output is correct
46 Correct 45 ms 11256 KB Output is correct
47 Correct 77 ms 18552 KB Output is correct
48 Correct 75 ms 18808 KB Output is correct
49 Correct 66 ms 17920 KB Output is correct
50 Correct 68 ms 17912 KB Output is correct