Milly and magical array
Practice
3.5 (188 votes)
Ready
Mathematics
Open
Approved
Easy
Problem
28% Success 4096 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Milly is playing with an Array A of size N. She wants to convert this array into a magical array. This magical array satisfies the condition Ai-1 < Ai where i ∈ [2, N] . She can add a value X to any element of this array any number of times. Your task is to tell her the minimum number of such addition of X are required in order to get the magical array.
Input
- First line of the input will contain T(No. of test cases).
- For every test case, first line will contain two space separated integers denoting N and X. Next line will contain N space separated integers denoting Ai.
Output
- For every test case, print the required answer in a new line.
Constraints
- 1 ≤ T ≤ 10
- 2 ≤ N ≤ 105
- 1 ≤ X ≤ 109
- 1 ≤ Ai ≤ 109
Explanation
Test case #1: Add 1 to the second value.
Test case #2: Add 1 to the second value and add 1 to the third value.
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
Dynamic ProgrammingAlgorithmsMediumDynamic programming
Points:50
3 votes
Tags:
AlgorithmsGraphsMax flowMaximum Bipartite MatchingMaximum flowMediummaxflow
Points:30
636 votes
Tags:
MediumGraph TheorySortingReadyApprovedDisjoint set
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output