A sequence a[0], a[1], …, a[N-1] is called decreasing if a[i] >= a[i+1] for each i: 0 <= i < N-1. You are given a sequence of numbers a[0], a[1],…, a[N-1] and a positive integer K. In each 'operation', you may subtract K from any element of the sequence. You are required to find the minimum number of 'operations' to make the given sequence decreasing.

**Input:**

The first line contains a positive integer T denoting the number of test cases. Each of the test case consists of 2 lines. The first line of each test case contains two integers N and K. Next line contains space separated sequence of N integers.

**Output:**

Output the minimum number of ‘operations’ for each case on new line.Print your answer modulo 10^{9}+7.

**Constraints:**

1 <= T <=100

1 <= N <= 10^{6}

1 <= K <= 100

1 <= a[] <= 10^{3}

**Example:**

**Input:**

3

4 5

1 1 2 3

5 2

5 4 3 2 1

5 3

5 4 3 3 1

**Output:**

3

0

0

**Explanation:**

For 1^{st} case: One operation is required to change a[2] = 2 into -3 and two opertations are required to change a[3] = 3 into -7. The resulting sequence will be 1 1 -3 -7. Hence, in total 3 operations are required.

For 2^{nd }and 3^{rd} cases: The sequence is already decreasing. Hence, no operations are required in both the cases.

Author: sajalagrawal

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.