fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,b) for(ll i =a; i<b;++i)
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define endl "\n"
  6. #define pb push_back
  7. #define F first
  8. #define S second
  9. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  10. #define print1(a) for(auto x : a) cout << x.F << " " << x.S << endl
  11. #define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
  12. #define mk(x,y) make_pair(x,y)
  13. typedef long long int ll;
  14. const int N = ( 2e6 + 5 );
  15. const int mod = 1e9+7;
  16. ll n , m , q ,sz , a[N] ,l,r , ans , pos;
  17.  
  18. ll pow_mod_m(ll a , ll n)
  19. {
  20. if(!n)
  21. return 1;
  22. ll pt = pow_mod_m(a,n/2);
  23. pt *= pt ; pt %= mod;
  24. if(n&1)
  25. pt *= a , pt %= mod;
  26. return pt;
  27. }
  28.  
  29. void solve( ll l ,ll r)
  30. {
  31. if( l == pos+1 or r == pos-2) return;
  32. if( llabs(min(a[l],a[r]))*2 + a[r] - a[l] > m)
  33. {
  34. // cout << " in here with l and r as : " << l << r << endl;
  35. solve(l+1,r);
  36. solve(l,r-1);
  37. }
  38. else
  39. {
  40. // cout << " in here with l and r as : " << l << r << endl;
  41. ans = max(ans,r-l+1);
  42. return;
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. IOS;
  49. // freopen("a_example (2).txt","r",stdin);
  50. // freopen("c.txt","w",stdout);
  51.  
  52. int ts =1;
  53. //cin>>ts;
  54. while(ts--)
  55. {
  56. cin >> n >> m;
  57. rep(i,0,n){
  58. cin >> a[i];
  59. }
  60. rep(i,0,n)
  61. {
  62. if(a[i-1] < 0 and a[i] > 0)
  63. {
  64. pos = i;
  65. }
  66. }
  67. if(pos ==0 )
  68. {
  69. if(a[0] > 0 ) pos = 0;
  70. if(a[n-1] < 0) pos = n-1;
  71. }
  72. solve(0,n-1);
  73. cout << ans << endl;
  74. }
  75. }
Success #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
0