fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;
  7. cin>>n;
  8. vector<int>arr(n);
  9. for(int i=0;i<n;i++){
  10. cin>>arr[i];
  11. }
  12. sort(arr.begin(),arr.end());
  13. int k;
  14. cin>>k;
  15. int count=0;
  16. for(int i=0;i<n;i++){
  17. for(int j=n-1;j>=i+1;j--){
  18. int sum=arr[i]+arr[j];
  19. if(sum<=k){
  20. count=count+j-i;
  21.  
  22. }
  23.  
  24. }
  25. }
  26. cout<<count;
  27. return 0;
  28. }
Success #stdin #stdout 0s 5304KB
stdin
4
1 2 3 4
3
stdout
1