TL

Revision en1, by muzzaleeni, 2018-11-17 13:11:00

Why TL?

//pikachu

include <bits/stdc++.h>

using namespace std;

typedef long long ll;

define sz(x) ((int) (x).size())

define show(x) cout << (#x) << ": " << x << endl

const int MAXN = 5e5;

void tachyon() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

int binarySearch(int i, int d, int n, vector a) { int l = i, r = n; while (l + 1 < r) { int mid = (l + r) / 2; if (a[i] + d <= a[mid]) r = mid; else l = mid; } return r; }

int main() {
tachyon(); freopen("gen.out", "r", stdin); int n, d; cin >> n >> d; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { int x = binarySearch(i, d, n, a); if (x < n && a[i] + d == a[x]) ans++; } cout << ans; return false; }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English muzzaleeni 2018-11-17 13:12:30 947
en1 English muzzaleeni 2018-11-17 13:11:00 958 Initial revision (published)