Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- inline void max_self(int& a, int b) {
- a = max(a, b);
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int N, x;
- cin >> N >> x;
- vector < int > a(N);
- for(int& x : a)
- cin >> x;
- vector < int > dp(N);
- dp[N - 1] = 1;
- int ans = 1;
- for(int i = N - 2; i >= 0; --i) {
- int mx = 0;
- for(int j = i + 1; j < N; ++j)
- if(a[j] - a[i] >= x)
- max_self(mx, dp[j]);
- dp[i] = mx + 1;
- max_self(ans, dp[i]);
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment