text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, K, ans; int a[MAXN]; int main() { ios::sync_with_stdio(false); cin >> n >> K; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); ans = n; int j = 1; for (int i = 1; i < n; i++) { while (j <= n && a[i] == a[j]) j++; if (j <= n && a[i] + K >= a[j]) ans--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> int const MAX = 1e5 + 5; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long c = 1, ans = 0; for (long long i = 1; i < n; i++) { if (a[i - 1] + k >= a[i] && a[i] > a[i - 1]) { ans += c; } if (a[i] == a[i - 1]) c++; else c = 1; } cout << n - ans; }
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } int power(int a, int b, int m, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1) ans = 1LL * ans * a % m; return ans; } int a[200020]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int num = 0; a[n] = 0x3f3f3f3f; for (int i = 0; i < n; i++) { int x = a[i]; int y = upper_bound(a, a + n + 1, x) - a; if ((a[y] - x) > k) { num++; } } cout << num << endl; }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { for (int i = 0; i < argc; i++) { if ((string)argv[i] == "viLap") { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } } int n, K; cin >> n >> K; vector<int> mas(n); for (int i = 0; i < n; i++) { cin >> mas[i]; } sort(mas.begin(), mas.end()); int ans = 0; int eat = 0; int i = 1; int j = 0; while (i < n) { if (mas[j] < mas[i]) { if (mas[i] <= (mas[j] + K)) { if ((i - j) == 1) i++; j++; eat++; } else { ans++; i++; j = i - 1; } } else { i++; } } cout << n - eat; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000000]; bool vis[1000000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; set<int> s; for (int i = 0; i < n; i++) cin >> a[i], s.insert(a[i]); sort(a, a + n); int ret = n; for (int i = 0; i < n; i++) { auto p = s.upper_bound(a[i]); if (p == s.end()) continue; if (*p - a[i] <= k) ret--; } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { long long n, k; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int cnt = 0; for (int i = 0; i < n; i++) { if (upper_bound(a.begin(), a.end(), a[i]) != a.end()) { int r = (upper_bound(a.begin(), a.end(), a[i])) - a.begin(); if (a[r] > a[i] + k) cnt++; } else { cnt++; } } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; inline void prep() { cin.tie(0); cin.sync_with_stdio(0); } const int mod = (int)1e9 + 7; const int MX = (int)1e5 + 5; int main() { prep(); int n, k; cin >> n >> k; multiset<int> ms; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); ms.insert(a[0]); for (int i = 1; i < n; ++i) { auto it = ms.insert(a[i]); auto lb = ms.lower_bound(a[i] - k); while (*lb < *it && *lb + k >= a[i]) ms.erase(lb++); } cout << ms.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> ar; long long n, k; cin >> n >> k; long long i; for (i = 0; i < n; i++) { long long x; cin >> x; ar.push_back(x); } sort(ar.begin(), ar.end()); long long n1 = long(ar.size()) - 2; long long n2, cnt = 0; for (n2 = ar.size() - 1; n2 >= 0; n2--) { if (n1 == n2) n1--; while (n1 >= 0 && ar[n2] - ar[n1] <= k && ar[n1] != ar[n2]) { n1--; cnt++; } } cout << n - cnt; }
#include <bits/stdc++.h> using namespace std; const int N = 3 + 2e5; int n, a[N]; int k; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); int last = 1, ans = n; for (int i = 2; i <= n; ++i) { if (a[i] == a[last]) continue; if (a[i] <= a[last] + k) ans -= i - last; last = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n + 5]; set<int> st; for (int i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); } map<int, int> mp; int c = 0; vector<int> b; for (auto w : st) { b.push_back(w); } for (int i = 0; i < b.size() - 1; i++) { if (b[i + 1] - b[i] <= k) mp[b[i]] = 1; else mp[b[i]] = 0; } mp[b[b.size() - 1]] = 0; for (int i = 0; i < n; i++) { if (mp[a[i]] == 0) c++; } cout << c << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n + 2], cnt = n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { int it = upper_bound(a + i, a + n, a[i] + k) - a; it--; if (it >= 0 && a[it] > a[i]) cnt--; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; void fastIO() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int n, k; int v[1000007]; bool canBeEaten(int indx) { int st_indx = upper_bound(v, v + n, v[indx]) - v; if (st_indx == n) return false; int st = st_indx, en = n - 1, md; while (st <= en) { md = (st + en) >> 1; if (v[md] <= v[indx] + k) { return true; } en = md - 1; } return false; } int main() { fastIO(); cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; sort(v, v + n); int res = n; for (int i = 0; i < n; i++) { if (canBeEaten(i)) res--; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int f[1000001] = {0}; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } sort(a, a + n); int cnt = 0; for (int i = 0; i < n - 1; i++) { if (a[i + 1] > a[i] && a[i] + k >= a[i + 1]) cnt += f[a[i]]; } cout << n - cnt; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i, j; cin >> n >> k; long long int arr[n]; set<long long int> s; set<long long int> s2; map<long long int, long long int> ans; for (i = 0; i < n; i++) { cin >> arr[i]; s.insert(arr[i]); ans[arr[i]]++; } for (auto itr = s.begin(); itr != s.end(); itr++) { auto itr2 = itr; itr2++; if (itr2 != s.end()) { if (*itr + k >= (*itr2)) continue; else s2.insert(*itr); } else s2.insert(*itr); } long long int ans2 = 0; for (auto itr = s2.begin(); itr != s2.end(); itr++) { ans2 += ans[*itr]; } cout << ans2; }
#include <bits/stdc++.h> using namespace std; int m[200001], k, cd; int val[2000001]; void inp() { cin >> cd >> k; for (int i = 1; i <= cd; i++) { cin >> m[i]; val[m[i]]++; } sort(m + 1, m + 1 + cd); } bool check(int i) { if (m[i] <= m[i - 1] + k && m[i] > m[i - 1]) return true; return false; } void calc() { int kq = cd; for (int i = 2; i <= cd; i++) { if (check(i)) kq -= val[m[i - 1]]; } cout << kq << endl; } int main() { inp(); calc(); }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 9; const int Mod = 1e9 + 7; inline int dcmp(double x) { if (fabs(x) <= 1e-9) return 0; return x < 0 ? -1 : 1; } inline int scan() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long scan(long long x) { int f = 1; char ch = getchar(); x = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct Point { int x, y, id; Point(int x = 0, int y = 0) : x(x), y(y) {} Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); } Point operator*(const long long &a) const { return Point(x * a, y * a); } Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } bool operator==(const Point &a) const { return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0; } bool operator<(const Point &a) const { if (x == a.x) return y < a.y; return x < a.x; } void read() { scanf("%d%d", &x, &y); } void out() { cout << x << " " << y << endl; } }; double Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } double dis(Point a) { return sqrt(Dot(a, a)); } long long Cross(Point a, Point b) { return a.x * 1LL * b.y - a.y * 1LL * b.x; } bool chk(Point p1, Point p2, Point p3, Point p) { return abs(Cross(p2 - p, p1 - p)) + abs(Cross(p3 - p, p2 - p)) + abs(Cross(p1 - p, p3 - p)) == abs(Cross(p2 - p1, p3 - p1)); } int n, k, ti; int a[200005], vis[200005]; void solve() { n = scan(); k = scan(); for (int i = 1; i <= n; i++) a[i] = scan(); memset(vis, 0, sizeof(vis)); sort(a + 1, a + 1 + n); for (int i = 1; i <= n; i++) { ti = i; while (ti - 1) { ti--; if (vis[ti]) break; if (a[ti] + k < a[i]) break; if (a[ti] < a[i]) vis[ti] = 1; else break; } } ti = 0; for (int i = 1; i <= n; i++) { if (!vis[i]) ti++; } cout << ti << endl; } int main() { int t = 1; for (int i = 1; i <= t; i++) { solve(); } return 0; }
#include <bits/stdc++.h> std::vector<std::vector<int>> vec; using namespace std; long long mod = 1e9 + 7; int ans = 0; void solve() { long long n, k; scanf("%lld%lld", &n, &k); vector<int> t, v(n); set<int> s; for (int i = 0; i < n; i++) { scanf("%d", &v[i]); s.insert(v[i]); } for (auto i : s) t.push_back(i); vector<bool> aa(1e6 + 1, 0); for (int i = 0; i + 1 < t.size(); i++) { if (t[i + 1] - t[i] <= k) aa[t[i]] = 1; } for (auto i : v) ans += aa[i]; cout << n - ans << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, count = 0; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); vector<pair<int, int>> vec; vec.push_back(make_pair(arr[0], 1)); for (int i = 1; i < n; i++) { if (arr[i] == vec.back().first) vec.back().second++; else vec.push_back(make_pair(arr[i], 1)); } n = vec.size(); for (int i = 0; i < n - 1; i++) { if (vec.at(i).first + k < vec.at(i + 1).first) count += vec.at(i).second; } count += vec.back().second; cout << count << endl; }
#include <bits/stdc++.h> int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; const double PI = acos(-1), EPS = 1e-7; const int OO = 0x3f3f3f3f, N = 100000 + 5, mod = 1e9 + 7; using namespace std; long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); } long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); } void file() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vector<int> v; int main() { file(); int n, k; cin >> n >> k; v = vector<int>(n); for (auto &t : v) cin >> t; int cnt = 0; sort(((v).begin()), ((v).end())); v.push_back(2e9); for (int i = 0; i < n; i++) { auto t = upper_bound(((v).begin()), ((v).end()), v[i]); if (*t - v[i] > k) cnt++; } cout << cnt << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; vector<int> v; cin >> n >> k; for (i = 0; i < n; i++) { cin >> j; v.push_back(j); } sort(v.begin(), v.end()); int cnt = 0, num = 1; for (i = 0; i < n - 1; i++) { if (v[i] == v[i + 1]) num++; else if (v[i] < v[i + 1] && v[i + 1] <= v[i] + k) { cnt += num; num = 1; } else { num = 1; } } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; void moha() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const long double eps = 1e-10; int main() { moha(); int n, k; cin >> n >> k; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int x = n, z = 1; for (int i = 0; i < n - 1; i++) { if (a[i] < a[i + 1] && a[i] + k >= a[i + 1]) { x -= z; } if (a[i] == a[i + 1]) { z++; } else { z = 1; } } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; vector<int> p; int ho, mi, se; void fix_time() { if (se > 59) mi += se / 60, se = se % 60; if (se < 0) se += 60, mi--; if (mi > 59) ho += mi / 60, mi = mi % 60; if (mi < 0) mi += 60, ho--; } int my_pow(int x, int y) { long long num = 1; for (int i = x; y > 0; i = (i * i), y >>= 1) if (y & 1) num = ((num)*i); return num; } bool prime[1000001]; void sieve() { for (int i = 2; i <= 1000000; i += 2) prime[i] = false, prime[i - 1] = true; prime[2] = true; for (int i = 3; i <= 1000; i += 2) if (prime[i]) for (int j = i * i; j <= 1000000; j += 2 * i) prime[j] = false; } void pfact(int x) { if (x % 2 == 0) { p.push_back(2); while (x % 2 == 0) x /= 2; } for (int i = 3; i * i <= x; i += 2) if (x % i == 0) { p.push_back(i); while (x % i == 0) x /= i; } if (x > 1) p.push_back(x); } int n, m, k, a[200003], b, cnt; set<int> bac; int num[1000004]; int main() { ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; bac.insert(a[i]); num[a[i]]++; } for (auto it = bac.begin(); it != --bac.end();) { auto it2 = it; ++it2; int bac1 = *it, bac2 = *it2; if (bac2 > bac1 && bac2 <= bac1 + k) bac.erase(it); it = it2; } for (auto it = bac.begin(); it != bac.end(); it++) cnt += num[*it]; cout << cnt; return 0; }
#include <bits/stdc++.h> int main() { int n, k; std::cin >> n >> k; std::vector<int> v(n); std::unordered_map<int, int> cnt; for (int i = 0; i < n; ++i) { std::cin >> v[i]; cnt[v[i]]++; } std::sort(v.begin(), v.end()); int ans = n; for (int i = 0; i + 1 < n; ++i) { if (v[i + 1] > v[i] && v[i + 1] <= v[i] + k) { ans -= cnt[v[i]]; } } std::cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int a[maxn * 10]; int ans[maxn]; int main() { int n, k; while (cin >> n >> k) { memset(a, 0, sizeof(a)); memset(ans, 0, sizeof(ans)); int cnt = 0; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; } for (int i = 0; i < maxn * 10; i++) { if (a[i]) ans[cnt++] = i; } int tt = 0; for (int i = 1; i < cnt; i++) { if (ans[i - 1] + k >= ans[i] && ans[i - 1] < ans[i]) { tt += a[ans[i - 1]]; } } cout << n - tt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool comp(int a, int b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n, comp); int i = 0, ans = 0, pre; bool eater = false; while (i < n) { if (!eater) { eater = true; pre = arr[i]; ans++; i++; continue; } eater = false; while (i < n && arr[i] == pre) ans++, i++; while (i < n && pre - k <= arr[i]) pre = arr[i++]; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int a[n]; long long int i = 0; while (i < n) { cin >> a[i]; i++; } sort(a, a + n); vector<long long int> v; vector<long long int> v1; i = 0; long long int count = 0; while (i < n) { count = 1; v1.push_back(a[i]); while (i < n - 1 and a[i] == a[i + 1]) { count++; i++; } v.push_back(count); i++; } i = 1; count = 0; while (i < v.size()) { if (v1[i] > v1[i - 1] and v1[i] - v1[i - 1] <= k) count += v[i - 1]; i++; } cout << n - count; }
#include <bits/stdc++.h> using namespace std; const int inf = 2 * (1e9) + 10; const long long MOD = 998244353; const int NMAX = 1000005; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; set<pair<int, int>> st; int cnt[NMAX]; int n, k, a; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a; cnt[a]++; } for (int i = 1; i <= 1000000; ++i) { if (cnt[i]) st.insert({i, cnt[i]}); } int ans = 0; while (st.size() > 1) { pair<int, int> fst = *(st.begin()); pair<int, int> snd = *(++st.begin()); if (snd.first - fst.first <= k) { st.erase(st.begin()); } else { ans += fst.second; st.erase(st.begin()); } } cout << ans + ((*(st.begin())).second) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } ll llceil(ll a, ll b) { return (a + b - 1) / b; } ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); } string toupper(const string& S) { string T(S); for (ll i = (0); i < (((ll)(T).size())); ++i) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); for (ll i = (0); i < (((ll)(T).size())); ++i) T[i] = tolower(T[i]); return T; } using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; using VLD = vector<ld>; using VVLD = vector<VLD>; using VVVLD = vector<VVLD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; static const ll INF = (1LL << 62) - 1; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); ll N, K; cin >> N >> K; VLL A(N); for (ll i = (0); i < (N); ++i) cin >> A[i]; map<ll, ll> cnt; for (ll a : A) cnt[a]++; VP X; for (auto [a, n] : cnt) X.push_back(P(a, n)); ll ans = N; for (ll i = (0); i < (((ll)(X).size()) - 1); ++i) { auto [a1, n1] = X[i]; auto [a2, _] = X[i + 1]; if (a1 < a2 && a2 - a1 <= K) ans -= n1; } cout << (ans) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; set<int> s; int a[200009]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } int re = 0; sort(a, a + n); for (int i = n - 1; i > -1; i--) { if (s.size() == 0) { s.insert(a[i]); continue; } auto x = s.upper_bound(a[i] + k); if (x != s.begin()) { x--; if (*x > a[i] + k || *x <= a[i]) continue; re++; } s.insert(a[i]); } cout << n - re; }
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 7; const long long q = 7057594037927903; const long long prime = 2137; int n, k, wynik, poczatek, koniec, srodek, tab[M], czyzjedzony[M]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &tab[i]); sort(tab, tab + n); for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (czyzjedzony[j] == 1 || tab[i] > tab[j] + k || tab[j] == tab[i]) break; else czyzjedzony[j] = 1; } } for (int i = 0; i < n; i++) if (czyzjedzony[i] == 0) wynik++; printf("%d", wynik); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, k; int fa[maxn]; int a[maxn]; int cnt; int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } void merge(int x, int y) { int fx = gf(x); int fy = gf(y); if (fx != fy) { fa[fx] = fy; --cnt; } } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), fa[i] = i; sort(a + 1, a + 1 + n); cnt = n; int i, j; for (i = 1; i <= n - 1; i = j) { j = i; for (; j <= n && a[i] == a[j]; j++) ; if (a[i] < a[j] && a[j] <= a[i] + k) { for (int z = i; z < j; z++) merge(z, j); } } printf("%d", cnt); }
#include <bits/stdc++.h> using namespace std; inline void initialize(bool needFiles) { if (needFiles) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main() { initialize(false); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); int alive = n; for (int i = 0; i < n; ++i) { int j = (int)(upper_bound(a, a + n, a[i]) - a); if (j != n && a[j] <= k + a[i]) alive--; } cout << alive; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int n, K; map<int, int> mp; struct Node { int num, times; } a[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> K; for (int i = 1; i <= n; ++i) { int t; cin >> t; mp[t]++; } int cnt = 0; for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) { a[++cnt].num = it->first; a[cnt].times = it->second; } int ans = n; for (int i = 2; i <= cnt; ++i) { if (a[i].num - a[i - 1].num <= K) { ans -= a[i - 1].times; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, k, a[200005]; map<int, int> sz; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sz[a[i]]++; } sort(a, a + n); int m = unique(a, a + n) - a; int ans = n; for (int i = 0; i < m - 1; i++) { if (a[i + 1] - a[i] <= k) ans -= sz[a[i]]; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, a[10000000], num[10000000], ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); num[a[i]]++; } sort(a + 1, a + 1 + n); for (int i = 2; i <= n; i++) if (a[i] > a[i - 1] && a[i] <= m + a[i - 1]) ans += num[a[i - 1]]; cout << n - ans; return 0; }
#include <bits/stdc++.h> using namespace std; multiset<int> st; int main() { ios::sync_with_stdio(false), cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; st.insert(x); } for (auto x : st) { auto e = st.lower_bound(x); auto s = st.lower_bound(x - k); st.erase(s, e); } cout << st.size(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int n, k, c = 0, t = 1; cin >> n >> k; vector<long long int> vec; for (int i = 0; i < n; i++) { long long int x; cin >> x; vec.push_back(x); } sort(vec.begin(), vec.end()); for (int i = 1; i < vec.size(); i++) { if (vec[i] == vec[i - 1]) t++; else if ((vec[i] - vec[i - 1]) <= k) { c += t; t = 1; } else t = 1; } cout << vec.size() - c; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const long long mod = 1e9 + 7; const int MAXN = 1e6 + 7; void solve(); signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); vector<int> st; for (int i = 0; i < n; i++) { while (st.size() != 0 && a[i] - st.back() <= k && st.back() < a[i]) { st.pop_back(); } st.push_back(a[i]); } cout << st.size(); return; }
#include <bits/stdc++.h> using namespace std; int a[200005], done[200005] = {0}; int main() { ios::sync_with_stdio(false); int n, k; int ans = 0, i, j, pos; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { for (j = i - 1; j >= 0 && a[j] != 0; j--) { if (a[i] > a[j] && a[i] <= a[j] + k) { a[j] = 0; } else { break; } } } for (i = 0; i < n; i++) { if (a[i]) ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> a; int b[N]; int main() { int n, ans, k, x; cin >> n >> k; ans = n; for (int i = 1; i <= n; ++i) { cin >> x; a.push_back(x); } sort(a.begin(), a.end()); for (int i = 0; i < a.size(); i++) { int pos1 = upper_bound(a.begin(), a.end(), a[i]) - a.begin(); int pos2 = upper_bound(a.begin(), a.end(), a[i] + k) - a.begin() - 1; if (pos2 < pos1) continue; if (pos2 != i && pos1 != i) b[i] = 1; } for (int i = 0; i < a.size(); i++) { if (b[i]) { ans--; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; void init_ios() { ios_base::sync_with_stdio(0); cin.tie(0); } const int N = (int)1e6 + 10; int n, k, a[N], sum[2 * N]; int main() { init_ios(); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) ++sum[a[i]]; for (int i = 1; i <= 2 * N - 5; ++i) sum[i] += sum[i - 1]; for (int i = 1; i <= n; ++i) if (sum[a[i] + k] - sum[a[i]]) a[i] = 0; int res = 0; for (int i = 1; i <= n; ++i) if (a[i]) ++res; cout << res << "\n"; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long a[n + 1]; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); a[n] = 1e9; long long cnt = 0, j = 0; for (long long i = 0; i < n; i++) { while (a[j] == a[i]) j++; if (a[j] - a[i] > k) cnt++; } cout << cnt; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; const long long int infl = LLONG_MAX; int main() { std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long int n, k; cin >> n >> k; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } long long int count = n; int val = 1; sort(arr, arr + n); for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) { val++; } if (arr[i] > arr[i - 1] && arr[i] <= arr[i - 1] + k) { count = count - val; } if (arr[i] != arr[i - 1]) { val = 1; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000005]; int b[1000005]; int sum[1000005]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for (int i = 1; i < n; i++) { int tmp = a[i] - k; if (tmp <= 0) tmp = 1; if (a[i - 1] + k < a[i]) continue; int x = lower_bound(a, a + i, tmp) - a; if (a[i - 1] >= a[i]) continue; if (x >= 0 && x <= i) { b[x] += 1; b[i] = -1; } } sum[0] = b[0]; int cnt = 0; if (sum[0] == 0) cnt++; for (int i = 1; i < n; i++) { sum[i] = sum[i - 1] + b[i]; if (sum[i] == 0) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, cnt, ans, a[200010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) if (a[i] == a[i - 1]) ++cnt; else if (a[i] <= a[i - 1] + k) cnt = 1; else ans += cnt, cnt = 1; printf("%d\n", ans + cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; int T[N]; int occ[N]; bool done[N]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &T[i]); occ[T[i]]++; } sort(T, T + n); stack<int> stk; int ans = n; for (int i = 0; i < n; i++) { if (done[T[i]]) continue; while (!stk.empty() && (T[i] - stk.top()) <= k) ans -= occ[stk.top()], stk.pop(); stk.push(T[i]); done[T[i]] = 1; } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int n, k, t = 0, j; cin >> n >> k; long int a[n], i, s[n]; for (i = 0; i < n; i++) { cin >> a[i]; s[i] = 1; } sort(a, a + n); for (j = 1; j < n; j++) if (a[j] > a[j - 1] && a[j] <= a[j - 1] + k) { t++; i = j - 1; while (i >= 0 && a[i] == a[i - 1]) { i--; t++; } } cout << (n - t); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map<int, int> m; int n, k, v[200000], a = 0; cin >> n >> k; int r = n; for (int i = 0; i < n; i++) { v[i] = 0; int x; cin >> x; if (!m[x]++) { v[a++] = x; } } sort(v, v + a); for (int i = 0; i < a - 1; i++) { if (v[i + 1] > v[i] && v[i] + k >= v[i + 1]) { r -= m[v[i]]; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void dbg(T a) {} template <typename T, typename... Arg> void dbg(T a, Arg... arg) {} const int maxn = (1e6) + 7; const int maxk = 20; const int inf = (1e9) + 7; const long long LLinf = (1e18) + 7; const long double eps = 1e-9; const long long mod = 1e9 + 7; bool czy[maxn]; long long tab[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> tab[i]; sort(tab, tab + n); for (int i = 0; i < n - 1; i++) if (tab[i + 1] > tab[i] && tab[i + 1] <= tab[i] + k) czy[tab[i]] = 1; long long res = 0LL; for (int i = 0; i < n; i++) if (czy[tab[i]] == 0) res++; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; void f(vector<int> &A, int k) { sort(A.begin(), A.end()); for (int i = 0; i < (int)A.size(); i++) { vector<int>::iterator it = lower_bound(A.begin() + i + 1, A.end(), A[i] + 1); if (it != A.end() && *it <= A[i] + k) { A[i] = -1; } } int ans = 0; for (int i = 0; i < (int)A.size(); i++) { if (A[i] != -1) { ans++; } } cout << ans << endl; } int main() { int n, k; cin >> n >> k; vector<int> A(n, 0); for (int i = 0; i < n; i++) { cin >> A[i]; } f(A, k); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 2e5 + 5; int n, k, d; vector<int> a; int eat[MAX]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> d; a.push_back(d); } sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { int l = upper_bound(a.begin(), a.end(), a[i]) - a.begin(); int u = upper_bound(a.begin(), a.end(), a[i] + k) - a.begin() - 1; if (l <= u) eat[i] = true; } int ans = 0; for (int i = 0; i < n; i++) { if (!eat[i]) ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { int n, k, x; cin >> n >> k; for (int i(0); i < (n); i++) { cin >> x; a.push_back(x); } sort((a).begin(), (a).end()); int ct = 0, cct = 0; for (int i(0); i < (n - 1); i++) { if (a[i] != a[i + 1] && a[i + 1] <= a[i] + k) { if (cct > 0) { ct += cct + 1; cct = 0; } else { ct++; } } else if (a[i] == a[i + 1]) { cct++; } else { cct = 0; } } cout << n - ct; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, i, j, k, l, m, arr[200010], x, a, b, c, d, od = 0, ev = 0, arr1[200010], p, hi, lo, mid, s, y, t, res = 0; map<long long, long long> mp, mp1; vector<long long> vc, vc1; string st, st1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (i = 0; i < n; i++) { cin >> arr[i]; if (mp.find(arr[i]) == mp.end()) mp[arr[i]] = 1; else mp[arr[i]]++; } for (map<long long, long long>::iterator it = mp.begin(); it != mp.end(); it++) { vc.push_back(it->first); } res = mp[vc[int(vc.size()) - 1]]; for (i = 0; i < int(vc.size()) - 1; i++) { if (vc[i + 1] - vc[i] > k) { res += mp[vc[i]]; } } cout << res; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int l = 1e6 + 1; int a[l]; int i; int x; for (i = 0; i < l; i++) a[i] = 0; for (i = 1; i <= n; i++) { cin >> x; a[x]++; } int max = 0; for (i = 0; i < l; i++) { if (a[i] == 0) a[i] = max; else { a[i] += max; max = a[i]; } } max = 0; for (i = 0; i < l; i++) { if (a[i] > max) { if (i + k < l && a[i + k] > a[i]) n = n - a[i] + max; else if (i + k >= l && a[l - 1] > a[i]) n = n - a[i] + max; max = a[i]; } } cout << n << endl; }
#include <bits/stdc++.h> using namespace std; inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; } inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; } inline int Pow(int base, long long exp, int _mod) { if (!(base %= _mod)) return 0; int _ans = 1; for (; exp; exp >>= 1, base = (long long)base * base % _mod) exp& 1 ? _ans = (long long)_ans * base % _mod : 0; return _ans; } inline long long Pow(long long base, long long exp, long long _mod) { if (!(base %= _mod)) return 0; long long _ans = 1; for (; exp; exp >>= 1, base = base * base % _mod) exp& 1 ? _ans = _ans * base % _mod : 0; return _ans; } const int INF = 0x3f3f3f3f; int n, k; int a[200002], b[100001]; map<int, int> c; int h[100001], nxt[200001], to[200001], tot; inline void ins(int x, int y) { nxt[++tot] = h[x]; to[tot] = y; h[x] = tot; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= (n); ++i) scanf("%d", a + i), c[a[i]]++; sort(a + 1, a + n + 1); a[n + 1] = INF; int A = 0; for (int i = 2; i <= (n + 1); ++i) if (a[i] - a[i - 1] > k) A += c[a[i - 1]]; printf("%d", A); return 0; }
#include <bits/stdc++.h> using namespace std; int m[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, v[200000], a = 0; cin >> n >> k; int r = n; for (int i = 0; i < n; i++) { v[i] = 0; int x; cin >> x; if (!m[x]++) { v[a++] = x; } } sort(v, v + a); for (int i = 0; i < a - 1; i++) { if (v[i + 1] > v[i] && v[i] + k >= v[i + 1]) { r -= m[v[i]]; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; pair<pair<int, int>, pair<int, int> > intersect(pair<int, int> f1, pair<int, int> f2, pair<int, int> s1, pair<int, int> s2) { int x5, y5, x6, y6; x5 = max(min(f1.first, f2.first), min(s1.first, s2.first)); x6 = min(max(f1.first, f2.first), max(s1.first, s2.first)); y5 = max(min(f1.second, f2.second), min(s1.second, s2.second)); y6 = min(max(f1.second, f2.second), max(s1.second, s2.second)); if (x5 >= x6 || y5 >= y6) { return {{0, 0}, {0, 0}}; } return {{x5, y5}, {x6, y6}}; } template <class T, class V> int min(T a, V b) { return min((int)a, (int)b); } template <class T, class V> int max(T a, V b) { return max((int)a, (int)b); } bool isPrime(long long n, long long p) { if (n < 2) return 0; for (long long i = 2; i * i <= n; i++) { if (i > p) break; if (n % i == 0) return 0; } return 1; } void faster() { if (0) { freopen( "taskA" ".in", "r", stdin); freopen( "taskA" ".out", "w", stdout); } if (1) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } } const long long INF = 1e18; const int inf = 1e9; const int MAXN = (int)2e5 + 123; const int MOD = (int)1e9 + 7; const long double PI = acos(-1); const long double EPS = 3E-16; namespace MATH_CAL { const int mod = MOD; inline long long add(long long a, long long b) { return a + b >= mod ? a + b - mod : a + b; } inline long long sub(long long a, long long b) { return a - b < 0 ? a - b + mod : a - b; } inline long long mul(long long a, long long b) { return (long long)a * b % mod; } inline void Add(long long &a, long long b) { (a += b) >= mod ? a -= mod : 0; } inline void Sub(long long &a, long long b) { (a -= b) < 0 ? a += mod : 0; } inline long long qpow(long long first, long long n) { long long r = 1; for (; n; n /= 2, first = mul(first, first)) if (n & 1) r = mul(r, first); return r; } inline long long mod_inv(long long first) { return qpow(first, mod - 2); } inline long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } } // namespace MATH_CAL using namespace MATH_CAL; void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int ans = n; for (int i = 0; i < n; i++) { int item = a[i]; auto gr = upper_bound(a.begin() + i + 1, a.end(), item); if (gr != a.end()) { if (*gr <= item + k) { ans--; } } } cout << ans << endl; } int main() { faster(); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a; int flag = 0; for (int i = 0; i < n; i++) { int y; cin >> y; a.push_back(y); } for (int i = 1; i < n; i++) { if (a[i] == a[i - 1]) { flag++; } } if (flag == n - 1) { cout << n; return 0; } sort(a.begin(), a.end()); int s = n; int j = 0; for (int i = 0; i < n; i++) { while (a[j] < a[i]) { if (a[i] - a[j] <= k) { s--; } j++; } } cout << s; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; scanf("%lld%lld", &n, &k); vector<long long> v; long long x; map<long long, long long> make_pair; for (long long i = 0; i < n; i++) { scanf("%lld", &x); v.push_back(x); make_pair[x]++; } sort(v.begin(), v.end()); long long cnt = 0, j, i, flag = 0; for (i = 0; i < n - 1; i++) { if (v[i] < v[i + 1] && v[i] + k >= v[i + 1]) { cnt = cnt + make_pair[v[i]]; } } cout << n - cnt << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, k, sum = 0, count = 0, ans = 0; cin >> n >> k; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = 0; i < n - 1; i++) { j = lower_bound(a, a + n, a[i] + 1) - a; if ((a[j] - a[i]) <= k) ans++; } cout << n - ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5, MAXK = 1e6 + 6; int n, k, a, ans, size = 0; int Arr[MAXN]; int Mark[MAXK]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a; if (!Mark[a]) Arr[size++] = a; Mark[a]++; } sort(Arr, Arr + size); for (int i = 0; i + 1 < size; i++) if (Arr[i + 1] - Arr[i] > 0 && Arr[i + 1] - Arr[i] <= k) ans += Mark[Arr[i]]; cout << n - ans; return 0; }
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mapa; vector<int> tab; int main() { ios_base::sync_with_stdio(false); int n, k, a; cin >> n >> k; int aktIlosc = n; for (int i = 0; i < n; i++) { cin >> a; if (mapa[a] == 0) tab.push_back(a); mapa[a]++; } sort(tab.begin(), tab.end()); for (int i = 0; i + 1 < tab.size(); i++) { if (tab[i] < tab[i + 1] && tab[i] + k >= tab[i + 1]) aktIlosc -= mapa[tab[i]]; } cout << aktIlosc; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int INF = 0x3f3f3f3f; int n, m; int p[MAXN]; int tag[MAXN], pre[MAXN]; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> n >> m; for (int i = 0; i < n; i++) cin >> p[i]; sort(p, p + n); int cnt = 0; for (int i = 0; i < n; i++) { int u = lower_bound(p, p + i, p[i] - m) - p; int v = lower_bound(p, p + i, p[i]) - p; cnt += (v - u); tag[u]++; tag[v]--; } for (int i = 0; i < n; i++) { if (!i) pre[i] = tag[i]; else pre[i] = pre[i - 1] + tag[i]; cnt -= max(pre[i] - 1, 0); } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, a, x; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a; v.push_back(a); } sort(v.begin(), v.end()); vector<int> ans; for (int i = 0; i < n; i++) { while (!ans.empty() && ans.back() + k >= v[i] && ans.back() < v[i]) { ans.pop_back(); } ans.push_back(v[i]); } cout << ans.size() << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; long long a[maxn]; int main() { ios::sync_with_stdio(false); long long n, k, cnt = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) { int pos = upper_bound(a, a + n, a[i]) - a; if (pos >= n) { continue; } if (a[i] + k >= a[pos]) { cnt++; } } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long long n, k; cin >> n >> k; vector<long long> line(n); for (long long& i : line) cin >> i; sort(line.begin(), line.end()); long long ans = n; long long same = 0; for (long long i = 0; i < n - 1; i++) { if (i > 0 && line[i] == line[i - 1]) same++; else same = 1; if (line[i + 1] > line[i] && line[i + 1] <= line[i] + k) ans -= same; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> bac; for (int i = 0; i < n; i++) { int b; cin >> b; bac.push_back(b); } sort(bac.begin(), bac.end()); int repLen = 0; int prevRepLen = 0; for (int i = 1; i < bac.size(); i++) { if (bac[i] == bac[i - 1]) { repLen++; continue; } prevRepLen = repLen; repLen = 0; if (bac[i - 1] + k >= bac[i]) { for (int j = i - prevRepLen - 1; j < i; j++) { bac[j] = -1; } } } int count = 0; for (int i = 0; i < bac.size(); i++) { if (bac[i] != -1) { count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int DIM = 200005; int arr[DIM], cnt[DIM * 5]; int main(void) { int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> arr[i]; ++cnt[arr[i]]; } sort(arr + 1, arr + n + 1); int ans = n; for (int i = 2; i <= n; ++i) if (arr[i] > arr[i - 1] and arr[i] <= arr[i - 1] + k) ans -= cnt[arr[i - 1]]; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int array[n]; for (int i = 0; i < n; i++) { cin >> array[i]; } sort(array, array + n); int scope = 1, count = 0; for (int i = 0; i < n; i++) { scope = max(scope, i + 1); for (int j = scope; j < n; j++) { if (array[j] != array[i]) { if (array[j] <= array[i] + k) { count++; } scope = j; break; } scope++; } } cout << n - count << endl; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:10000000000") using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); template <typename T> ostream& operator<<(ostream& o, vector<T> x) { for (auto it : x) o << it << ' '; return o; } template <typename T> istream& operator>>(istream& i, vector<T>& x) { for (auto& it : x) i >> it; return i; } template <typename T1, typename T2> void chkmin(T1& a, T2 b) { a > b ? a = b : 0; } template <typename T1, typename T2> void chkmax(T1& a, T2 b) { a < b ? a = b : 0; } const long long INF = 1000000007; const long long INF2 = 100000000000000007; const long long mINF = 1e16; const long long MOD1 = 998244353; const long long MOD = 1000000007; const long long SIZE = 500010; const long long base = 53; const long double eps = 1e-6; const long double pi = acosl(-1.0); long long add(long long a, long long b) { return ((a + b) % MOD + MOD) % MOD; } long long mult(long long a, long long b) { return (a * b) % MOD; } long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) res = mult(res, a); a = mult(a, a); n >>= 1; } return res; } long long binpow1(long long a, long long n) { long long res = 1; while (n) { if (n & 1) { res *= a; } a *= a; n >>= 1; } return res; } long long inv(long long a) { return binpow(a, MOD - 2); } long long del(long long a, long long b) { return mult(a, inv(b)); } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T sqr(T x) { return x * x; } long long n, k, a, rs; map<long long, long long> cnt; vector<long long> kek; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; rs = n; for (long long i = 0; i < n; ++i) { cin >> a; if (cnt.find(a) == cnt.end()) kek.push_back(a); cnt[a]++; } sort(kek.begin(), kek.end()); for (long long i = 1; i < kek.size(); ++i) { if (kek[i] <= kek[i - 1] + k) { rs -= cnt[kek[i - 1]]; } } cout << rs; return 0; }
#include <bits/stdc++.h> using namespace std; double const EPS = 1.0E-9; int const MOD = (int)1e9 + 7; inline void read(int &x) { scanf("%d", &(x)); } inline void read(long long &x) { scanf("%lld", &x); } inline void read(double &x) { scanf("%lf", &x); } inline long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } inline long long lcm(long long x, long long y) { return x == 0 && y == 0 ? 0 : x / gcd(x, y) * y; } inline long long powmod(long long x, long long n, long long m = MOD) { long long r = 1; while (n) { if (n & 1) r = (r * x) % m; x = (x * x) % m; n /= 2; } return r; } int leap(int y) { return y % 4 == 0 && y % 100 != 0 || y % 400 == 0; } int const month[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; int const MAXN = 1 << 17; int const MAXV = 26 * 2 + 10 + 1; int solve() { std::map<int, int> mp; int n, d; read(n); read(d); for (int i = 0; i < n; ++i) { int a; read(a); ++mp[a]; } int ans = 0; for (auto it = mp.begin(), it_e = mp.end(); it != it_e; ++it) { auto it_next = std::next(it); if (it_next == it_e) { ans += (*it).second; } else { int cur_a = (*it).first; int next_a = (*it_next).first; if (next_a <= cur_a + d) { } else { ans += (*it).second; } } } printf("%d\n", ans); return 0; } int main(int argc, char *argv[]) { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, z, w, k, h[300000], a[300000]; string s; long long bs(long long xx, long long yy, long long kk) { long long mm = (xx + yy) / 2; if (yy - xx <= 1) return xx; if (a[mm] <= kk) return bs(mm, yy, kk); else return bs(xx, mm, kk); } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = n - 1; i >= 0; i--) { x = bs(0, n, a[i] - k); while (a[i] - k > a[x]) x++; while (x != 0 && a[x - 1] == a[x]) x--; for (int j = x; j < i; j++) { if (a[i] == a[j]) break; if (h[j] == 1) break; h[j] = 1; } } for (int i = 0; i < n; i++) { if (h[i] == 0) y++; } cout << y; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; stack<int> s; int main() { cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { while (!s.empty() && a[i] > s.top() && a[i] <= s.top() + k) { s.pop(); } s.push(a[i]); } cout << s.size(); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long int n, k; cin >> n >> k; long long int ar[n]; for (int i = 0; i < n; i++) { cin >> ar[i]; } sort(ar, ar + n); long long int e = 1, c = 0; for (long long int i = 0; i < n - 1; i++) { if (ar[i] == ar[1 + i]) { e++; } else if (ar[i + 1] <= ar[i] + k) { c += e; e = 1; } else e = 1; } cout << n - c; return 0; }
#include <bits/stdc++.h> const long long N = 1e6 + 10; const long long mod = 1e9 + 7; long long dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0}; using namespace std; long long v[N], vis[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; for (long long i = 1; i <= n; i++) { long long x; cin >> x; vis[x]++; } for (long long i = 1e6; i >= 1; i--) { if (vis[i]) { long long r = i - k; r = max(r, 1LL); v[r]--, v[i]++; } } for (long long i = 1; i <= 1e6; i++) v[i] += v[i - 1]; long long ans = 0; for (long long i = 1; i <= 1e6; i++) if (v[i] >= 0) ans += vis[i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000000 + 10]; int main() { int n, K; cin >> n >> K; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int cnt = 0; int tmp = a[0]; int c = 1; for (int i = 1; i < n; i++) { if (a[i] == a[i - 1]) c += 1; else if (a[i] <= a[i - 1] + K) cnt += c, c = 1; else c = 1; } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 123; const int M = 1000 * 1000 + 123; int n; int k; int a[N]; int x[M]; int ps[M]; int main() { scanf("%d", &n); scanf("%d", &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); x[a[i]] = 1; } sort(a, a + n); for (int i = 1; i < M; i++) { ps[i] = ps[i - 1] + x[i]; } int ans = 0; for (int i = 0; i < n; i++) { int l = a[i] + 1; int r = min(M - 1, a[i] + k); int sum = ps[r] - ps[l - 1]; if (sum == 0) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Ha { int pos, num; } ha[2000050]; int n, k, a[2000050], ans = 0, cnt = 0; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); int no = 0; for (int i = 1; i <= n; i++) { if (a[i] != no) { ha[++cnt].pos = a[i]; ha[cnt].num = 1; no = a[i]; } else ha[cnt].num++; } ha[++cnt].pos = 10000000; no = 1; for (int i = 1; i <= cnt; i++) { if (ha[i].pos == ha[no].pos) continue; if (ha[i].pos - k > ha[no].pos) ans += ha[no].num; no = i; } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int bs(vector<int> &lb, int i, int s) { int l = i; int h = (int)lb.size() - 1; while (l <= h) { int mid = (l + h) / 2; if (lb[mid] < s) { l = mid + 1; } else { h = mid - 1; } } return l; } int main() { int n, k; cin >> n >> k; vector<int> items(n); for (int i = 0; i < n; i++) { cin >> items[i]; } sort(items.begin(), items.end()); int cnt = 0; for (int i = 0; i < n; i++) { int res = bs(items, i + 1, items[i] + 1); if (res != n && items[res] <= items[i] + k) { cnt++; } } cout << n - cnt << endl; int pause; cin >> pause; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, K; vector<int> v; cin >> n >> K; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; v.push_back(tmp); } sort(v.begin(), v.end()); int size = 0; vector<int>::iterator pre, up; pre = v.begin(); do { up = upper_bound(pre, v.end(), *pre); if (up != v.end() && (*up <= *pre + K)) { size += up - pre; } pre = up; } while (up != v.end()); cout << n - size; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, c = 0; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int j; int index = -1; sort(arr, arr + n); int cc = 1; for (int i = 1; i < n; i++) { if (arr[i] > arr[i - 1] && arr[i] <= arr[i - 1] + k) { c = c + cc; cc = 1; } else if (arr[i] == arr[i - 1]) cc++; else cc = 1; } cout << n - c; return 0; }
#include <bits/stdc++.h> using namespace std; int ar[1000006], a[200005]; int main() { int n, K, i, j; long long int gb; cin >> n >> K; memset(ar, 0, sizeof(ar)); for (i = 0; i < n; i++) { cin >> a[i]; ar[a[i]]++; } sort(a, a + n); gb = 0ll; for (i = 1; i < n; i++) { j = i - 1; if (((a[j] < a[i]) && ((a[j] + K) >= a[i]))) { gb += (ar[a[j]]); } } cout << n - gb << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[1001001]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int last = a[n - 1] + k + 1, it = n - 1, ans = 0; for (; it >= 0;) { if (last > a[it] + k) { last = a[it]; while (it >= 0 && a[it] == last) { ans++; it--; } } else { last = a[it]; it--; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int ba[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &ba[i]); } sort(ba, ba + n, greater<int>()); int cnt = 0; for (int i = 0; i < n; i++) { int tar = lower_bound(ba, ba + n, ba[i] + k, greater<int>()) - ba; if (ba[tar] > ba[i]) { ++cnt; } } printf("%d\n", n - cnt); return 0; }
#include <bits/stdc++.h> namespace ringo { template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } template <class T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar('0' + x % 10); } template <class T> inline void print(T x, char c) { print(x), putchar(c); } const int N = 2e5 + 10, M = 1e6 + 10; int n, m, tn, ans; int a[N], cnt[M]; void main() { read(n), read(m); for (int i = 1; i <= n; i++) read(a[i]); ans = n; std::sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) ++cnt[a[i]]; tn = std::unique(a + 1, a + n + 1) - a - 1; for (int i = 2; i <= tn; i++) if (a[i - 1] + m >= a[i]) ans -= cnt[a[i - 1]]; print(ans, '\n'); } } // namespace ringo signed main() { return ringo::main(), 0; }
#include <bits/stdc++.h> int i, j, n, k, a[200005], ans, s, f[1000005] = {0}, p; int main() { scanf("%d %d", &n, &k); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); f[a[i]]++; } for (i = 0, ans = n, s = 0, p = -1; i <= 1000000; i++) if (f[i]) { if (p < 0) p = i; else { if (i <= p + k) ans -= f[p]; p = i; } } else s++; printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t, n, k, c = 0, d = 0; cin >> n >> k; map<long long, long long> m; for (int i = 0; i < n; ++i) { cin >> t; m[t]++; } auto it2 = m.begin(); for (auto it = m.begin(); it != m.end(); ++it) { it2 = it; it2++; t = it->first; if (it2 == m.end()) { c += it->second; break; } d = it2->first; if (t + k < d) c += it->second; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long ooo = 9223372036854775807ll; const int _cnt = 1000 * 1000 + 7; const int _p = 1000 * 1000 * 1000 + 7; const int N = 200005; const double PI = acos(-1.0); const double eps = 1e-9; int o(int x) { return x % _p; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } void file_put() { string s = "/home/jslijin/jslijin/code/"; freopen((s + "code.in").c_str(), "r", stdin); freopen((s + "code.out").c_str(), "w", stdout); } int n, k, a[N], ans; map<int, int> M; int main() { scanf("%d%d", &n, &k), ans = n; for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]), M[a[i]]++; sort(a + 1, a + n + 1), n = unique(a + 1, a + n + 1) - a - 1; for (int i = (1); i <= (n - 1); ++i) ans -= M[a[i]] * (a[i] < a[i + 1] && a[i] + k >= a[i + 1]); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; int n, k, ans, a[N]; multiset<int> st; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); int r = 0; for (int i = 0; i < n; i++) { while (r + 1 < n && a[r] <= a[i]) r++; if (a[i] + k >= a[r] && a[r] > a[i]) continue; ans++; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; int ara[2000105]; int fre[2000105]; int s[2000105]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &ara[i]); fre[ara[i]]++; } sort(ara, ara + n); int sz = 0; s[sz] = ara[0]; sz++; for (int i = 1; i < n; i++) { if (ara[i] != ara[i - 1]) { s[sz] = ara[i]; sz++; } } int cnt = fre[s[sz - 1]]; for (int i = 0; i < (sz - 1); i++) { if ((s[i] + k) < s[i + 1]) { cnt += fre[s[i]]; } } printf("%d\n", cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 7; const long long q = 7057594037927903; const long long prime = 2137; int n, k, wynik, poczatek, koniec, srodek, tab[M], czyzjedzony[M]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &tab[i]); sort(tab, tab + n); for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (czyzjedzony[j] == 1 || tab[i] > tab[j] + k || tab[j] == tab[i]) break; else czyzjedzony[j] = 1; } } for (int i = 0; i < n; i++) if (czyzjedzony[i] == 0) wynik++; printf("%d", wynik); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[200005]; int bs(int x) { int l = 0, r = n - 1; int m; while (l <= r) { m = (l + r) / 2; if (a[m] == x) return x; else if (a[m] > x) r = m - 1; else l = m + 1; } if (a[m] > x) m--; return a[m]; } bool com(int x) { auto it = upper_bound(a, a + n, x); int y = it - a; y = a[y]; if (x == a[n - 1]) y = x * 2; int b = bs(x + k); if (y <= b) return true; return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int r = n; for (int i = 0; i < n; i++) { if (com(a[i])) r--; } cout << r << endl; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:336777216") using namespace std; const double pi = atan((double)1.0) * 4; long long MOD = (long long)1e9 + 7; long long power(long long n, long long k) { if (k == 0) return 1; else if (k == 1) return n; else { if (k % 2 == 0) { return power((n * n) % MOD, k / 2); } else { return (power((n * n) % MOD, k / 2) * n) % MOD; } } } long long modInv(long long n) { return power(n, MOD - 2); } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } template <class T> bool reverse_sort(T a, T b) { return a > b; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, K; cin >> n >> K; map<long long, long long> arr; for (int i = 0; i < n; i++) { long long k; cin >> k; arr[k] += 1; } long long ans = n; for (auto it = arr.begin(); it != arr.end(); it++) { auto jt = it; jt++; if (jt == arr.end()) break; if (jt->first - it->first <= K) ans -= it->second; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; long long BigMod(long long N, long long P) { if (P == 0) return 1; if (P % 2 == 0) { long long ret = BigMod(N, P / 2); return ((ret % 1000000007) * (ret % 1000000007)) % 1000000007; } else return ((N % 1000000007) * (BigMod(N, P - 1) % 1000000007)) % 1000000007; } int a[200005]; int biS(int key, int mx, int lo, int hi) { int id; do { id = (lo + hi) / 2; if (a[id] > key) { if (a[id] > mx) { hi = id - 1; } else { return 1; } } else { lo = id + 1; } } while (lo <= hi); return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, K; while (cin >> n >> K) { for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); long long ans = n; for (int i = 1; i <= n; i++) { int x = a[i] + K; if (biS(a[i], x, 1, n)) { ans--; } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; long long a[N]; long long k; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; while (cin >> n >> k) { for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); int cnt = 0; for (int i = 1; i < n; i++) { if (a[i] == a[i - 1]) continue; int lo = lower_bound(a + 1, a + n + 1, a[i]) - a; int up = upper_bound(a + 1, a + n + 1, a[i]) - a; if (up <= n && a[i] + k >= a[up]) cnt += up - lo; } cout << n - cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, k; cin >> n >> k; multiset<long long> a; for (long long t, i = 0; i < n; i++) { cin >> t; a.insert(t); } long long j = INT_MAX; for (auto i : a) { if (i > j && i <= j + k) { a.erase(j); } j = i; } cout << a.size(); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; long long arr[n + 5]; bool vis[n + 5]; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; ++i) cin >> arr[i]; int ptr = 2; sort(arr + 1, arr + 1 + n, greater<long long>()); long long ans = 0; for (int i = 1; i <= n; ++i) { while (ptr <= n && arr[ptr] >= arr[i]) ptr++; while (ptr <= n && arr[i] <= arr[ptr] + k && arr[i] > arr[ptr]) { vis[ptr] = 1; ptr++; } } for (int i = 1; i <= n; ++i) { if (!vis[i]) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; inline int read() { int re = 0, flag = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') re = (re << 1) + (re << 3) + ch - '0', ch = getchar(); return re * flag; } int n, K, a[200010]; int main() { n = read(); K = read(); int i, j, cur = 0, ans = 0, pretot = 0, tot; for (i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); for (i = 1; i <= n; i++) { tot = 1; while (a[i + 1] == a[i]) tot++, i++; if (cur < a[i] || cur - K == a[i]) ans += pretot; cur = a[i] + K; pretot = tot; } ans += pretot; printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; int ax[210000]; int bn[210000]; int cn[1100000]; int main(void) { int n, k; scanf("%d%d", &n, &k); memset(bn, 0, sizeof(bn)); memset(cn, 0, sizeof(cn)); for (int i = 0; i < n; i++) { scanf("%d", &ax[i]); cn[ax[i]]++; } sort(ax, ax + n); for (int i = 0; i < n - 1; i++) { bn[i] = ax[i + 1] - ax[i]; } int tot = 0; for (int i = 0; i < n - 1; i++) { if (bn[i] <= k && bn[i] > 0) tot += cn[ax[i]]; } printf("%d\n", n - tot); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 1e6 + 5; const int LIM = 1e6; bool tree[MAXN << 2]; void pushup(int rt) { tree[rt] = tree[rt << 1] || tree[rt << 1 | 1]; } void update(int pos, int l, int r, int rt) { if (pos == l && pos == r) { tree[rt] = true; return; } int m = (l + r) >> 1; if (pos <= m) update(pos, l, m, rt << 1); else update(pos, m + 1, r, rt << 1 | 1); pushup(rt); } bool query(int L, int R, int l, int r, int rt) { if (L > R) return false; if (L <= l && r <= R) return tree[rt]; int m = (l + r) >> 1; if (L <= m) { if (query(L, R, l, m, rt << 1)) return true; } if (m < R) { if (query(L, R, m + 1, r, rt << 1 | 1)) return true; } return false; } int a[MAXN]; int main() { int n, K; scanf("%d%d", &n, &K); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); update(a[i], 1, LIM, 1); } int ans = n; for (int i = 1; i <= n; i++) { if (query(a[i] + 1, min(a[i] + K, LIM), 1, LIM, 1)) ans--; } if (!ans) ans++; printf("%d\n", ans); return 0; }