Cod sursa(job #569455)

Utilizator gramatovici_paulGramatovici Paul gramatovici_paul Data 1 aprilie 2011 15:17:04
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<stdio.h>
#include<algorithm>

using namespace std;


int n,k,p[100001],x[100001],i,j,s;
int main()
{
	freopen("elemente.in","r",stdin);
	freopen("elemente.out","w",stdout);
	scanf("%d%d",&n,&k);
	p[0]=1;
	for(i=1;i<=n;++i)
	{
		p[i]=(p[i-1]*2)%1000003;
		scanf("%d",&x[i]);
	}
	sort(x+1,x+n+1);
	j=1;
	for(i=1;i<=n;++i)
	{
		while (j<=n && x[j]-x[i]<=k)
			++j;
		s=s+p[j-i-1];
		if(s>=1000003)
			s-=1000003;
	}
	printf("%d",s);
}