Micro and Array Update
Practice
3.8 (869 votes)
Ad Hoc
Approved
Data structures
Easy
One Dimensional
Problem
73% Success 139751 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
337 votes
Tags:
1-D arrayArraysData Structures
Points:10
113 votes
Tags:
ArraysData Structures1-DC++
Points:10
25 votes
Tags:
ArraysData Structures1-D