fork download
  1. #include <bits/stdc++.h>
  2. #define VuDucNam ios_base::sync_with_stdio(false);
  3. #define Lop9a6 cin.tie(NULL);
  4. #define THCSPhamVanDong cout.tie(NULL);
  5. #define ll long long
  6. #define el cout << '\n'
  7. #define sz(a) (ll) a.size()
  8. #define all(a) a.begin(), a.end()
  9. #define fi first
  10. #define se second
  11. #define fill(a, x) memset(a, x, sizeof(a))
  12. #define file(name) \
  13.   if (fopen(name ".INO", "r")) \
  14.   { \
  15.   freopen(name ".INP", "r", stdin); \
  16.   freopen(name ".OUT", "w", stdout); \
  17.   }
  18. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  19. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  20.  
  21. using namespace std;
  22.  
  23. const int N5 = 1e5 + 5;
  24. const ll MOD = 1e9 + 7;
  25. const ll inf = LLONG_MAX;
  26.  
  27. int n,k,a[1005],dp[1005],ans=0;
  28.  
  29. void solve()
  30. {
  31. cin >> n >> k;
  32. for(int i=1;i<=n;++i){
  33. cin >> a[i];
  34. dp[i]=1;
  35. for(int j=1;j<i;++j){
  36. if(a[j]+k==a[i]){
  37. dp[i]=max(dp[i],dp[j]+1);
  38. }
  39. }
  40. ans=max(ans,dp[i]);
  41. }
  42. cout << ans;
  43. el;
  44. }
  45.  
  46. int main()
  47. {
  48. VuDucNam Lop9a6 THCSPhamVanDong
  49. file("BAI5");
  50. solve();
  51. RUNTIME;
  52. return 0;
  53. }
Success #stdin #stdout #stderr 0s 5288KB
stdin
Standard input is empty
stdout
0
stderr
Runtime: 0.004686s.