Pagini recente » Istoria paginii utilizator/vamvudenisa | Cod sursa (job #205850) | Cod sursa (job #1194553) | Istoria paginii utilizator/casian307 | Cod sursa (job #53469)
Cod sursa(job #53469)
#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;
}