Submission #893122

# Submission time Handle Problem Language Result Execution time Memory
893122 2023-12-26T14:29:26 Z LCJLY Hacker (BOI15_hac) C++14
20 / 100
49 ms 15948 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<=2*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<=2*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()&&x>=k)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();
	}	
}



		


		
		
	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 8 ms 2904 KB Output is correct
5 Correct 20 ms 6492 KB Output is correct
6 Correct 24 ms 8284 KB Output is correct
7 Correct 29 ms 9824 KB Output is correct
8 Correct 49 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -