For this Question: You are given N points on a horizontal axis. Find the number of ways you can choose 3 points such that maximum distance between those points is not greater than d.The first line contains two integers: N and d. The next line contains N space-separated integers x1, x2, ..., xN, — the x-coordinates of the points that Petya has got.

<b>Constraints:</b>
1 &le; N &le; 1e5
1 &le; d &le; 1e9
1 &le; |x[i]| &le; 1e9

It is guaranteed that the coordinates of the points in the input strictly increase.Print the number of ways to choose 3 points.Sample Input:
4 3
1 2 3 4

Sample Output:
4

Explanation:
1 2 3
1 2 4
2 3 4
1 3 4
are the required triplets

Sample Input:
4 2
-3 -2 -1 0

Sample Output:
2, I have written this Solution Code: 
#include<bits/stdc++.h>
using namespace std;

// Returns the number of triplets with the
// distance between farthest points <= L
long long  countTripletsLessThanL(int n, long L, long * arr)
{
    // sort the array
    sort(arr, arr + n);

    long long  ways = 0;
    for (int i = 0; i < n; i++) {

        // find index of element greater than arr[i] + L
        int indexGreater = upper_bound(arr, arr + n,
                                         arr[i] + L) - arr;

        // find Number of elements between the ith
        // index and indexGreater since the Numbers
        // are sorted and the elements are distinct
        // from the points btw these indices represent
        // points within range (a[i] + 1 and a[i] + L)
        // both inclusive

        long long  numberOfElements = indexGreater - (i + 1);

        // if there are at least two elements in between
        // i and indexGreater find the Number of ways
        // to select two points out of these

        if (numberOfElements >= 2) {
            ways += (numberOfElements
                        * (numberOfElements - 1) / (long long )2);
        }
    }

    return ways;
}

// Driver Code
int main()
{

    int n;
    cin>>n;
    long l;
    cin>>l;
    long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
  cout<<countTripletsLessThanL(n, l, a);


}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?