Adding Array Elements

easy
1. You are given an array of N elements. 2. You are also given a number K. 3. You have to find the minimum number of steps in which the elements of the array can be added to make all the elements greater than or equal to K. 4. You are allowed to add only two elements together and make them one in a single step. For example: Input : arr[] = {1 10 12 9 2 3} and K = 6 Output : 2 Explanation: First we add (1 + 2), now the new list becomes 3 10 12 9 3, then we add (3 + 3), now the new list becomes 6 10 12 9, Now all the elements in the list are greater than or equal to 6. Hence the output is 2 i.e 2 steps are required to do this. 5. display is a utility function, feel free to use it for debugging purposes. 6. main takes input from the users and creates the array. 7. This is a functional problem. 8. You have to complete the steps function. It takes as input an array and K. It should return an integer representing the minimum number of steps(if possible), else should return -1. 9. Don't change the code of main and display.

Input Format

First line takes input N, the length of the array. Second line takes input N space separated numbers representing the elements of the array. Third line takes input K. Input is handled for you.

Output Format

Minimum number of steps, if possible else -1. Output is handled for you.

Constraints

1 <= N <= 30000
  1 <= arr[i] <= 10^6

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6 
1 10 12 9 2 3 
6
Output
2
Previous
Valid Sudoku
Next
Cheapest Flights Within K Stops

Related Questions