Under construction

Still being built. Things may change

Mountain Ranges

Interview

Time limit0.1sMemory limit512 MB

Summary
Given non-decreasing viewpoint altitudes along a trail, find the length of the longest run where each consecutive altitude increase is at most X, starting anywhere.
Level

Easy3 of 10

Topics
Array, Two pointers, Greedy, Implementation
Solved
No attempts yet

Problem

Nlogonia, famous for its mountain ranges, attracts millions of tourists every year. The government sets aside a budget for continuously maintaining the hiking trails spread across the country, and most of them have scenic viewpoints reachable by wooden walkways and stairs.

Lola and her husband are traveling through Nlogonia and hope to return home with plenty of pictures. They want to visit as many viewpoints as possible. They plan to hike a different trail each day and explore its viewpoints. To avoid being exhausted at the end of the day, if moving from one viewpoint to the next requires going up more than X meters, they simply call it a day and go back to their hotel to rest. Fortunately, every hiking trail in Nlogonia has modern chairlifts, so the couple can start hiking the trail at any viewpoint they choose. Once the hike begins, the couple moves only toward the peak of the mountain.

To make sure she does not waste a day, Lola wants to hike only on trails where she will reach a reasonable number of viewpoints. Given the altitudes of the scenic viewpoints on a hiking trail, determine the maximum number of viewpoints the couple can visit.

Input

The first line contains two integers N (1 ≤ N ≤ 1000) and X (0 ≤ X ≤ 8848), indicating the number of scenic viewpoints on the hiking trail and the maximum number of meters Lola and her husband are willing to go up from one viewpoint to the next. The second line contains N integers A1, A2, . . . , AN (1 ≤ Ai ≤ 8848 for i = 1, 2, . . . , N), where Ai is the altitude (in meters) of the i-th viewpoint. Viewpoints are given in the order they appear on the hiking trail, and their altitudes are non-decreasing, that is, Ai ≤ Ai+1 for i = 1, 2, . . . , N − 1.

Output

Output a single line with an integer indicating the maximum number of scenic viewpoints that can be visited without going up more than X meters from one viewpoint to the next, considering that the journey can be started at any viewpoint.

Examples3

  1. Example 1

    Input
    9 2
    3 14 15 92 653 5897 5897 5898 5900
    
    Expected output
    4
    
  2. Example 2

    Input
    9 0
    3 14 15 92 653 5897 5897 5898 5900
    
    Expected output
    2
    
  3. Example 3

    Input
    9 8848
    3 14 15 92 653 5897 5897 5898 5900
    
    Expected output
    9