- Source Code
#include<iostream> #include<algorithm> #include<string.h> using namespace std; int main() { int k, n; while (cin >> k >> n && (k + n) != -2) { int a[1003]; int j = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a,a + n); bool b[1002]; memset(b, false, sizeof(b)); int s = 0; for (int i = 0; i < n; i++) { s++; for (int j = i+1; j < n; j++) { if (a[j] - a[i] > k) { i = j - 1; break; } if (j == n - 1) i = n - 1; } for (int j = i+1; j < n; j++) { if (a[j] - a[i] > k) { i = j - 1; break; } if (j == n - 1) i = n - 1; } } cout << s << endl; } return 0; }