Advertisement
a53

NrTriplete

a53
Nov 27th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. int NrTriplete(int a[],int n,int S)
  2. {
  3. sort(a,a+n);
  4. int nrt=0;
  5. for(int i=0;i<n-2;++i)
  6. {
  7. int j=i+1,N=n-1;
  8. while(j<N)
  9. {
  10. if(a[i]+a[j]+a[N]>=S)
  11. --N;
  12. else
  13. nrt+=(N-j),++j;
  14. }
  15. }
  16. return nrt;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement