text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; const double eps = 1e-9; inline int read() { int ans = 0, fh = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fh = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); return ans; } const int maxn = 2e5 + 100; int n, k, a[maxn], ans; int main() { n = read(), k = read(); for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); for (int i = 2; i <= n; i++) { if (a[i] != a[i - 1] && a[i] <= a[i - 1] + k) { ans++; int pa = i - 1; while (a[pa] == a[pa - 1] && pa > 1) ans++, pa--; } } printf("%d", n - ans); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(const bool &b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(const A &v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } int a[200005]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); int ans = 0; int ls = n; for (int i = n - 1; i; --i) { if (a[ls] > a[i] && a[ls] - k <= a[i]) ans++; if (a[i] != a[ls] && a[i] != a[i - 1]) ls = i; } n -= ans; cout << n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int a[maxn]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int remain = 0; for (int i = 1; i <= n; i++) { auto lo = lower_bound(a + i, a + 1 + n, a[i] + k); auto hi = upper_bound(a + i, a + 1 + n, a[i]); if (lo == hi && (*lo <= a[i] || *lo > a[i] + k)) remain++; } printf("%d\n", remain); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int num[MAXN]; bool mark[MAXN]; bool comp(int a, int b) { return a > b; } int main(void) { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> num[i]; sort(num + 1, num + n + 1, comp); int ans = n; for (int i = n - 1; i >= 1; i--) { if (num[i] == num[i + 1]) continue; int j; for (j = i + 1; j <= n && num[i] - num[j] <= k && !mark[j]; j++) ans--, mark[j] = 1; } cout << ans << "\n"; }
#include <bits/stdc++.h> using std::sort; int a[200005]; 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 ans = n; for (int i = 0; i < n - 1; ++i) { int cnt = 1; while (a[i + 1] == a[i]) { i++; cnt++; } if (a[i] + k >= a[i + 1] && a[i + 1] > a[i]) ans -= cnt; } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int a[1000009], vis[1000009]; int main() { int n, k, num, sz; cin >> n >> k; sz = n; for (int i = 0; i < n; i++) { cin >> num; if (vis[num]++ == 0) a[i] = num; else sz--; } sort(a, a + n, greater<int>()); for (int i = sz - 1; i > 0; i--) { if (a[i] < a[i - 1] && a[i] + k >= a[i - 1]) n -= vis[a[i]]; } cout << n; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int a[n], i, j, p; bool b[n]; for (int i = 0; i <= n - 1; ++i) { cin >> a[i]; b[i] = 1; } sort(a, a + n); for (int i = 1; i <= n - 1; ++i) { if (a[i] > a[i - 1]) { p = a[i - 1]; if (a[i] <= (a[i - 1] + k)) { for (int j = i - 1; j >= 0; j--) { if (a[j] == p) { b[j] = 0; } else break; } } } } int sum = 0; for (int i = 0; i <= n - 1; ++i) { if (b[i] == 1) sum++; } cout << sum << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[200007]; int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int acc = 1, cnt = 0; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) { if (a[i] <= a[i - 1] + k) cnt += acc; acc = 1; } else acc++; } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> arr(n); for (long long i = 0; i < n; i++) { cin >> arr[i]; } sort(arr.begin(), arr.end()); long long cnt = n; for (long long i = 0; i < n; i++) { long long w = upper_bound(arr.begin(), arr.end(), arr[i]) - arr.begin(); if (w == arr.size()) { break; } else { if ((arr[i] + k) >= arr[w]) { cnt--; } } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long *a = new long long[n]; long long i, j; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long count = n; for (i = 0; i < n - 1; i++) { if (a[i] != a[i + 1] && a[i] + k >= a[i + 1]) { long long temp = i; while (temp >= 0 && a[temp] == a[i]) count--, temp--; } } cout << count; }
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long mod) { long long c = 1; while (b > 0) { if (b % 2) c *= a, c %= mod; b /= 2; a *= a; a %= mod; } return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; long long a[n]; map<long long, long long> cnt; for (long long i = 0; i < n; i++) { cin >> a[i]; cnt[a[i]]++; } sort(a, a + n); long long x = 0; for (long long i = 0; i < n; i++) { if (a[i] < a[i + 1]) { if (a[i] + k >= a[i + 1]) { x += cnt[a[i]]; } } } cout << n - x << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int a[2000200], b[2002000], c[2002000]; int main() { int n, m; scanf("%d%d", &n, &m); memset(b, 0, sizeof(b)); for (int i = 0; i < n; i++) { int x; scanf("%d", &a[i]); b[a[i]]++; } sort(a, a + n); int ans = 0, max0 = a[n - 1], max2 = a[n - 1]; int k = 0; for (int i = 1; i < 1000001; i++) { if (b[i]) c[k++] = i; } for (int i = 0; i < k - 1; i++) { if (c[i + 1] <= c[i] + m) ans += b[c[i]]; } printf("%d\n", n - ans); return 0; }
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast") using namespace std; void timestamp(char const* const tag, bool absolute = false); size_t n; int k; vector<int> a; void read() { cin >> n >> k; a.resize(n); for (auto& v : a) { cin >> v; } } void solve() { sort(a.begin(), a.end()); int ans = static_cast<int>(n); size_t last_surviving = 0; for (size_t curr = 0; curr < n; ++curr) { while (a[last_surviving] < a[curr] - k) { ++last_surviving; } while (a[last_surviving] < a[curr]) { ++last_surviving; --ans; } } cout << ans << endl; } void timestamp(char const* const tag, bool absolute) { static double last = 0; double now = (static_cast<double>(clock()) / CLOCKS_PER_SEC) * 1000; if (absolute) { ; } else { ; last = now; } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); timestamp("start"); read(); timestamp("read()"); solve(); timestamp("solve()"); timestamp("total", true); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n, k, count = 0; cin >> n >> k; vector<long> v; for (int i = 0; i < n; i++) { long x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { long long up = upper_bound(v.begin(), v.end(), v[i] + k) - v.begin() - 1; if (v[up] != v[i]) count++; } cout << v.size() - count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; map<long long, long long> vect; cin >> n >> k; long long a; while (n--) { cin >> a; vect[a]++; } map<long long, long long>::iterator it = vect.begin(); while (1) { if (vect.size() == 1) break; map<long long, long long>::iterator it2 = ++it; it--; if (it2 == vect.end()) break; long long q = it->first; long long r = it2->first; if (q < r && q + k >= r) { vect[it->first] = 0; } it++; } long long ans = 0; for (it = vect.begin(); it != vect.end(); it++) { ans += it->second; } cout << ans << endl; }
#include <bits/stdc++.h> using ll = long long; using namespace std; const ll mod = 1e9 + 7; const ll num = 1e9; const int N = 1e6 + 5; int main() { int n, k; scanf("%d%d", &n, &k); vector<int> v(n); for (int i = 0; i < n; i++) scanf("%d", &v[i]); sort(v.begin(), v.end()); int c = 0; for (int i = 0; i < n; i++) { auto it = upper_bound(v.begin(), v.end(), v[i] + k); it--; int id = it - v.begin(); if (id > i && v[i] + k >= v[id] && v[id] > v[i]) c++; } printf("%d", n - c); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); 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 = 0; while (a.size()) { int cur = a.back(); while (a.size() && a.back() == cur) ans++, a.pop_back(); while (a.size() && a.back() >= cur - k) cur = a.back(), a.pop_back(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 1e18; int main() { long long n, k; cin >> n >> k; vector<long long> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); long long ans = n; for (int i = 0; i < n; i++) { auto it = upper_bound(v.begin(), v.end(), v[i]); if (it != v.end() && *it <= v[i] + k) ans--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double M = 144115188075855872; long long a[200100]; int main() { long long n, k, t = 0; cin >> n >> k; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); t = n; long long q = 0; for (long long i = 1; i < n; i++) { if (a[i] == a[i - 1]) { q++; continue; } if (a[i] > a[i - 1] && a[i] <= a[i - 1] + k) { q++; t -= q; } q = 0; } cout << t; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); cout.tie(0); int n, k, a[200001], i = 1, sospesi = 0, eliminati = 0; cin >> n >> k; if (n == 1) { cout << 1; return 0; } for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); while (i < n) { if (a[i] - a[i - 1] > k) sospesi = 0; else if (a[i] - a[i - 1] == 0) sospesi++; else { eliminati += sospesi + 1; sospesi = 0; } i++; } cout << n - eliminati; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20); long long int n, m; cin >> n >> m; vector<long long int> v(n); for (long long int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); long long int cnt = 0; long long int extra = 0; for (auto i = 1; i <= n - 1; i++) { if (v[i] != v[i - 1] && v[i - 1] + m >= v[i]) { cnt++; cnt += extra; } else if (v[i - 1] == v[i]) { extra++; } if (v[i] != v[i - 1]) extra = 0; } cout << n - cnt; ; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; double pi = 3.1415926535898; string ys = "Yes\n"; string no = "No\n"; const double EPS = 1e-6; const int inf = 2e9; const long long M = 998244353; const int N = 100100; int n, k; int a[200200]; map<int, int> mp; vector<int> v; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> n >> k; for (int i = 1; i <= int(n); i++) cin >> a[i]; for (int i = 1; i <= int(n); i++) mp[a[i]]++; sort(a + 1, a + n + 1); v.push_back(a[1]); for (int i = 2; i <= int(n); i++) { if (a[i] != a[i - 1]) { v.push_back(a[i]); } } int ans = 0; int lst = n; for (int i = 0; i < int(v.size()); i++) { if (v[i + 1] > v[i] && v[i + 1] <= v[i] + k) { ans += mp[v[i]]; } } cout << n - ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, ele, count = 0; cin >> n >> k; set<int> s; set<int>::iterator it, pre; unordered_map<int, int> mp; while (n--) { cin >> ele; if (mp.find(ele) == mp.end()) mp[ele] = 1; else mp[ele] = mp[ele] + 1; s.insert(ele); } it = s.begin(); it++; if (it == s.end()) cout << mp[ele] << endl; else { while (it != s.end()) { it--; pre = it; it++; if (*it > *pre && *it - *pre <= k) { } else count += mp[*pre]; it++; } it--; count += mp[*it]; cout << count << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, c; vector<long long> a; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> c; a.push_back(c); } sort(a.begin(), a.end()); c = n; stack<long long> b; for (int i = 0; i < n - 1; i++) { if (a[i] + k >= a[i + 1] && a[i] != a[i + 1]) { c--; while (!b.empty()) { if (b.top() + k >= a[i + 1]) { c--; b.pop(); } else break; } } else { if (a[i] == a[i + 1]) { b.push(a[i]); } } } cout << c; }
#include <bits/stdc++.h> using namespace std; vector<int> v; int n, k; map<int, int> mp; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; if (!mp[x]) v.push_back(x); mp[x]++; } sort(v.begin(), v.end()); int ans = 0; for (int i = 1; i < v.size(); i++) { if (v[i - 1] + k >= v[i]) ans += mp[v[i - 1]]; } cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int a[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int i = n - 1, ans = 0; while (i >= 0) { int j = i; while (j >= 0 && a[j] == a[i]) j--; ans += i - j; int las = a[i] - k; while (j >= 0 && a[j] >= las) las = a[j] - k, j--; i = j; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int UP = 2e5 + 5; int n; long long int k, a[UP]; int main() { scanf("%d%lld", &n, &k); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); sort(a, a + n); stack<long long int> s; for (int i = 0; i < n; i++) { while (s.size() && s.top() < a[i] && a[i] <= s.top() + k) s.pop(); s.push(a[i]); } printf("%d\n", s.size()); return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> m; int main() { ios::sync_with_stdio(false); int n, k; while (cin >> n >> k) { int a[n + 5]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = 1; i < n; i++) { if (a[i] > a[i - 1] && a[i] - a[i - 1] <= k) { m[a[i - 1]] = 1; } } int cnt = 0; for (int i = 0; i < n; i++) { if (m[a[i]] == 0) { cnt++; } } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> const long double eps = 1e-10; const int MOD = 1000000007; using namespace std; int a[200005], K, n; int main() { scanf("%d %d", &n, &K); for (int i = 0; i < n; ++i) scanf("%d", a + i); sort(a, a + n); int ret = 0; for (int i = 0; i < n - 1; ++i) { int b = a[i] + K; int low = i + 1, high = n; while (low <= high) { int mid = (low + high) >> 1; if (a[mid] == a[i]) { low = mid + 1; continue; } if (a[mid] > a[i] && a[mid] <= b) { ++ret; break; } else { high = mid - 1; } } } printf("%d\n", n - ret); return 0; }
#include <bits/stdc++.h> const unsigned long long base = 1237; using namespace std; int n, k; int a[200010]; void init() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); } int main() { init(); sort(a, a + n); int ans = 0; int j = 0; for (int i = 0; i < n; ++i) { while (a[i] >= a[j] && j < n) j++; if (j < n && a[j] > a[i] && a[j] <= a[i] + k) ans++; } cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> Map; set<int> Set, Sec; int ans; int main() { int N, K; int num; cin >> N >> K; for (int i = 0; i < N; i++) { scanf("%d", &num); Set.insert(num); if (Map.find(num) == Map.end()) { Map.insert(make_pair(num, 1)); } else { Map[num] = Map[num] + 1; } } set<int>::iterator iter = Set.begin(); set<int>::iterator lst = iter; iter++; for (; iter != Set.end(); iter++) { if (*lst + K >= *iter) { Sec.insert(*lst); } lst++; } for (iter = Sec.begin(); iter != Sec.end(); iter++) { ans += Map[*iter]; } cout << N - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; map<long long, long long> d; for (long long i = (0); i < (long long)(n); i++) { long long x; cin >> x; d[x]++; } long long total = n; for (auto &z : d) { long long x = z.first; auto it = d.lower_bound(x - k); vector<long long> erase; while (it->first < x) { total -= it->second; erase.push_back(it->first); it++; } for (auto &x : erase) { d.erase(x); } } printf("%lld\n", total); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int A[MAXN], N, K; int main() { scanf("%d %d", &N, &K); for (int i = 1; i <= N; ++i) scanf("%d", &A[i]); if (N == 1) { puts("1"); return 0; } sort(A + 1, A + N + 1); int left = 1, right = 2, cnt = 0; while (right <= N) { if (A[left] == A[right]) { while (A[left] == A[right]) right++; } else { if (left == right) right++; else { if (A[right] <= A[left] + K) cnt++, left++; else left++; } } } printf("%d\n", N - cnt); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x, m, c = 0; int d[1000010] = {0}; cin >> n >> k; m = 20000000; for (int i = 0; i < n; i++) { cin >> x; d[x]++; } for (int i = 1000000; i >= 1; i--) if (d[i] > 0) { if (m > i + k) c += d[i]; m = i; } cout << c; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } sort(a, a + n); int ct = 0; int mrk = 0; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1] && a[i] <= a[i - 1] + m) { ct += mp[a[i - 1]]; } } cout << n - ct; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<pair<int, int> > wek; int tab[n], temp = 1; for (int i = 0; i < n; i++) { cin >> tab[i]; } sort(tab, tab + n); for (int i = 0; i < n; i++) { if (i > 0) { if (tab[i] == tab[i - 1]) { temp++; } else { wek.push_back(make_pair(tab[i - 1], temp)); temp = 1; } } } wek.push_back(make_pair(tab[n - 1], temp)); int wynik = 0; for (int i = 1; i < wek.size(); i++) { if (wek[i].first <= wek[i - 1].first + m) wynik += wek[i - 1].second; } cout << n - wynik; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long n, K; cin >> n >> K; vector<long long> v(n); for (long long _i = 0; _i < (long long)v.size(); ++_i) cin >> v[_i]; sort(v.begin(), v.end()); long long res = 0; for (long long i = 0; i < n; ++i) { long long j = i, cnt = 0; while (v[j] == v[i]) { j++; if (j == n) break; } if (j == n) res += j - i; else if (v[i] + K < v[j]) res += j - i; i = j - 1; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; const int M = 1e6 + 500; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int BASE = 31337; const int LOG = 18; const int OFF = (1 << LOG); const double EPS = 1e-9; const double PI = 3.1415926535; int n, k, bio[2 * M + 10]; vector<int> v; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); v.push_back(x); bio[x]++; } for (int i = 1; i < 2 * M; i++) { bio[i] += bio[i - 1]; } int sol = 0; for (int i = 0; i < v.size(); i++) { if ((bio[v[i] + k] - bio[v[i]]) == 0) sol++; } printf("%d\n", sol); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const double PI = acos(-1.0); const int MOD = 1e9 + 7; int n, K; int a[MAXN]; vector<pair<int, int>> segs; 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) { int L = 1, R = i; if (a[i - 1] == a[i]) { segs.emplace_back(i, i); continue; } while (L < R) { int mid = (L + R) / 2; if (a[mid] == a[i] || a[i] - a[mid] > K) L = mid + 1; else R = mid; } segs.emplace_back(R, i); } sort(segs.begin(), segs.end()); int res = 1; int rmax = 0; for (int i = 0; i < n - 1; ++i) { rmax = max(rmax, segs[i].second); if (rmax < segs[i + 1].first) { ++res; } } printf("%d", res); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; int n, k; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int num = 0; for (int i = 1; i < n; i++) { if (a[i] == a[n]) break; int x = upper_bound(a + 1, a + 1 + n, a[i]) - a; if (a[i] + k >= a[x]) num++; } printf("%d\n", n - num); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int a[n + 5]; fill(a, a + n + 4, 1e9); for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int j = 0, ans = 0; for (int i = 0; i < n; i++) { while (j < n && a[j] == a[i]) j++; if (a[j] > a[i] + k) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int arr[200008]; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &arr[i]); } sort(arr, arr + n); int res = n; int cnt = 0; for (int i = 0; i < n - 1; ++i) { if (arr[i + 1] == arr[i]) { cnt++; } else if (arr[i + 1] - arr[i] <= k) { res -= (cnt + 1); cnt = 0; } else { cnt = 0; } } printf("%d", res); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> v; vector<int>::iterator up; long long i; for (i = 0; i < n; i++) { long long a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); long long count = n; for (i = 0; i < n; i++) { up = upper_bound(v.begin(), v.end(), v[i]); if (up != v.end() && v[up - v.begin()] <= v[i] + k) { count--; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; const int MX = 1 << 22; const int MOD = 1000000007; const int64_t mod2 = 1000000007 * 1LL * 1000000007; double strtod(string second) { stringstream str(second); double number = 0; str >> number; return number; } int64_t strtoll(string second) { stringstream str(second); int64_t number = 0; str >> number; return number; } int64_t ff[50005], M[30005][505]; int64_t vis[100005], pref[100005]; int64_t cnt, n, m, second, t; vector<int> gr[100005]; int dn[1005][1005]; char str[1001][1001]; int dx[] = {-1, 1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, -1, 1, 1, -1, -1, 1}; bool valid(int x, int y) { if (x >= 0 && x < n && y >= 0 & y < m) return true; return false; } int64_t dis[200005], dis2[200005]; vector<pair<int64_t, int64_t> > grp[200005]; void dijkstra(int64_t v) { set<pair<int64_t, int64_t> > second; second.insert({0, v}); dis[v] = 0; while (!second.empty()) { auto ff = *second.begin(); second.erase(second.begin()); for (auto i : grp[ff.second]) { if (ff.second == n + 1) { if (dis[ff.second] + i.second < dis[i.first]) { second.erase({dis[i.first], i.first}); dis[i.first] = dis[ff.second] + i.second; second.insert({dis[i.first], i.first}); } } else { if (dis[ff.second] + 2 * 1LL * i.second < dis[i.first]) { second.erase({dis[i.first], i.first}); dis[i.first] = dis[ff.second] + 2 * 1LL * i.second; second.insert({dis[i.first], i.first}); } } } } } int Rank[100001], parent[100001], Color[100001][101]; int qu[200001], qq[200001], pai[200001], qar[200001]; int xxx[101], yyy[101]; int findSet(int x) { return (parent[x] = (parent[x] == x) ? x : findSet(parent[x])); } int isSameSet(int x, int y) { return findSet(x) == findSet(y); } void unionSet(int x, int y) { if (!isSameSet(x, y)) { int xx = findSet(x), yy = findSet(y); if (Rank[xx] > Rank[yy]) { parent[yy] = xx; } else { parent[xx] = yy; } if (Rank[xx] == Rank[yy]) Rank[yy]++; } } bool isBetween(pair<int, int> a, pair<int, int> b, pair<int, int> c) { int crossproduct = (c.second - a.second) * (b.first - a.first) - (c.first - a.first) * (b.second - a.second); if (abs(crossproduct) != 0) return false; int dotproduct = (c.first - a.first) * (b.first - a.first) + (c.second - a.second) * (b.second - a.second); if (dotproduct < 0) return false; int squaredlengthba = (b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second); if (dotproduct > squaredlengthba) return false; return true; } int64_t fast_pow(int64_t a, int64_t b, int64_t mod) { int64_t res = 1; while (b) { if (b & 1) { res = (1LL * res * a) % mod; } a = (1LL * a * a) % mod; b >>= 1; } return res; } int64_t MMI_fermat(int64_t n, int64_t MOD) { return fast_pow(n, MOD - 2, MOD); } struct trie { int val; trie *child[2]; }; trie *get_node() { trie *new_node = new trie(); new_node->val = 0; new_node->child[0] = NULL; new_node->child[1] = NULL; return new_node; } void add(trie *root, int key) { trie *head = root; for (int i = 29; i >= 0; i--) { bool bit = (key & (1 << i)); if (head->child[bit] == NULL) { head->child[bit] = get_node(); } head = head->child[bit]; } head->val = key; } int get_Min(trie *root, int key) { trie *head = root; for (int i = 29; i >= 0; i--) { bool bit = (key & (1 << i)); if (head->child[bit] != NULL) { head = head->child[bit]; } else if (head->child[1 ^ bit] != NULL) { head = head->child[1 ^ bit]; } } return key ^ (head->val); } int get_Max(trie *root, int key) { trie *head = root; for (int i = 29; i >= 0; i--) { bool bit = (key & (1 << i)); if (head->child[1 ^ bit] != NULL) { head = head->child[1 ^ bit]; } else if (head->child[bit] != NULL) { head = head->child[bit]; } } return key ^ (head->val); } int st[MX]; pair<int, int> ar[MX]; int fans[MX]; void build_st(int l, int r, int idx) { if (l == r) { st[idx] = 1; return; } int mid = (l + r) / 2; build_st(l, mid, 2 * idx); build_st(mid + 1, r, 2 * idx + 1); st[idx] = st[2 * idx] + st[2 * idx + 1]; } void print(int idx, int n) { if (2 * idx >= 2 * n) { cout << fans[idx] << " "; return; } print(idx * 2, n); print(2 * idx + 1, n); } void inversion_count(int second, int e, int ar[], int &ans) { if (second >= e) return; int mid = (second + e) / 2; inversion_count(second, mid, ar, ans); inversion_count(mid + 1, e, ar, ans); int i = second, j = mid + 1; int aux[e - second + 1]; int k = 0; while (i <= mid && j <= e) { if (ar[i] <= ar[j]) { aux[k] = ar[i]; k++; i++; } else { ans += (mid - i + 1); aux[k] = ar[j]; k++; j++; } } while (i <= mid) { aux[k] = ar[i]; k++; i++; } while (j <= e) { aux[k] = ar[j]; k++; j++; } int l = second; for (int i = 0; i < k; i++) { ar[l] = aux[i]; l++; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n); int ct = 0; for (int i = 0; i < n; i++) { int ub = upper_bound(ar, ar + n, ar[i] + k) - ar; if (ub - 1 != i && ar[ub - 1] - ar[i] <= k && ar[ub - 1] > ar[i]) { ar[i] = -1; ct++; } } cout << (n - ct) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int arr[200000 + 10]; int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int ans = n; for (int i = 1; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (arr[j] == -1) { break; } if (arr[i] > arr[j] && arr[j] + k >= arr[i]) { ans--; arr[j] = -1; } else break; } } cout << ans; return 0; }
#include <bits/stdc++.h> const long long mod = 1000000007ll; const long long Mod = 1000000009ll; const long long maxn = 100005; using namespace std; int main() { int n, k; cin >> n >> k; vector<long long> a(n); int f[1000005] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; f[a[i]]++; } int ans = n; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { int index = upper_bound(a.begin(), a.end(), a[i] + k) - a.begin() - 1; if (index - i > 0 && a[i] != a[index]) { ans = ans - f[a[i]]; f[a[i]] = 0; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > a; unordered_map<int, int> um; int n; int m; bool eat(pair<int, int> x, pair<int, int> y) { if (x.first > y.first && y.first + m >= x.first) return true; return false; } int main() { cin >> n >> m; int x; for (int k = 0; k < n; k++) { cin >> x; um[x]++; } for (auto i : um) { a.push_back(make_pair(i.first, i.second)); } sort(a.begin(), a.end()); int s = 0; for (int k = 0; k < a.size() - 1; k++) { if (eat(a[k + 1], a[k])) { s += a[k].second; } } cout << n - s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long n, k; cin >> n >> k; if (n == 1) { cout << "1" << endl; return 0; } std::vector<long long> a; long long temp; for (long long i = 0; i < n; i++) { cin >> temp; a.push_back(temp); } sort(a.begin(), a.end()); long long j = 1, l = 0; while (true) { if ((a[j] - a[l] <= k) && (a[j] > a[l])) { a[l] = 0; l = l + 1; if (j == l) j++; } if (j == n) break; if (a[j] - a[l] > k) { l = l + 1; if (j == l) j++; } if (j == n) break; if (a[j] <= a[l]) j++; if (j == n) break; } long long count = 0; for (long long i = 0; i < n; i++) { if (a[i] != 0) count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } sort(v.begin(), v.end()); int c = 0; for (int i = 0; i < n - 1; ++i) { int index1 = upper_bound(v.begin(), v.end(), v[i]) - v.begin(); int index2 = lower_bound(v.begin(), v.end(), v[i] + k) - v.begin(); if (index1 == n) continue; else { if (index2 == n) c++; else { if (v[index2] == (v[i] + k)) c++; else if ((index2 - 1) != i && v[index2 - 1] > v[i]) c++; } } } printf("%d", n - c); return 0; }
#include <bits/stdc++.h> using namespace std; int a[200010]; int main() { int n, k; while (~scanf("%d%d", &n, &k)) { for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int sum = 0; for (int i = 1; i <= n; i++) { int ans1 = upper_bound(a + 1, a + 1 + n, a[i]) - a - 1; int ans2 = upper_bound(a + 1, a + 1 + n, a[i] + k) - a - 1; if (ans1 != ans2) sum++; } printf("%d\n", n - sum); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, i, nr, poz; int v[200010], nxt[200010]; int main() { cin >> n >> k; for (i = 1; i <= n; i++) cin >> v[i]; sort(v + 1, v + n + 1); poz = n + 1; for (i = n; i; i--) { if (v[i] == v[i + 1]) nxt[i] = nxt[i + 1]; else nxt[i] = i + 1; } for (i = 1; i <= n; i++) { if (v[nxt[i]] - v[i] <= k && v[nxt[i]] > v[i]) nr++; } cout << n - nr; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200008; inline int read() { int s = 0, w = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') w = -1; for (; isdigit(c); c = getchar()) s = 10 * s + c - '0'; return s * w; } long long n, m, cnt = 1, a[N], s[N], ans; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { a[i] = read(); } sort(a + 1, a + n + 1); for (int i = 2; i <= n; i++) { if (a[i] == a[i - 1]) { cnt++; continue; } if (a[i] - a[i - 1] <= m && a[i] > a[i - 1]) { ans += cnt; cnt = 1; continue; } if (a[i] > a[i - 1]) cnt = 1; } cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream &operator<<(ostream &out, pair<S, T> const &p) { out << p.first << " " << p.second; return out; } template <typename T> ostream &operator<<(ostream &out, vector<T> const &v) { long long int l = v.size(); for (long long int i = 0; i < l - 1; i++) out << v[i] << ' '; if (l > 0) out << v[l - 1]; return out; } template <typename T> void trace(const char *name, T &&arg1) { cout << name << " : " << arg1 << "\n"; } template <typename T, typename... Args> void trace(const char *names, T &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; trace(comma + 1, args...); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; long long int arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); reverse(arr, arr + n); vector<pair<long long, long long> > v; long long int curr, count = 0; for (long long int i = 0; i < n; i++) { if (i == 0) { curr = arr[i]; count = 1; } else { if (arr[i] == curr) { count++; } else { v.push_back(make_pair(curr, count)); curr = arr[i]; count = 1; } } } v.push_back(make_pair(curr, count)); long long int si = v.size(); long long int ans = 0; for (long long int i = si - 2; i >= 0; i--) { long long int c = v[i].first; long long int cn = v[i + 1].first; if (c <= cn + k) { ans += v[i + 1].second; } } cout << n - ans << "\n"; return 0; }
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; using namespace std; int n, k, a[maxn]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); int cnt = 0; a[n + 1] = inf; for (int i = 1; i <= n - 1; i++) { int pos = upper_bound(a + 1, a + 1 + n, a[i]) - a; if (a[pos] <= a[i] + k) cnt++; } cout << n - cnt << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; template <typename X> inline X abs(const X& a) { return a < 0 ? -a : a; } template <typename X> inline X sqr(const X& a) { return a * a; } const int size = 1e5 + 2; const double eps = 0.0001; const long double PI = 3.1415926535897932384626433832795; const long long MOD = 1000000007; const long long INF = 1LL << 60; const long long MAX5 = 100001; const long long MAX6 = 1000001; const long long MAX17 = 99999999999999999; const double DMAX = 2e18 + 5; void solution(); void include_file(); int main() { ios_base::sync_with_stdio(false); solution(); return 0; } void include_file() { ios_base::sync_with_stdio(true); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } inline bool isPrime(long long n) { for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } string ekv(string a) { if (a.size() & 1) return a; string x = ekv(a.substr(0, a.size() / 2)); string y = ekv(a.substr(a.size() / 2)); return min(x + y, y + x); } long long cubic_root(long long x) { long long l = 0, r = MAX6; while (l != r) { long long m = (l + r + 1) / 2; if (m * m * m > x) r = m - 1; else l = m; } return l; } float FastInvSqrt(float x) { float xhalf = 0.5f * x; int i = *(int*)&x; i = 0x5f3759df - (i >> 1); x = *(float*)&i; x = x * (1.5f - (xhalf * x * x)); return x; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void yes() { cout << "YES"; } void no() { cout << "NO"; } void yes(bool res) { if (res) cout << "YES"; else cout << "NO"; } void dabl(double x) { printf("%.10lf", x); } namespace bits { template <typename X> inline X MAX(const X& a, const X& b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); } template <typename X> inline X MIN(const X& a, const X& b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); } bool check2(const long long n) { return n > 0 && (n & (n - 1)); } long long ostatok2(const long long n, const long long m) { return m & (n - 1); } template <typename X> void SWAP(X& a, X& b) { a ^= b; b ^= a; a ^= b; } size_t count_1_in_LL(unsigned long long n) { std::size_t i(0); for (; n; ++i) n &= n - 1; return i; } } // namespace bits vector<vector<int> > g; inline void solution() { long long n, k; cin >> n >> k; int a[n]; for (long long i = 0; i < n; ++i) cin >> a[i]; ; map<int, int> q; for (long long i = 0; i < n; ++i) q[a[i]]++; sort(a, a + n); int res = 0; auto it = q.begin(); it++; for (; it != q.end(); ++it) { auto ita = it; ita--; if ((*ita).first + k >= (*it).first) res += (*ita).second; } cout << n - res; }
#include <bits/stdc++.h> using namespace std; int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int prime100[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103}; template <typename T> inline bool isLeap(T y) { return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); } template <typename T> inline T GCD(T a, T b) { a = abs(a); b = abs(b); if (a < b) swap(a, b); while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline T LCM(T x, T y) { T tp = GCD(x, y); if ((x / tp) * 1. * y > 9e18) return 9e18; return (x / tp) * y; } template <typename T> inline T BIGMOD(T A, T B, T M = 1000000009) { T ret = 1; while (B) { if (B & 1) ret = (ret * A) % M; A = (A * A) % M; B = B >> 1; } return ret; } template <typename T> inline T BigMod(T A, T B, T M) { T ret = 1; while (B) { if (B & 1) ret = (ret * A) % M; A = (A * A) % M; B = B >> 1; } return ret; } long long int MySqrt(long long int n) { long long int p = sqrt(n); if ((p + 1) * (p + 1) <= n) return p + 1; else if (p * p <= n) return p; else return p - 1; } long long int MyPow(long long int x, long long int n) { if (n == 0) return 1; else if (n % 2 == 0) return MyPow(x * x, n / 2); else return x * MyPow(x * x, ((n - 1) / 2)); } int arr[200005]; int main(int argc, char const *argv[]) { int n, k; scanf("%d%d", &(n), &(k)); for (int i = 0; i < n; i++) { scanf("%d", &(arr[i])); } sort(arr, arr + n); int i = 0, cnt = 0, same = 0; while (i < n) { int x = arr[i]; int now = x + k; int pos = n; same = 0; for (int j = i + 1; j < n; j++) { if (x == arr[j]) { same++; continue; } else if (arr[j] <= now && arr[j] > x) { same = 0; pos = j; break; } else { pos = j; cnt++; cnt = cnt; break; } } cnt = cnt + same; i = pos; } printf("%d\n", cnt + 1); }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long long int expo(long long int x, long long int y) { long long int res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } void matmul(long long int a[][2], long long int b[][2]) { long long int tmp[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { tmp[i][j] = 0; for (int k = 0; k < 2; k++) tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % mod; } } for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) a[i][j] = tmp[i][j]; } long long int fibo(int n) { if (n == 0) return 0; else if (n == 1) return 1; long long int T[2][2] = {{0, 1}, {1, 1}}; long long int res[2][2] = {{1, 0}, {0, 1}}; n--; while (n) { if (n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k, i, cnt = 0; cin >> n >> k; vector<int> a; for (i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); } sort((a).begin(), (a).end()); multiset<int> s; multiset<int>::iterator it, itr; for (i = 0; i < n; i++) s.insert(a[i]); for (int i = 0; i < n; i++) { it = s.upper_bound(a[i]); if (it != s.end()) { if (*it <= a[i] + k) { s.erase(s.find(a[i])); } } } cout << ((int)(s).size()); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; const long long M = 8007; const long long mod = 5e9 + 7; long long n, k; long long a[N]; int main() { scanf("%lld%lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } sort(a + 1, a + n + 1); int ans = 0; for (int i = 2; i <= n; i++) { if (a[i - 1] + k < a[i]) { int j = i - 1; while (a[j] == a[i - 1]) { ans += 1; j -= 1; } } } int j = n; while (a[j] == a[n]) { j -= 1; ans += 1; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } sort(v.begin(), v.end()); int count = 0, add = 1; for (int i = 1; i < n; i++) { if (v[i] > v[i - 1] && v[i] <= v[i - 1] + k) { count += add; add = 1; } else if (v[i] == v[i - 1]) add++; else add = 1; } cout << n - count; return 0; }
#include <bits/stdc++.h> using namespace std; int n, K; vector<int> vect; int res; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> K; res = n; for (int i = 0; i < n; i++) { int a; cin >> a; vect.push_back(a); } sort(vect.begin(), vect.end()); int L = 0; int R = 0; for (int i = 0; i < n; i++) { L = max(L, i); while (L < n && vect[L] == vect[i]) L++; while (R < n && vect[R] <= vect[i] + K) R++; if (R > L) res--; } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k, arr[200009]; bool done[200009]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (int i = 0; i < n; i++) { int l = i, r = n; while (r - l > 1) { int m = (l + r) / 2; if (arr[m] > arr[i] && arr[m] <= arr[i] + k) { done[i] = 1; break; } if (arr[m] > arr[i]) r = m; else l = m; } } int ans = 0; for (int i = 0; i < n; i++) { if (done[i] == 0) { ans++; } } cout << ans << endl; exit(0); }
#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); long long int count = 0; vector<long long int> v; vector<long long int> v1; i = 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; int main() { int n, k; cin >> n >> k; vector<int> arr; arr.resize(n); for (int i = 0; i < n; ++i) cin >> arr[i]; sort(arr.begin(), arr.end()); int ans = n, hv = 0; for (int i = 0; i < n - 1; ++i) { if (arr[i + 1] == arr[i]) hv++; else { if (arr[i + 1] - arr[i] <= k) ans -= hv + 1; hv = 0; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int tree[1000000 + 10]; int a[1000000 + 10]; int lowbit(int x) { return x & (-x); } void add(int x, int val) { for (int i = x; i <= 1000000; i += lowbit(i)) tree[i] += val; } int query(int x) { int ans = 0; for (int i = x; i; i -= lowbit(i)) ans += tree[i]; return ans; } int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); a[x]++; add(x, 1); } for (int i = 1; i <= 1000000; i++) { if (!a[i]) continue; int sj = min(1000000, i + k); int q = query(sj) - query(i); if (q) add(i, -a[i]); } int ans = query(1000000); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } bool cmp(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first == p2.first) return p1.second < p2.second; return abs(p1.first - p1.second) < abs(p2.first - p2.second); } int32_t main() { 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, greater<long long>()); long long p1 = 0, p2 = 1; long long count = 0; while (p1 != n - 1) { if ((a[p1] > a[p2]) && (a[p1] <= a[p2] + k)) { count++; p2++; } else p1++; if (p1 == p2) p2++; } cout << n - count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int Getint() { char c = getchar(); int ret = 0, f = 1; while (!isdigit(c)) { if (c == '-') f = -f; c = getchar(); } while (isdigit(c)) ret = (ret << 1) + (ret << 3) + c - '0', c = getchar(); return ret * f; } const int Maxn = 2e5 + 50; int a[Maxn]; int n, k; int main() { n = Getint(), k = Getint(); for (int i = 1; i <= n; i++) a[i] = Getint(); sort(a + 1, a + n + 1); int temp = 0; int i = 2, j = 1; for (; i <= n; i++) { while (a[j] + k >= a[i] && a[j] < a[i]) j++, temp++; while (a[j] != a[i]) j++; } cout << n - temp; return 0; }
#include <bits/stdc++.h> using namespace std; long long a[1000016]; map<long long, long long> mp; map<long long, long long>::iterator it, it2; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i, k, cnt = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } it = mp.begin(); it2 = mp.begin(); it++; for (; it != mp.end(); it++, it2++) { if (it2->first + k >= it->first) cnt += it2->second; } cout << n - cnt << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, K; int arr[maxn], val[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> K; int res = n; for (int i = 1; i <= n; ++i) cin >> arr[i]; sort(arr + 1, arr + 1 + n); int cnt = 1; val[1] = 1; for (int i = 2; i <= n; ++i) { if (arr[i] != arr[i - 1]) arr[++cnt] = arr[i], val[cnt] = 1; else ++val[cnt]; } for (int i = 2; i <= cnt; ++i) { if (arr[i] <= arr[i - 1] + K) { res -= val[i - 1]; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chkmin(T& x, T y) { return x > y ? x = y, true : false; } template <class T> inline bool chkmax(T& x, T y) { return x < y ? x = y, true : false; } inline long long read(void) { long long x, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f; } int a[200005], n, k, q, ss; int main(void) { n = read(); k = read(); for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); q = 1; ss = 1; for (int i = (n - 1); i >= (1); --i) { if (a[i + 1] == a[i] && ss == 1) q++; else if (a[i + 1] - a[i] > k) { q++; ss = 1; } else ss = 0; } printf("%d\n", q); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; const int N = 2e5 + 10; int a[N]; vector<int> sta; int main() { ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; ++i) { while (sta.size() && sta.back() < a[i] && a[i] <= sta.back() + k) { sta.pop_back(); } sta.push_back(a[i]); } cout << sta.size() << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int co = 0, g, i, n, y, m, d, j, k, z, t, x = 0, a, b, c, l, r; cin >> n >> k; vector<long long int> ar; map<long long int, long long int> mp; for (i = 0; i < n; i++) { cin >> x; if (mp[x] == 0) ar.push_back(x); mp[x]++; } sort(ar.begin(), ar.end()); for (i = 1; i < ar.size(); i++) { if (ar[i - 1] + k >= ar[i]) ar[i - 1] = -1; } co = 0; for (i = 0; i < ar.size(); i++) { if (ar[i] != -1) co += mp[ar[i]]; } cout << co; return 0; } bool prime(long long int n) { bool x = true; int i; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) { x = false; } } return x; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v; int x; int count = 0; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.rbegin(), v.rend()); for (int i = 0; i < n - 1; i++) { if (v[i] <= v[i + 1] + k && v[i] != v[i + 1]) { count++; int y = v[i + 1]; while (i + 2 < n && v[i + 2] == y) { count++; i++; } } } cout << n - count; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; map<int, int> mp; for (int i = 0; i < N; i++) { int a; cin >> a; mp[a]++; } vec<Pa<int, int>> A; for (auto& x : mp) A.push_back(x); int ans = N; int n = A.size(); for (int i = 0; i + 1 < n; i++) { if (A[i].first + K >= A[i + 1].first) ans -= A[i].second; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0l); const long long MOD = 1e9 + 7; bool debug = 1; const int N = -1; int main() { long long n, k; cin >> n >> k; multiset<long long> s; for (int i = 0; i < n; i++) { long long x; scanf("%lld", &x); s.insert(x); } for (auto it = s.begin(); it != s.end();) { long long cand = *(--s.upper_bound(*it + k)); if (cand > *it and cand <= *it + k) it = s.erase(it); else it++; } cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long b[1000001], n, m, k, l, o, p, q, u, c[1000001], d[1000001], x, y, z, sum, ans, mn, mx; string s; map<long long, long long> e; vector<int> v; vector<int>::iterator it; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (int i = n - 2; i >= 0; i--) if (v[i + 1] - v[i] > m || (v[i + 1] == v[i] && d[v[i]] == 0)) { ans++; } else d[v[i]] = 1; cout << ans + 1; return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, k; cin >> n >> k; map<long long, long long> a; for (int i = 0; i < n; i++) { long long x; cin >> x; a[x]++; } vector<long long> kek; for (auto i : a) { kek.push_back(i.first); } long long ans = 0; for (int i = 1; i < kek.size(); i++) { if (kek[i] <= kek[i - 1] + k) { continue; } ans += a[kek[i - 1]]; } cout << ans + a[kek.back()]; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> v; map<int, int> m; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k; int t; while (cin >> n >> k) { m.clear(); v.clear(); for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); m[t]++; } sort(v.begin(), v.end()); int len = unique(v.begin(), v.end()) - v.begin(); int ans = n; for (int i = 1; i < len; i++) { if (v[i] <= v[i - 1] + k) ans -= m[v[i - 1]]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; int main() { int n, k, x, a[maxn], book[maxn]; while (scanf("%d %d", &n, &k) != EOF) { memset(a, 0, sizeof(a)); memset(book, 0, sizeof(book)); int ans = n, cnt = 0; for (int i = 0; i < n; i++) { scanf("%d", &x); if (!book[x]) a[cnt++] = x; book[x]++; } sort(a, a + cnt); for (int i = 1; i < cnt; i++) { if (a[i] - a[i - 1] <= k) ans = ans - book[a[i - 1]]; } printf("%d\n", ans); } 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() { static const int MPS = 1 << 20; std::vector<int> mp(MPS); int n, d; read(n); read(d); for (int i = 0; i < n; ++i) { int a; read(a); ++mp[a]; } int ans = n; for (int i = 0, j = 0; i < MPS; ++i) { if (mp[i]) { if (j <= i) j = i + 1; while (j < MPS && j - i < d && !mp[j]) ++j; if (j < MPS && j - i <= d && mp[j]) { ans -= mp[i]; } } } printf("%d\n", ans); return 0; } int main(int argc, char *argv[]) { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, temp, i; cin >> n >> k; long long int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long int count = 0; for (i = 0; i < n - 1; i++) { long long int j = i + 1; long long int cnt = 1; while (a[i] == a[j] && j < n) { j++; cnt++; } if (a[i] + k >= a[j]) { count = count + cnt; } i = j - 1; } cout << n - count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, K; cin >> n >> K; int *a = new int[n](); for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater<int>()); int count = n; for (int i = n - 1; i >= 0; i--) { int count_val = 0; while (i >= 1 && a[i] == a[i - 1]) { count_val++; i--; } if (i >= 1 && a[i - 1] > a[i] && a[i - 1] <= a[i] + K) { count = count - count_val - 1; } } cout << count; delete[] a; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005, MAXM = 1000005, INF = 1 << 29; int n, m, a[MAXN], s[MAXM], b[MAXN], bt; int main() { int ans = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); s[a[i]]++; } sort(a + 1, a + n + 1); for (int i = 1; i <= a[n]; i++) s[i] += s[i - 1]; for (int i = 1; i <= n; i++) if (a[i] != a[i - 1]) b[++bt] = a[i]; b[0] = -1; for (int i = 2; i <= bt; i++) ans += s[b[i] - 1] - s[max(b[i] - m, b[i - 1]) - 1]; cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, K; cin >> n >> K; int *a = new int[n](); for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater<int>()); int count = n; for (int i = n - 1; i >= 0; i--) { int count_val = 0; while (i >= 1 && a[i] == a[i - 1]) { count_val++; i--; } if (i >= 1 && a[i - 1] > a[i] && a[i - 1] <= a[i] + K) count = count - count_val - 1; } cout << count; delete[] a; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + +5; int a[maxn]; int main() { ios::sync_with_stdio(false); int n, m; int tmp; while (cin >> n >> m) { for (int i = 0; i < n; ++i) { cin >> a[i]; } int ans = n; sort(a, a + n); for (int i = 0; i < n; ++i) if (upper_bound(a + i, a + n, a[i] + m) - upper_bound(a + i, a + n, a[i]) > 0) --ans; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[531551]; long long arr[6546554]; map<long long, long long> mp; signed main() { long long n, m; cin >> n >> m; set<long long> ss; for (long long i = 1; i <= n; i++) { cin >> a[i]; ss.insert(a[i]); } if (ss.size() == 1) { cout << n << '\n'; return 0; } sort(arr + 1, arr + 1 + n); long long sum = 0; long long cnt = 0; for (long long i = 1; i <= n; i++) { if (!mp[a[i]]) { arr[cnt++] = a[i]; } mp[a[i]]++; } sort(arr, arr + cnt); for (long long i = 0; i < cnt - 1; i++) { if (arr[i] + m >= arr[i + 1] && arr[i + 1] > arr[i]) { sum += mp[arr[i]]; } } cout << n - sum; return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -f; for (; isdigit(ch); ch = getchar()) ret = ret * 10 + ch - 48; return ret * f; } int N, K, a[200005], vis[200005], ans; int main() { N = read(); K = read(); for (int i = 1; i <= N; i++) a[i] = read(); sort(a + 1, a + 1 + N); for (int i = 2; i <= N; i++) if (a[i] > a[i - 1] && a[i] <= a[i - 1] + K) { vis[i - 1] = 1; for (int j = i - 2; j >= 1; j--) if (a[j] == a[i - 1]) vis[j] = 1; else break; } for (int i = 1; i <= N; i++) if (!vis[i]) ans++; printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int module = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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 counter = n; int cnt = 1; for (int i = 0; i < n - 1; ++i) { if (a[i] == a[i + 1]) { cnt++; } else { if (a[i] < a[i + 1] && a[i] + k >= a[i + 1]) { counter -= cnt; } cnt = 1; } } cout << counter << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using vpii = vector<pair<int, int>>; using vpll = vector<pair<ll, ll>>; using pii = pair<int, int>; using pll = pair<ll, ll>; void solve() { int n, k; cin >> n >> k; vi a(n + 1); for (ll i = 0; i < n; i++) cin >> a[i]; ; a[n] = 1e9; sort(a.begin(), a.end()); int ans = 0, u = 0; for (int i = 0; i < n; i++) { while (u < n && a[i] == a[u]) { u++; } if (a[u] - a[i] > k) ans++; } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; long long vis[1000005]; int main() { set<long long> s; long long n, k, a; cin >> n >> k; for (long long i = 0; i < n; i++) { cin >> a; vis[a]++; s.insert(a); } set<long long>::iterator iter; long long ans = 0; for (iter = s.begin(); iter != s.end(); iter++) { long long temp = (*iter); iter++; if (iter == s.end()) break; if (*iter <= temp + k) ans += vis[temp]; iter--; } cout << n - ans << endl; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); template <typename T> inline void write(T x) { long long i = 20; char buf[21]; buf[20] = '\n'; do { buf[--i] = x % 10 + '0'; x /= 10; } while (x); do { putchar(buf[i]); } while (buf[i++] != '\n'); } void read(long long &x) { bool neg = false; register long long c; x = 0; c = getchar(); if (c == '-') { neg = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48; if (neg) x *= -1; } int main() { long long n, k; cin >> n >> k; long long a[n]; map<long long, long long> make_pair, mp2; for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (long long i = 0; i < n; i++) { long long diff = a[i] - k; long long lb = lower_bound(a, a + n, diff) - a; long long ub = lower_bound(a, a + n, a[i]) - a; if (lb == n or lb == ub) continue; if (make_pair[lb] < i or make_pair[lb] == 0) { make_pair[lb] = ub - 1; } } map<long long, long long>::iterator it = make_pair.begin(), lb, lb2; it = make_pair.begin(); long long prev = -1, ans = 0; for (; it != make_pair.end(); it++) { if ((*it).first > prev) ans += (*it).second - (*it).first + 1; else if ((*it).first <= prev) { ans += (*it).second - prev; } prev = (*it).second; } cout << n - ans; return 0; }
#include <bits/stdc++.h> using namespace std; void codeforces_edu_45_A() { long long n, m, a, b; scanf("%lld %lld %lld %lld", &n, &m, &a, &b); if (n % m == 0) { printf("0"); return; } else { long long i = m - n % m; long long j = n % m; if (a * i < b * j) { printf("%lld", a * i); } else { printf("%lld", b * j); } } } void codeforces_edu_45_B() { int n, k; scanf("%d %d", &n, &k); int a[1000005]; for (int i = 0; i < 1000005; i++) { a[i] = 0; } for (int i = 0; i < n; i++) { int t; scanf("%d", &t); a[t]++; } int ans = 0; int minmin = 100000000; for (int i = 1000000; i > 0; i--) { if (a[i] == 0) { continue; } else { if (i < minmin) { ans += a[i]; } minmin = i - k; } } printf("%d", ans); } void codeforces_edu_45_C() {} void codeforces_edu_45_D() {} void codeforces_edu_45_E() {} void codeforces_edu_45_F() {} int main() { codeforces_edu_45_B(); codeforces_edu_45_C(); codeforces_edu_45_D(); codeforces_edu_45_E(); codeforces_edu_45_F(); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; while (TESTS--) { long long int n, a[200005], k, c = 0, x; cin >> n >> k; std::map<long long int, long long int> lol; for (int i = 0; i < n; i++) { cin >> x; if (lol[x] == 0) { a[c] = x; c++; } lol[x]++; } sort(a, a + c); x = 0; for (int i = 1; i < c; i++) { if (a[i - 1] + k >= a[i]) { x += lol[a[i - 1]]; } } cout << n - x; } return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { long long n, k; cin >> n >> k; int a; vector<int> st; for (int i = 0; i < n; i++) { cin >> a; mp[a]++; if (mp[a] == 1) st.push_back(a); } int ans = 0; sort(st.begin(), st.end()); for (int i = 0; i < st.size() - 1; i++) { if (st[i] + k >= st[i + 1]) { ans += mp[st[i]]; } } cout << n - ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e5 + 10; int main() { int n, k; cin >> n >> k; vector<int> v(n); for (auto &x : v) cin >> x; sort(v.begin(), v.end()); vector<int> ans; for (auto &x : v) { while (!ans.empty() && ans.back() < x && x <= ans.back() + k) ans.pop_back(); ans.push_back(x); } cout << ans.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[200000]; vector<pair<int, int> > v; int main() { int i, j, n, K; scanf("%d%d", &n, &K); for (i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int ind_low = 0, ind_high = 0; for (i = 1; i < n; i++) { int ele = a[i]; for (j = ind_low; j <= i; j++) { if (a[j] >= ele - K) { ind_low = j; break; } } for (j = ind_high; j <= i; j++) { if (a[j] >= ele) { ind_high = j - 1; break; } } if (ind_high >= ind_low) v.push_back(make_pair(ind_low, ind_high)); } int sz = v.size(); if (sz == 0) printf("%d\n", n); else { int ans; for (i = 0; i < sz; i++) { int low = v[i].first, prev_high = v[i - 1].second; if (i == 0) ans = low; else if (low > prev_high + 1) ans += (low - prev_high - 1); } ans += (n - 1 - v[sz - 1].second); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } int a[200005]; int main() { int n = read(), k = read(); for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); int j = 1, ans = n; for (int i = 2; i <= n; i++) while (a[i] != a[j]) { if (a[i] > a[j] && a[i] <= a[j] + k) ans--; j++; } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int main() { long long n, k; while (~scanf("%lld%lld", &n, &k)) { long long a[maxn] = {0}; vector<long long> v; for (int i = 1; i <= n; i++) { scanf("%lld", a + i); } sort(a + 1, a + 1 + n); for (int i = 1; i <= n; i++) { while (!v.empty() && v.back() < a[i] && v.back() + k >= a[i]) { v.pop_back(); } v.push_back(a[i]); } cout << v.size() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { 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 cnt = 0, j = 0; a[n] = int(2e9); for (int i = 0; i < n; i++) { while (j < n && a[j] == a[i]) ++j; if (a[j] - a[i] > k) ++cnt; } cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 200005; int n, k, in[MAXN]; bool check(int id) { int v = in[id]; int tmp = upper_bound(in, in + n + 1, v) - in; if (in[tmp] - v <= k) return true; return false; } int main() { ios::sync_with_stdio(0), cin.tie(0); while (cin >> n >> k) { for (int i = 0; i < n; ++i) { cin >> in[i]; } sort(in, in + n); in[n] = 20000000; int ret = 0; for (int i = 0; i < n; ++i) { if (check(i)) continue; else ret++; } cout << ret << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[1000001] = {}, s[1000001] = {}, r = 0, b; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> b; a[b]++; } for (int i = 1; i < 1000001; i++) s[i] = s[i - 1] + a[i]; for (int i = 1; i < 1000000; i++) if (s[min(i + k, 1000000)] - s[i] == 0) r += a[i]; cout << r + a[1000000]; }