比赛 2025暑期集训第4场 评测结果 AAAAA
题目名称 环路运输 最终得分 100
用户昵称 李奇文 运行时间 0.227 s
代码语言 C++ 内存使用 5.59 MiB
提交时间 2025-07-05 11:22:54
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+1;
int n,a[N],q[N],h,t,ans;
int main(){
	freopen("transportt.in","r",stdin);
	freopen("transportt.out","w",stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
    	a[i+n]=a[i];
    }
    for(int i=1;i<=n*2;i++){
    	while(h<=t&&i-q[h]>n/2) h++;
    	if(h<=t){
    		ans=max(ans,a[i]+a[q[h]]+i-q[h]);
    	}
    	while(h<=t&&a[q[t]]-q[t]<=a[i]-i){
    		t--;
    	}
    	q[++t]=i;
    }
    printf("%d",ans);
    return 0;
}