Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
693 B
3
Indexable
Never
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 100005;

int main()
{
    long long n, k;
    cin >> n >> k;
    long long niza[n];
    map<long long, long long> cnt;
    int nuli = 0;
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
        if(niza[i] == 0) {
            nuli += 1;
        }
        cnt[niza[i]] += 1;
    }
    
    long long parovi = 0;
    for(int i = 0; i < n; i++) {
        parovi += cnt[niza[i] - k];
    }
    if(k == 0) {
        parovi -= n;
        parovi /= 2;
    }
    cout << parovi << endl;
    return 0;
}

/*
 DD -1  brojac + 1
 DD -2 brojac + 1
 LL -1 brojac + 1
 LL 0 brojac + 0
 */