Pagini recente » Cod sursa (job #882782) | Cod sursa (job #788017) | Cod sursa (job #997357) | Cod sursa (job #661068) | Cod sursa (job #32200)
Cod sursa(job #32200)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
#define FORI(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define FOR(i, N, M) for (int i = (int)(N); i <= (int)(M); ++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define PMAX 666013
vector<pair<int, int> > h[PMAX];
typedef long long LL;
int N, L, a[1024];
int get(int x)
{
if (x < 0) return 0;
int t = x % PMAX;
FORI(it, h[t])
if (it->first == x)
return it->second;
return 0;
}
void inc(int x)
{
int t = x % PMAX;
FORI(it, h[t])
if (it->first == x) { ++ it->second; return; }
h[t].push_back(make_pair(x, 1));
}
int main(void)
{
freopen("oite.in", "r", stdin);
freopen("oite.out", "w", stdout);
scanf("%d %d", &N, &L);
REP(i, N) scanf("%d", &a[i]);
LL Ans = 0;
REP(i, N)
{
FOR(j, i+1, N-1)
Ans += get(L-a[i]-a[j]);
FOR(j, 0, i-1)
inc(a[i]+a[j]);
}
printf("%lld\n", Ans);
return 0;
}