Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CAU2"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- constexpr int N = 1e3 + 5;
- constexpr int Inf = 1e9 + 7;
- int n, a[N], h, f[N];
- void Read()
- {
- cin >> n >> h;
- for (int i = 1; i <= n; ++i)
- cin >> a[i];
- }
- void Solve()
- {
- sort(a + 1, a + n + 1);
- for (int i = 1; i <= n; ++i)
- {
- f[i] = Inf;
- for (int j = i; j >= 1 && a[i] - a[j] <= h; --j)
- f[i] = min(f[i], f[j - 1] + 1);
- }
- cout << f[n];
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement