Pagini recente » Cod sursa (job #2952339) | Cod sursa (job #1055888) | Cod sursa (job #1717850) | Cod sursa (job #188655) | Cod sursa (job #931587)
Cod sursa(job #931587)
#include <fstream>
#define nmax 100100
#define value first
#define index second
using namespace std;
pair <int,int> V[nmax];
int N,D,Nr,Answer[nmax];
void solve() {
int Left,Right;
sort(V+1,V+N+1);
for(Left=Right=1;Left<=N;Left++) {
if(!Answer[V[Left].index])
Answer[V[Left].index]=++Nr;
for(;Right<=N && (Answer[V[Right].index] || V[Right].value-V[Left].value < D);Right++);
if(Right<=N)
Answer[V[Right].index]=Answer[V[Left].index];
}
}
void read() {
ifstream in("partitie.in");
in>>N>>D;
for(int i=1;i<=N;i++) {
in>>V[i].value;
V[i].index=i;
}
in.close();
}
void write() {
ofstream out("partitie.out");
out<<Nr<<'\n';
for(int i=1;i<=N;i++)
out<<Answer[i]<<'\n';
out.close();
}
int main() {
read();
solve();
write();
return 0;
}