Pagini recente » Cod sursa (job #2216512) | Cod sursa (job #18495) | Cod sursa (job #2328552) | Cod sursa (job #2648987) | Cod sursa (job #2624114)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
//#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e3 + 11;
const int INF = 2e9;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;
ifstream in ("oite.in");
ofstream out ("oite.out");
int a[N], L, n;
unordered_map<int,int>m;
void solve(){
in >> n >> L;
for(int i = 1; i <= n; i++)in >> a[i];
sort(a + 1, a + n + 1);
ll ans = 0;
for(int i = 3; i < n; i++){
//pairs till now
for(int j = 1; j < i - 1; j++){
m[a[i - 1] + a[j]]++;
}
//pairs with a[i]
for(int j = i + 1; j <= n; j++){
int sum = L - a[i] - a[j];
if(sum >= 0)ans += m[sum];
}
}
out << ans << '\n';
}
int main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
int t = 1;
//cin >> t;
while(t--){
solve();
}
}