fork(14) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define maxn 5005
  5. ll a[maxn];
  6. ll n, i, j, k, tmp, res, tong;
  7. int main()
  8. {
  9.  
  10. cin >> n;
  11. for (i = 0; i < n; i++)
  12. cin >> a[i];
  13. sort(a, a + n);
  14. for (i = 0; i < n - 2; i++)
  15. {
  16. for (j = i+1; j < n - 1; j++)
  17. {
  18. tmp = lower_bound(a + j + 1, a + n, a[i] + a[j]) - a;
  19. res = res + (tmp - j-1);
  20. }
  21. }
  22. cout << res;
  23. }
  24.  
Success #stdin #stdout 0s 4704KB
stdin
5
4 3 1 5 7
stdout
3