Ahmed_Negm

Untitled

Apr 21st, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8. #include<utility>
  9.  
  10. #define ll long long
  11. #define sz(x) int(x.size())
  12. #define all(x) x.begin(),x.end()
  13. #define rall(s)  s.rbegin(), s.rend()
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. using namespace std;
  16.  
  17. void Fast_IO(){
  18.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  19.     #ifndef ONLINE_JUDGE
  20.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  21.     #endif
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. void solve(){
  29.   ll n,k; cin>>n>>k;
  30.   vector<ll>v;
  31.   vector<bool>negative(10000005);
  32.   vector<bool>positive(10000005);
  33.   while(n--){
  34.       ll x; cin>>x;
  35.       if(x<0){
  36.           if(negative[abs(x)]==0){
  37.               v.push_back(x);
  38.               negative[abs(x)]=1;
  39.           }
  40.       }else{
  41.           if(positive[x]==0){
  42.               v.push_back(x);
  43.               positive[x]=1;
  44.           }
  45.       }
  46.      
  47.   }
  48.   ll counter=0;
  49. //   for(int i=0; i<sz(v); i++) cout<<v[i]<<' ';
  50.   for(int i=0;i<sz(v)-1;i++)
  51.   for(int j=i+1; j<sz(v);j++){
  52.       if(abs(v[i]-v[j])==k) counter++;
  53.     //   cout<<abs(v[i]-v[j])<<'\n';
  54.   }
  55. cout<<counter;
  56.  
  57.  
  58.  
  59. }
  60.  
  61. int main(){
  62.     Fast_IO();
  63. int t =1;
  64. //cin>>t;
  65. while(t--){
  66. solve();
  67. }
  68. return 0;
  69. }  
Advertisement
Add Comment
Please, Sign In to add comment