Cod sursa(job #461295)

Utilizator SpiderManSimoiu Robert SpiderMan Data 6 iunie 2010 11:33:00
Problema Partitie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <algorithm>
using namespace std;

const char FIN[] = "partitie.in", FOU[] = "partitie.out";
const int MAX = 300005;

struct sol
{
    int el, ind;
} ;

sol V[MAX];
int X[MAX];
int N, D, solve;

bool operator <( const sol &lhs, const sol &rhs )
{
    return lhs.el < rhs.el;
}

int main()
{
	freopen(FIN , "r" , stdin);
	freopen(FOU , "w" , stdout);

	scanf("%d %d", &N, &D);

	for (int i = 1; i <= N; ++i)
		scanf("%d", &V[i].el), V[i].ind = i;

	sort(V + 1, V + N + 1);

	for (int i = 1, j = 1; i <= N; ++i)
		V[i].el - D >= V[j].el ? X[V[i].ind] = X[V[j++].ind] : X[V[i].ind] = ++solve;

	printf("%d\n", solve);

	for (int i = 1; i <= N; ++i)
		printf("%d\n", X[i]);

	return 0;
}