#include using namespace std; int main() { int n, d; cin >> n >> d; vector> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(make_pair(a, i)); } sort(v.begin(), v.end()); vector answer(n, 0); int count = 0; int num = 0; for (int i = 0; i < n; i++) { while (v.at(i).first - d >= v.at(num).first) { count++; num++; } if (v.at(i).first - d < v.at(num).first) { answer.at(v.at(i).second) = count; } } for (int x : answer) { cout << x << endl; } }