fork download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <algorithm>
  4. #include <stdio.h>
  5. #include <map>
  6. #include <vector>
  7. #include <set>
  8. #include <iomanip>
  9. using namespace std;
  10. const long long MaxLL = (long long)1e18;
  11. const int maxInt = (int)1e9, maxN = (int)1e5 + 228;
  12.  
  13. pair<int, int> a[maxN];
  14. vector<int> b;
  15. int ans[maxN], i, j, n, m;
  16.  
  17. int main() {
  18. // freopen(".in", "r", stdin);
  19. // freopen(".out", "w", stdout);
  20.  
  21. cin >> n >> m;
  22. for(i = 0; i < n; i++) {
  23. cin >> a[i].first;
  24. a[i].second = i;
  25. }
  26. sort(a, a + n);
  27.  
  28. for(i = 0; i < n; i++) {
  29. for(j = 0; j < b.size(); j++) {
  30. if(a[i].first - b[j] > m) break;
  31. }
  32.  
  33. ans[a[i].second] = j + 1;
  34. if(j == b.size()) b.push_back(0);
  35. b[j] = a[i].first;
  36. }
  37.  
  38. cout << b.size() << "\n";
  39. for(i = 0; i < n; i++) {
  40. cout << ans[i] << " ";
  41. }
  42. puts("");
  43. }
  44.  
Success #stdin #stdout 0s 4592KB
stdin
Standard input is empty
stdout
0