fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main(){
  6. int n,k; cin>>n>>k;
  7. if(k<0){
  8. cout<<-1;
  9. }
  10. vector<int>arr(n);
  11. for(int i = 0 ; i< n ; i++){
  12. cin>>arr[i];
  13. }
  14. unordered_map<int,int>hash;
  15. int k_halfcount = 0 ; int smaller = 0 ;
  16. for(int i = 0 ; i<n;i++){
  17. if(arr[i]==k/2 || arr[i]==-k/2){
  18. k_halfcount++;
  19. }
  20. else if((abs(arr[i])<k/2)){
  21. smaller++;
  22. }
  23. }
  24. cout<<(k_halfcount)*(k_halfcount-1)/2 + k_halfcount*smaller;
  25.  
  26.  
  27. return 0 ;
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
4 2
1 3 2 0
stdout
1