Cod sursa(job #53469)

Utilizator alextheroTandrau Alexandru alexthero Data 22 aprilie 2007 11:19:36
Problema Oite Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <stdio.h>
#include <string.h>

#define cmax 1024
#define lmax 1000001
#define mod 1000001

int c,l,tot,i,j;
int a[cmax],hs[lmax];

inline int hash(int x) {
	return x % mod;
}

int main() {
	freopen("oite.in","r",stdin);
	freopen("oite.out","w",stdout);

	scanf("%d%d",&c,&l);
	for(i = 0; i < c; i++) scanf("%d",&a[i]);

	memset(hs,0,sizeof(hs));

	for(i = 0; i < c; i++) { 
		for(j = i + 1; j < c; j++) 
			if(l - (a[i] + a[j]) >= 0) 
				tot += hs[hash(l - (a[i] + a[j]))];
		for(j = 0; j < i; j++) 
			hs[hash(a[i] + a[j])]++;
	}

	printf("%d\n",tot);
	return 0;
}