ARC B 题 求助
  • 板块学术版
  • 楼主CodeBoy
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/11/20 22:09
  • 上次更新2023/10/27 02:08:18
查看原帖
ARC B 题 求助
253068
CodeBoy楼主2022/11/20 22:09
constexpr int N = 200005;
int a[N];
set<int> s;
signed main(){
  	int n, l;
  	cin>>n>>l;
  	for(int i = 1; i <= n; i++) cin>>a[i];
  	int ans = inf;
  	for(int i = 1; i <= n; i++){
  		s.insert(l - a[i]);
  	}
  	int mi = inf;
  	for(int i = 1; i <= n; i++){
		set<int>::iterator it=s.lower_bound(a[i]);
        set<int>::iterator it2=it;
        if(it!=s.begin()) it--;
        if(it2==s.end()) it2--;
  		mi = min(mi, abs(a[i] - *it));
  		mi = min(mi, abs(a[i] - *it2));
  	}
  	  	ans = min(ans, mi * 2 + l * 2);
  	cout<<ans<<endl;
	return 0;
}

思路好像没问题但却WA了, 是哪里写挂了吗?

2022/11/20 22:09
加载中...