fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e6+14;
  4. int n, a[maxn], f[maxn], p;
  5. map < int , int > m;
  6. bool comp(int a, int b) {
  7. return a >= b;
  8. }
  9. void solve(){
  10. cin >> n >> p;
  11. for (int i = 1; i <= n; i++){
  12. cin >> a[i];
  13. }
  14. f[n + 1] = -1e9 + 31;
  15. for (int i = n; i >= 1; i--){
  16. f[i] = max(f[i + 1], a[i]);
  17. }
  18.  
  19. int ans = 0;
  20. for (int i = 1; i <= n; i++) {
  21. int pos = lower_bound(f + i, f + 1 + n, a[i] + p, comp) - f - 1;
  22. ans = max(ans , pos - i);
  23. }
  24.  
  25. cout << ans ;
  26. }
  27. int main(){
  28. ios_base::sync_with_stdio(0);
  29. cin.tie(0); cout.tie(0);
  30. if (fopen("input.txt","r")){
  31. freopen("input.txt","r",stdin);
  32. freopen("output.txt","w",stdout);
  33. }
  34. solve();
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty