#P1589. Minimum Boards to Cover Muddy Road

    ID: 14875 Type: Default 1000ms 256MiB

Minimum Boards to Cover Muddy Road

Minimum Boards to Cover Muddy Road

After heavy rain, the road from FJ’s farm to the town has several muddy segments. You are given (N) intervals ([a, b]) representing the portions of the road that are muddy. FJ has an unlimited supply of wooden boards, each of length (L). The boards can be placed arbitrarily along the road, but each board covers exactly (L) units of distance.

Your task is to determine the minimum number of boards required to completely cover all the muddy segments.

inputFormat

The first line of input consists of two integers (N) and (L), where (N) is the number of muddy segments and (L) is the length of each board. Each of the following (N) lines contains two integers (a) and (b), denoting the start and end coordinates of a muddy segment.

outputFormat

Output a single integer representing the minimum number of boards needed to cover all the muddy segments completely.

sample

3 3
1 6
13 20
5 14
7