Advertisement
Josif_tepe

Untitled

Dec 16th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n, k;
  8.     cin >> n >> k;
  9.     int niza[n];
  10.     for(int i = 0; i < n; i++)
  11.     {
  12.         cin >> niza[i];
  13.     }
  14.     sort(niza, niza + n);
  15.     int parovi = 0;
  16.     for(int i = 0; i < n; i++)
  17.     {
  18.         for(int j = i + 1; j < n; j++)
  19.         {
  20.             if(niza[j] == niza[i] + k)
  21.             {
  22.                 parovi++;
  23.             }
  24.         }
  25.     }
  26.     cout << parovi << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement