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