fork download
  1. #include<stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6. int n, l;
  7. scanf("%d %d", &n, &l);
  8. int arr[1001];
  9. for (int i = 0; i < n; i++)
  10. {
  11. int temp;
  12. scanf("%d", &temp);
  13. arr[temp] = 1;
  14. }
  15.  
  16.  
  17. int count = 0;
  18.  
  19. for (int i = 1; i <= 1000;)
  20. {
  21. if (arr[i] == 1)
  22. {
  23. count++;
  24. for (int j = i; j <= l; j++)
  25. {
  26. arr[j] = 0;
  27. }
  28. i += l;
  29. }
  30. else i++;
  31.  
  32. }
  33.  
  34. printf("%d", count);
  35.  
  36. }
Success #stdin #stdout 0s 5288KB
stdin
2 1
4 1
stdout
27