Cod sursa(job #182354)

Utilizator ErgoVicol Sergiu Constantin Ergo Data 20 aprilie 2008 19:04:04
Problema Partitie Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
// Partitie . infoareana
// Schimb sortarea la mutarea pe linux
#include <fstream>
#include <algorithm>
using namespace std;

#define NMAX 300009

ifstream fin("partitie.in");
ofstream fout("partitie.out");
struct part
{
	int v;
	int c;
}  ;
int sortare(part a,part b)
{
	return (a.v<b.v);
}
int main()
{
	part A[NMAX];
	int n,s;
	long long aux;
	int i,j;

	fin>>n>>s;
	for (i=1;i<=n;i++)
	{
		fin>>A[i].v;
		A[i].c=i;
	}

	sort(A+1,A+(n+1),sortare);
	int Sf,St;
	Sf=St=1;
	int max=0;
	for (Sf=1;Sf<=n;Sf++)
		{
			while (A[Sf].v-A[St].v>=s)
			{
				if (Sf-St>max) max=Sf-St;
				St++;
			}

		}
	fout<<max<<'\n';
	for (i=1,j=1;i<=n;i++,j=j%max+1)
		A[A[i].c].v=j;
	for (i=1;i<=n;i++)
		fout<<A[i].v<<'\n';
	fout.close();
	return 0;
}