https://codeforces.com/gym/580226/problem/G
#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define lowbit(x) x&(-x)
#define endl '\n'
using ll = long long;
using pii = pair<int,int>;
const double PI = acos(-1);
const int N=2e5+10;
set<pii> ss;
int ans[N];
void solve(){
int n,m,d;cin>>n>>m>>d;
for(int i=1;i<=n;i++)
{
int x;cin>>x;
ss.insert(make_pair(x,i));
}
int day=0;
while(ss.size()){
day++;
int pos=ss.begin()->second;
int x=ss.begin()->first;
ans[pos]=day;
ss.erase(ss.begin());
while(1){
auto t=ss.lower_bound(make_pair(x+d+1,0));
if(t==ss.end()) break;
pos=t->second;
x=t->first;
ans[pos]=day;
ss.erase(t);
}
}
cout<<day<<endl;
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
浙公网安备 33010602011771号