Pagini recente » Cod sursa (job #1139477) | Cod sursa (job #293140) | Cod sursa (job #2467139) | Cod sursa (job #564157) | Cod sursa (job #2801451)
#include <bits/stdc++.h>
using namespace std;
ifstream in("oite.in");
ofstream out("oite.out");
using ll = long long;
const int MOD = 666013;
struct Hash {
vector<vector<pair<int, int>>> h;
void add(int x) {
int xh = (ll)37 * x % MOD;
bool added = false;
for (auto &val : h[xh])
if (val.first == x) {
val.second++;
added = true;
break;
}
if (!added)
h[xh].emplace_back(x, 1);
}
int count(int x) {
int xh = (ll)37 * x % MOD;
for (auto val : h[xh])
if (val.first == x)
return val.second;
return 0;
}
Hash() : h(MOD, vector<pair<int, int>>{}) {}
};
int main() {
ios_base::sync_with_stdio(false);
in.tie(NULL);
out.tie(NULL);
int n, l; in >> n >> l;
vector<int> a(n);
for (int &x : a)
in >> x;
sort(a.begin(), a.end());
Hash H;
ll ans = (ll)0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++)
if (l - a[i] - a[j] < 0)
break;
else {
int x = l - a[i] - a[j];
ans += H.count(x);
}
for (int j = 0; j < i; j++)
H.add(a[i] + a[j]);
}
out << ans << "\n";
return 0;
}