답안 #748457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748457 2023-05-26T10:07:57 Z mariowong Hacker (BOI15_hac) C++14
100 / 100
94 ms 14736 KB
#include <bits/stdc++.h>
 
using namespace std;
int n,a[500005],pre[500005],sum,r,l,ans,ttl;
priority_queue <pair<int,int>  > mx;
bool chk(int x,int y,int a1){
	if (x > y){
		if (a1 >= x || a1 <= y)
		return false;
		return true;
	}
	else
	{
		if (x <= a1 && a1 <= y)
		return false;
		return true;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n; ans=2e9;
	for (int i=0;i<n;i++){
		cin >> a[i];
		ttl+=a[i];
	}
	r=n/2-1;
	for (int i=0;i<n/2;i++){
		sum+=a[i];
	}
	for (int i=0;i<n;i++){
		pre[i]=sum;
		sum-=a[i];
		r++; r%=n;
		sum+=a[r];
	}
	l=n/2; r=n-1;
	for (int i=l;i<=r;i++){
		mx.push(make_pair(pre[i],i));
	}
	for (int i=0;i<n;i++){
		while (!mx.empty() && chk(l,r,mx.top().second)){
			mx.pop();
		}
		ans=min(ans,mx.top().first);
		l++; r++; l%=n; r%=n;
		mx.push(make_pair(pre[r],r));
	}
	cout << ttl-ans << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 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 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 14 ms 2388 KB Output is correct
5 Correct 34 ms 4820 KB Output is correct
6 Correct 48 ms 5572 KB Output is correct
7 Correct 45 ms 8240 KB Output is correct
8 Correct 72 ms 14736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 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 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 476 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 14 ms 2388 KB Output is correct
36 Correct 34 ms 4820 KB Output is correct
37 Correct 48 ms 5572 KB Output is correct
38 Correct 45 ms 8240 KB Output is correct
39 Correct 72 ms 14736 KB Output is correct
40 Correct 2 ms 656 KB Output is correct
41 Correct 3 ms 884 KB Output is correct
42 Correct 6 ms 1368 KB Output is correct
43 Correct 29 ms 6932 KB Output is correct
44 Correct 84 ms 14692 KB Output is correct
45 Correct 14 ms 2528 KB Output is correct
46 Correct 54 ms 8196 KB Output is correct
47 Correct 94 ms 14672 KB Output is correct
48 Correct 83 ms 10904 KB Output is correct
49 Correct 60 ms 14052 KB Output is correct
50 Correct 58 ms 14048 KB Output is correct