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. int k;
  13. cin>>k;
  14. int count=0;
  15. for(int i=0;i<n;i++){
  16. for(int j=i+1;j<n;j++){
  17. int sum=arr[i]+arr[j];
  18. if(sum<=k){
  19. count++;
  20. }
  21. }
  22. }
  23. cout<<count;
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5320KB
stdin
4
1 2 3 4 
3
stdout
1