답안 #893108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893108 2023-12-26T14:12:36 Z LCJLY Hacker (BOI15_hac) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

void solve(){	
	int n;
	cin >> n;
	int arr[2*n+1];
	for(int x=1;x<=n;x++){
		cin >> arr[x];
		arr[x+n]=arr[x];
	}
	
	int prefix[2*n+1];
	memset(prefix,0,sizeof(prefix));
	for(int x=1;x<=n;x++){
		prefix[x]=prefix[x-1]+arr[x];
	}
	
	int k=(n+1)/2;
	
	int ptr=k;
	deque<pii>d;
	int best=0;
	for(int x=1;x<=n;x++){
		while(ptr<=2*n&&ptr<=x+k-1){
			while(!d.empty()&&d.back().first>prefix[ptr]-prefix[ptr-k]){
				d.pop_back();
			}
			d.push_back({prefix[ptr]-prefix[ptr-k],ptr});
			ptr++;
		}
		
		while(!d.empty()&&d.front().second<x) d.pop_front();
		
		if(!d.empty())best=max(best,d.front().first);
	}
	cout << best;
	
}

int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("in.txt", "r", stdin);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}



		


		
		
	
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -