Pagini recente » Cod sursa (job #2070501) | Cod sursa (job #2157150) | Cod sursa (job #12051) | Cod sursa (job #1466899) | Cod sursa (job #2184226)
#include<cstdio>
#include<vector>
#define MOD 666013
using namespace std;
int v[1025];
vector<pair<int,int> > hash[666013];
int main ()
{freopen ("oite.in","r",stdin);
freopen ("oite.out","w",stdout);
int n,i,j,k,x,l,q,nr;
bool pp;
nr = 0;
scanf("%d%d",&n,&k);
for(i = 1; i <= n; i++)
scanf("%d",&v[i]);
for(i = 1; i <= n; i++)
for(j = n; j >= 1; j--)
if(j > i && v[i] + v[j] <= k)
{// numar perechile din hash cu care perechea i,j poate juca
x = k - (v[i] + v[j]);
q = x % MOD;
for(l = 0; l < hash[q].size(); l++)
if(hash[q][l].first == x)
nr += hash[q][l].second;
}
else if(j < i)
{// adaug perechea i,j in hash
x = v[i] + v[j];
q = x % MOD;
pp = false;
for(l = 0; l < hash[q].size(); l++)
if(hash[q][l].first == x)
{hash[q][l].second++;
pp = true;
l = hash[q].size();
}
if(pp == false)
hash[q].push_back(make_pair(x, 1));
}
printf("%d",nr);
return 0;
}