GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 31 July 2022

[Solution] Luke is a foodie Codeforces Solution


B. Luke is a foodie
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Luke likes to eat. There are n piles of food aligned in a straight line in front of him. The i-th pile contains ai units of food.

Luke will walk from the 1-st pile towards the n-th pile, and he wants to eat every pile of food without walking back. When Luke reaches the i-th pile, he can eat that pile if and only if |vai|x, where x is a fixed integer, and v is Luke's food affinity.

Before Luke starts to walk, he can set v to any integer. Also, for each i (1in), Luke can change his food affinity to any integer before he eats the i-th pile.

Find the minimum number of changes needed to eat every pile of food.

  • of 
Solution Click Below:-  👉CLICK HERE👈

👇👇👇👇👇

Note that the initial choice for v is not considered as a change.

Input

The input consists of multiple test cases. The first line contains a single integer t (1t104) — the number of test cases. The description of test cases follows.

For each test case, the first line contains two integers, n,x (1n21051x109) — the number of piles, and the maximum difference between the size of a pile and Luke's food affinity, such that Luke can eat the pile.

The second line contains n integers a1,a2,,an (1ai109).

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

For each test case, output an integer on a separate line, which is the minimum number of changes needed.

No comments:

Post a Comment