Pagini recente » Cod sursa (job #1344620) | Cod sursa (job #2057708) | Cod sursa (job #461284) | Cod sursa (job #225812) | Cod sursa (job #53840)
Cod sursa(job #53840)
#include<stdio.h>
const int maxn = 1025;
const int tabm = 1148576;
int i;
int n;
int k;
int j;
int a[maxn];
long long sol;
int ta[tabm];
int ta2[tabm];
int hash(int i)
{
return i % tabm;
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%d %d",&n,&k);
for(i = 1;i <= n; ++i)
{
scanf("%d",&a[i]);
}
for(i = 1;i <= n; ++i)
{
for(j = 1;j < i; ++j)
{
if (a[i] + a[j] <= k)
{
// int aux = sol;
sol += ta[hash(k - a[i] - a[j])];
// if (ta[hash(k - a[i] - a[j])] > 0)
/* {
printf("%d\n",k - a[i] - a[j]);
}*/
if (a[i] + a[j] * 2 <= k)sol -= ta2[hash(k - a[i] - a[j] * 2)];
if (k - a[i] - a[j] * 2 == a[j]) sol++;
//if (sol < 0) printf("%d %d\n",i,j);
// if (sol > aux) printf("%d %d %d\n",i,j,sol - aux);
}
}
// printf("%d %d\n",i,sol);
for(j = 1;j < i; ++j)
{
ta[hash(a[i] + a[j])]++;
}
ta2[hash(a[i])]++;
}
printf("%lld\n",sol / 3);
return 0;
}