7 3 1 2 3 4 5 -2 6
3
1 #include <iostream> 2 #include <algorithm> 3 #include <string.h> 4 #include <vector> 5 #include <queue> 6 7 #define inf 0x3f3f3f3f 8 9 using namespace std; 10 11 int main() 12 { 13 int n, k, i, cur, num; 14 int a[10005]; 15 cin >> n >> k; 16 for(i=0;i<n;i++) 17 { 18 cin >> a[i]; 19 } 20 sort(a, a+n); 21 cur = a[0] + k; 22 num = 1; 23 for(i=1;i<n;i++) 24 { 25 if(a[i]>cur) 26 { 27 cur = a[i]+k; 28 num++; 29 } 30 } 31 cout << num << endl; 32 return 0; 33 }
原文:https://www.cnblogs.com/0xiaoyu/p/14096445.html