Alex_tz307

Grupe X - 6.6.1 / pag 171

Sep 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. inline void max_self(int& a, int b) {
  6.     a = max(a, b);
  7. }
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(nullptr);
  12.     cout.tie(nullptr);
  13.     int N, x;
  14.     cin >> N >> x;
  15.     vector < int > a(N);
  16.     for(int& x : a)
  17.         cin >> x;
  18.     vector < int > dp(N);
  19.     dp[N - 1] = 1;
  20.     int ans = 1;
  21.     for(int i = N - 2; i >= 0; --i) {
  22.         int mx = 0;
  23.         for(int j = i + 1; j < N; ++j)
  24.             if(a[j] - a[i] >= x)
  25.                 max_self(mx, dp[j]);
  26.         dp[i] = mx + 1;
  27.         max_self(ans, dp[i]);
  28.     }
  29.     cout << ans;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment