Array Sorting

flash_7 AUST CSE 44th Batch(1.1)...
Limits 2s, 1.0 GB

Sorting an array is not any easy task. You have to apply so many difficult algorithms to perform the sorting. In this task you are going to follow a new technique to sort an array invented by our NSUPS algorithms specialists.

You'll be given an array A of N integers and two more integers X and K. You are allowed to perform the following operation to change the array elements:

Select any integer from the array and increment its value by X.

You have to find out whether you can make the array sorted after performing the above operation maximum K times.


The first line of the input contains an integer T which denotes the number of test cases.
The first line of each test case contains three integers N, K and X. The following two lines of a test case represent the elements of the array A.


  • 1 ≤ T ≤ 20
  • 1 ≤ N ≤ 50000
  • 1 ≤ K ≤ 1000000000
  • 1 ≤ X, Ai ≤ 100000


For each test case, print the result in the format “Case X: Y” where Y is either YES or NO depending on the result.


5 8 3
7 5 3 2 1
5 11 3
7 5 3 2 1
Case 1: NO
Case 2: YES


Login to submit.


88% Solution Ratio
ridzz007Earliest, Apr '20
Sarwar.445674Fastest, 0.0s
Mansura_170300Lightest, 0 B
sarthakmannaShortest, 312B
Toph uses cookies. By continuing you agree to our Cookie Policy.