Pagini recente » Statistici Zaharia Marius-Tudor (tudorzaharia) | Cod sursa (job #504990) | Cod sursa (job #512399) | Cod sursa (job #863802) | Cod sursa (job #2326996)
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
#define ll long long
#define unu first
#define doi second
vector < pair <int, int> > v[MAX];
void add (int x) {
for (auto &y : v[x % MAX]) {
if (y.unu == x) {
y.doi++;
return;
}
}
v[x % MAX].push_back ({x, 1});
}
int find (int x) {
for (auto y : v[x % MAX])
if (y.unu == x)
return y.doi;
return 0;
}
const int MAXN = 1024;
int a[MAXN + 1];
int main() {
int n, l, i, sol, j;
freopen ("oite.in", "r", stdin);
freopen ("oite.out", "w", stdout);
scanf ("%d%d", &n, &l);
for (i = 1; i <= n; i++)
scanf ("%d", &a[i]);
sol = 0;
for (i = 2; i <= n; i++) {
for (j = i + 1; j <= n; j++)
if (a[i] + a[j] <= l) {
sol = sol + find (l - a[i] - a[j]);
}
for (j = i - 1; j > 0; j--)
add (a[i] + a[j]);
}
printf ("%d", sol);
return 0;
}