2024.11.16下午千里传送:传送网址:

#include<bits/stdc++.h>
using namespace std;
int n,c,t,ans;
long long a[200005],b[200005];
long long sum[200005];
int p[200005],rp[200005];
bool cmp(int x,int y){
	return b[x]<b[y];
}
int col(int x){
	if(a[x]+x>c)return 0;
	int l=0,r=n;
	long long w;
	while(l<r){
		int mid=(l+r+1)/2;
		w=sum[mid]+a[x]+x;
		if(rp[x]<=mid){
			w-=b[x];
		}
		if(w<=c){
			l=mid;
		}
		else {
			r=mid-1;
		}
	}
	return l+(rp[x]>l);
} 
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&c);
		for(int i=1;i<=n;++i){
			scanf("%lld",&a[i]);
			b[i]=a[i]+min(i,n-i+1);
			p[i]=i;
		}	
		sort(p+1,p+n+1,cmp);
		for(int i=1;i<=n;++i){
			sum[i]=sum[i-1]+b[p[i]];
			rp[p[i]]=i;
		}
		for(int i=1;i<=n;++i){
			ans=max(ans,col(i));
		}
		printf("%d\n",ans);
	}
    return 0;
}

格式化