#P10837. 『FLA - I』云音泛

    ID: 10325 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟离散化洛谷原创O2优化排序前缀和队列差分洛谷月赛

『FLA - I』云音泛

Description

In his dream, Qiu planted nn roses. He remembered that the ii-th rose was planted at the moment tit_i.

A rose comes out as soon as it is planted. However, each rose will bloom for exactly mm moments (the rose planted at the moment TT will bloom from the moment TT to the moment T+m1T+m-1). After mm moments, the rose turns into unretained dust, fading away in the cold wind.

Qiu asks you, if he can change the planting moment of at most one rose (that is, select an tit_i and modify it to an arbitrary positive integer), for how many moments at most will there be exactly one rose blooming?

Input Format

The first line of input contains two integers nn and mm — the number of roses and the blooming time of each rose.

The second line of input contains nn integers t1,t2,,tnt_1,t_2,\dots, t_n — the planting moment of each rose.

Output Format

Output a single line containing an integer denoting the answer.

5 4
11 9 1 3 12

14

13 7
6 42 58 41 20 60 2 61 45 28 45 28 12

38

Hint

「Sample Explanation #1」

As the figure below, use golden stripes to mark the moments when exactly one rose is blooming, and use black and red stripes to mark the periods when each rose comes out.

example1

If we modify the planting moment of the rose with red mark to 1717 (i.e. we modify t1t_1 to 1717, as the figure below), the number of golden moments becomes 1414. It can be proven that there is no other scheme that makes the answer greater than 1414, therefore we should output 1414.

example2

「Constraints」

Test Id nn \leq mm \leq tit_i \leq
161 \sim 6 50005000
7127 \sim 12 2×1052 \times 10^5 2×1052 \times 10^5
131413 \sim 14 11 10910^9
152015 \sim 20 10910^9

Each test is worth 55 points.

For all tests, it is guaranteed that 1n2×1051 \leq n \leq 2 \times 10^5, 1m,ti1091 \leq m,t_i \leq 10^9.