谁能帮我优化优化(轩哥不用劳烦你),玄关
查看原帖
谁能帮我优化优化(轩哥不用劳烦你),玄关
998650
OTH_chinese_dragon楼主2024/8/5 16:41
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int main(){
	long long n,m;
	cin>>n>>m;
	for(long long i=0; i<n; i++){
		cin>>a[i];
	}
	long long cnt=0;
	stable_sort(a,a+n);
	for(long long k=n; k>=0; k--){
		for(long long i=0; i<k+1; i++){
			if(a[k]-a[i]==m){
				cnt++;
			}
		}
	}
	
	cout<<cnt;
	return 0;
}

2024/8/5 16:41
加载中...