#include #include #include #include #include #include #include using namespace std; using ll = long long; struct P { bool operator<(const P &p) const { return a < p.a; } int a, i; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, d; cin >> n >> d; vector

p(n); for (int i = 0; i < n; i++) { int a; cin >> a; p[i] = { a, i }; } sort(p.begin(), p.end()); vector r(n); int j = 0; for (int i = 0; i < n; i++) { while (p[j].a <= p[i].a - d) j++; r[p[i].i] = j; } for (int i = 0; i < n; i++) { cout << r[i] << '\n'; } return 0; }