Cod sursa(job #53468)

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

#define cmax 1024
#define lmax 1000001

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

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[l - (a[i] + a[j])];
		for(j = 0; j < i; j++) 
			hs[a[i] + a[j]]++;
	}

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