Pagini recente » Cod sursa (job #1104760) | Cod sursa (job #577570) | Cod sursa (job #2030641) | Cod sursa (job #1381321) | Cod sursa (job #682398)
Cod sursa(job #682398)
#include<cstdio>
#include<vector>
#include<algorithm>
#define infile "oite.in"
#define outfile "oite.out"
#define MOD 666013
#define pb push_back
#define ll long long
#define n_max 1030
#define FOR(g) \
for(vector < hash > ::iterator it = g.begin(); it!=g.end(); ++it)
using namespace std;
struct hash {
int a, b;
ll s;
};
vector < hash > T[MOD];
ll v[n_max], L;
int N;
ll Sol;
void citeste()
{
freopen(infile,"r",stdin);
scanf("%d %lld",&N, &L);
for(int i=1; i <= N; ++i)
scanf("%lld",&v[i]);
fclose(stdin);
}
inline int order(const int &a, const int &b, const int &c, const int &d)
{
if(a != c && a != d && b != c && b != d && c < a && a < d && b < d)
return 1;
return 0;
}
void rezolva()
{
hash r;
ll part_sum;
int where;
for(int i=1; i<=N; ++i)
for(int j=i+1; j<=N; ++j)
if(v[i] + v[j] <= L)
{
r.a = i;
r.b = j;
r.s = v[i] + v[j];
where = r.s % MOD;
T[where].pb(r);
part_sum = L - r.s;
where = part_sum % MOD;
FOR(T[where])
if((*it).s == part_sum)
if(order(i, j, (*it).a, (*it).b))
Sol++;
}
}
void afiseaza()
{
freopen(outfile,"w",stdout);
printf("%lld\n",Sol);
fclose(stdout);
}
int main()
{
citeste();
rezolva();
afiseaza();
return 0;
}