Global warming

Time limit2sMemory limit512 MB

Summary
Choose one contiguous interval and a shift d with |d| <= x, then find the maximum possible length of a strictly increasing subsequence of the modified sequence.
Level

Hard8 of 10

Topics
Dynamic programming, Binary search, Segment tree, Greedy
Solved
No attempts yet

Problem

Global warming is an important issue and Johnny knows about it. He decided to analyze historical temperatures and find a subsequence of days (not necessarily consecutive) where the temperature was strictly increasing. That will convince the non-believers!

Johnny has found historical data from nn consecutive days. The temperature on the ii-th day was tit_i.

Formally, we are interested in finding the length of the longest increasing subsequence (LIS) of (t1,t2,…,tn)(t_1, t_2, \ldots, t_n), that is, the largest possible kk for which it is possible to choose an increasing sequence of indices 1≤a1<a2<…<ak≤n1 \le a_1 < a_2 < \ldots < a_k \le n such that ta1<ta2<…<takt_{a_1} < t_{a_2} < \ldots < t_{a_k}.

Johnny wants to find a really long subsequence, and that is why he decided to cheat a bit. He will first choose a non-empty interval of days and an integer dd (−x≤d≤x-x \le d \le x), and he will increase the temperature on each of those days by dd. A small change like that probably will not be noticed by the community, while at the same time it should make the LIS longer. It is allowed to choose d=0d = 0.

What is the largest possible length of the LIS after a change?

Input

The first line of the standard input contains two space-separated integers nn and xx (1≤n≤200 0001 \le n \le 200\ 000, 0≤x≤1090 \le x \le 10^9), the number of days and the limit for the absolute value of dd.

The second line contains nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n (1≤ti≤1091 \le t_i \le 10^9) separated by spaces, the sequence of historical temperatures.

Output

Print one integer, the largest possible length of the LIS after a single change.

Examples1

  1. Example 1

    Input
    8 10
    7 3 5 12 2 7 3 4
    
    Expected output
    5