All Tracks Data Structures Arrays 1-D Problem

Micro and Array Update
Tag(s):

Ad-Hoc, Data Structures, Very-Easy

Problem
Editorial
Analytics

Micro purchased an array $$A$$ having $$N$$ integer values. After playing it for a while, he got bored of it and decided to update value of its element. In one second he can increase value of each array element by $$1$$. He wants each array element's value to become greater than or equal to $$K$$. Please help Micro to find out the minimum amount of time it will take, for him to do so.

Input:
First line consists of a single integer, $$T$$, denoting the number of test cases.
First line of each test case consists of two space separated integers denoting $$N$$ and $$K$$.
Second line of each test case consists of $$N$$ space separated integers denoting the array $$A$$.

Output:
For each test case, print the minimum time in which all array elements will become greater than or equal to $$K$$. Print a new line after each test case.

Constraints:
$$1 \le T \le 5$$
$$1 \le N \le 10^5$$
$$1 \le A[i], K \le 10^6$$

SAMPLE INPUT
2
3 4
1 2 5
3 2
2 5 5
SAMPLE OUTPUT
3
0
Explanation

For first test case,
After $$1$$ second, array will be $$\{ 2, 3, 6\}$$
After $$2$$ second, array will be $$\{ 3, 4, 7\}$$
After $$3$$ second, array will be $$\{ 4, 5, 8\}$$

So it will take $$3$$ second for all array elements to become greater than or equal to $$4$$.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic, Kotlin

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

March Easy '17

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications