Pagini recente » Cod sursa (job #3150081) | Cod sursa (job #1793195) | Cod sursa (job #1005493) | Cod sursa (job #2907662) | Cod sursa (job #2514250)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
#define MOD 100021
#define x first
#define y second
vector < pair<int,int> > Hash[MOD];
int n,v[3050],l,ans=0;
void Read()
{
fin>>n>>l;
for(int i=1;i<=n;i++)
fin>>v[i];
}
void Push_Hash(int value)
{
int List=value%MOD,ok=0;
if(!Hash[List].empty()){
for(unsigned ct=0;ct<Hash[List].size();ct++)
{
int a=Hash[List][ct].x;
if(a==value)
{
ok=1;
Hash[List][ct].y++;
break;
}
}}
if(!ok)
Hash[List].push_back(make_pair(value,1));
}
int Find_Hash(int value)
{
int List=value%MOD;
if(!Hash[List].empty()){
for(unsigned ct=0;ct<Hash[List].size();ct++)
{
int a=Hash[List][ct].x;
int b=Hash[List][ct].y;
if(a==value)
return b;
}}
return 0;
}
void Sol()
{
for(int i=1;i<n;i++)
{
for(int j=i+1;j<=n;j++)
ans+=Find_Hash(l-(v[i]+v[j]));
for(int j=1;j<i;j++)
{
if((v[i]+v[j])<=l){
Push_Hash(v[i]+v[j]);}
}
}
fout<<ans<<'\n';
}
int main()
{
Read();
Sol();
}