Pagini recente » Cod sursa (job #240275) | Cod sursa (job #2862498) | Cod sursa (job #2410882) | Cod sursa (job #1918960) | Cod sursa (job #251419)
Cod sursa(job #251419)
#include<cstdio>
//#include<ctime>
//#include<cstdlib>
#include<algorithm>
#include<vector>
#define NMAX 1024
#define MOD 666013
using namespace std;
int A[NMAX];
vector< pair<int,int> >H[MOD];
inline int find(const int val)
{
vector< pair< int,int > >::iterator it;
int pos=val%MOD;
int a1,a2;
int i;
for(i=0; i<H[pos].size(); ++i)
{
if( H[pos][i].first==val )
return H[pos][i].second;
}
return 0;
}
inline void insert(const int val)
{
vector< pair< int,int > >::iterator it;
int pos=val%MOD;
for( it=H[pos].begin(); it!=H[pos].end(); ++it )
{
if( it->first==val )
{
++(it->second);
return;
}
}
H[ pos ].push_back(make_pair(val,1));
}
inline void erase(const int val)
{
vector< pair< int,int > >::iterator it;
int pos=val%MOD;
for( it=H[pos].begin(); it!=H[pos].end(); ++it )
if( it->first==val )
{
--it->second;
if( it->second==0 )
H[pos].erase(it);
return;
}
}
int main()
{
//double start=clock();
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
int N,L,ANS=0;
scanf("%d%d",&N,&L);
int i,j;
int a1;
for(i=1; i<=N; ++i)
{
scanf("%d",&a1);
if( a1<L )
A[i]=a1;
else
--i,--N;
}
sort( A+1, A+1+N );
for(i=3; i<=N-1; ++i)
for(j=i+1; j<=N; ++j)
if( A[i]+A[j]<L )
insert( A[i]+A[j] );
int bs;//bun simt
for(i=2; i<=N-2; ++i)
{
for(j=1; j<i; ++j)
{
bs=L-A[i]-A[j];
if( bs>0 )
ANS+=find( bs );
}
for(j=i+2; j<=N; ++j)
if( A[i+1]+A[j]<L )
erase( A[i+1]+A[j] );
}
printf("%d\n",ANS);
//printf("%lf\n",clock()-start/(double)CLOCKS_PER_SEC);//f. imprecis
return 0;
}