You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
485 B
24 lines
485 B
#include<bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
//定义大数组,放在主函数外边
|
|
int a[1000001], n, f, i, j, k;
|
|
|
|
int main() {
|
|
cin >> n >> f;
|
|
for (i = 1; i <= n; ++i)
|
|
cin >> a[i];
|
|
|
|
k = 0;
|
|
//对数组进行一次排序
|
|
sort(a + 1, a + (n + 1));
|
|
//双重循环
|
|
for (i = 1; i < n; i++)
|
|
for (j = i + 1; j <= n; ++j) {
|
|
if (a[j] - a[i] > f)
|
|
break;
|
|
k++;
|
|
}
|
|
cout << k << endl;
|
|
return 0;
|
|
} |