Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int NrTriplete(int a[], int n, int S)
- {
- sort(a, a+n);
- int ans = 0;
- for (int i = 0; i < n - 2; i++)
- {
- int j = i + 1, k = n - 1;
- while (j < k)
- {
- if (a[i] + a[j] + a[k] >= S)
- k--;
- else
- {
- ans += (k - j);
- j++;
- }
- }
- }
- return ans;
- }
Add Comment
Please, Sign In to add comment