Pagini recente » Cod sursa (job #820155) | Cod sursa (job #2879857) | Cod sursa (job #1078849) | Cod sursa (job #2325899) | Cod sursa (job #2976947)
#include <bits/stdc++.h>
using namespace std;
ofstream fout("oite.out");
ifstream fin("oite.in");
const int NMAX = 1030;
int v[NMAX];
long long int total = 0;
unordered_map<int, int> h;
int main()
{
int n, l;
fin >> n >> l;
for (int i = 1; i <= n; i++)
{
fin >> v[i];
}
sort(v + 1, v + n + 1);
for (int i = 3; i < n; i++)
{
for (int j = 1; j < i - 1; j++)
{
h[v[i - 1] + v[j]]++;
}
for (int j = i + 1; j <= n; j++)
{
if (h.find(l - v[i] - v[j]) != h.end())
{
total += 1ll * h[l - v[i] - v[j]];
}
}
}
fout << total;
return 0;
}