Pagini recente » Istoria paginii runda/dddhxgdxnch/clasament | Cod sursa (job #2308691) | Cod sursa (job #152299) | Cod sursa (job #2341748) | Cod sursa (job #1770233)
#include<bits/stdc++.h>
#define cheie 666013
#define maxC 1035
using namespace std;
vector<pair<int,int> > h[cheie+5];
vector<pair<int,int> >::iterator it;
int n,l,v[maxC];
long long posibilitati;
void hadd(int x)
{
int y=x%cheie;
for(it=h[y].begin();it!=h[y].end();it++)
{
if((*it).first==x)
{
(*it).second++;
return;
}
}
h[y].push_back(make_pair(x,1));
}
int hsearch(int x)
{
int y=x%cheie;
for(it=h[y].begin();it!=h[y].end();it++)
{
if((*it).first==x)
{
return (*it).second;
}
}
return 0;
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++)
{
scanf("%d",&v[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=(i+1);j<=n;j++)
{
if((v[i]+v[j])<l)
{
int dif=l-v[i]-v[j];
posibilitati=posibilitati+1LL*hsearch(dif);
}
}
for(int j=1;j<i;j++)
{
if((v[i]+v[j])<l)
{
hadd(v[i]+v[j]);
}
}
}
printf("%lld\n",posibilitati);
return 0;
}