求助,为什么全WA
查看原帖
求助,为什么全WA
913288
3_14楼主2024/6/16 17:13
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+1;
int n,d,p[MAX];
int main(){
	cin>>n>>d;
	for(int i=1;i<=n;i++)cin>>p[i];
	sort(p+1,p+1+n);
	int ans=0;
	for(int i=2;i<n;i++){
		if(p[i+1]&&p[i-1]&&p[i+1]-p[i-1]<=d){
			p[i]=0;
			ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}
/*
100 2000
15214 11340 9327 28099 1728 32333 11211 5070 17280 4521 4636 2029 22831 17588 15863 20910 16184 18171 8001 26033 2757 16332 19362 8274 3799 15864 16183 21384 17046 21719 5511 27661 25062 2701 20153 29120 31802 31628 29956 26439 26029 22362 13926 19704 15951 6805 18073 19194 956 10804 7491 18087 24820 13327 25709 26421 12390 30882 11062 19862 25678 25101 12488 924 18753 3168 23436 26209 22278 8982 12442 4070 936 14303 24436 1018 19657 30371 13811 9310 27449 23235 4225 12326 25800 18850 6793 21090 28760 13924 29484 1022 24630 13045 2614 17639 1706 4685 18768 28783

80
*/
2024/6/16 17:13
加载中...