Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<map>
- #include<set>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- using namespace std;
- const int N = 1e5;
- set<pair<int, int>> a;
- int n;
- int d;
- int ans[N];
- bool used[N];
- int main() {
- scanf("%d%d", &n, &d);
- for(int i = 0; i < n; i++){
- int x;
- scanf("%d", &x);
- a.insert(make_pair(x, i));
- }
- int var = 1;
- for(auto i : a){
- if(!used[i.second]){
- ans[i.second] = var;
- auto it = a.lower_bound(make_pair(i.first + d + 1, -1));
- while(it != a.end()){
- if(!used[it->second]){
- ans[it->second] = var;
- used[it->second] = true;
- it = a.lower_bound(make_pair(it->first + d + 1, -1));
- }
- else{
- ++it;
- }
- }
- var++;
- }
- }
- printf("%d\n", var-1);
- for(int i = 0; i < n; i++){
- printf("%d ", ans[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement