玄关!求助!
查看原帖
玄关!求助!
1109550
Fish_Water楼主2025/2/7 14:49
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=2e5+10;
const int eps=1;
int t,n,m,cnt,ans[N],a[N];
struct edge{
	int m,d;
}cost[N];
bool cmp(edge x,edge y){
	return x.m<y.m;
}
int judge(int x,int y){
	if(x<y) return cost[x].m+a[cost[y].d]+cost[y].d;
	else return cost[x].m-(cost[y].m-cost[y-1].m)+a[cost[y].d]+cost[y].d;
}
int find(int x){
	int l=0,r=n+1; 
	while(r-l>eps){
		int mid=(l+r)>>1;
		if(judge(mid,x)<=m) l=mid;
		else r=mid;
	}
	return l;
}
signed main(){
	cin>>t;
	while(t--){
		cnt++;
		cin>>n>>m;
		for(int i=1;i<=n;i++) cin>>a[i]; 
		for(int i=1;i<=n;i++) cost[i].m=min(a[i]+i,a[i]+n-i+1),cost[i].d=i;
		sort(cost+1,cost+1+n,cmp);
		for(int i=1;i<=n;i++) cost[i].m+=cost[i-1].m;
		for(int i=1;i<=n;i++) ans[cnt]=max(ans[cnt],find(i));
	}
	for(int i=1;i<=cnt;i++) cout<<ans[i]<<'\n';
}
2025/2/7 14:49
加载中...