For this Question: Tom has N sticks that are distinguishable from each other. The length of the i-th stick is L[i]. He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b+c
b < c+a
c < a+b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.The first line of input contains the number of sticks N, the next line contain N space separated integer where the ith integer shows the length of ith stick.

Constraints:-
3 ≤ N ≤ 1000
1 ≤ L[i] ≤ 1000Print the number of different triangles that can be formed.Sample Input 1 
4
3 4 2 1

Sample Output 1 
1

Sample Input 2
3
1 1000 1

Sample Output 2
0

Explanation:
For sample test case 1 the only triangle that can be formed is 2 3 4
, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
    long cnt=0;
    for(int i=0;i<n-2;i++){
          
        int j=i+1;
int        k=i+2;
        while(k!=n){
                if(a[j]+a[i]<=a[k]){if(j>=k-1){k++;}
                    else{j++;}
                    }
                else{
                        cnt+=(k-j);
                    k++;

                }

        }

    }
    cout<<cnt;

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