Descending Weights
Practice
3.9 (17 votes)
Easy
Sorting
Problem
46% Success 3727 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You have been given an array A of size N and an integer K. This array consists of N integers ranging from 1 to \(10^7\). Each element in this array is said to have a Special Weight. The special weight of an element \(a[i]\) is \(a[i]\%K\).

You now need to sort this array in Non-Increasing order of the weight of each element, i.e the element with the highest weight should appear first, then the element with the second highest weight and so on. In case two elements have the same weight, the one with the lower value should appear in the output first.

Input Format:

The first line consists of two space separated integers N and K. The next line consists of N space separated integers denoting the elements of array A.

Output Format:

Print N space separated integers denoting the elements of the array in the order in which they are required.

Constraints:

\( 1 \le N \le 10^5 \)

\( 1 \le A[i] \le 10^7 \)

\( 1 \le K \le 10^7 \)

Note:

You need to print the value of each element and not their weight.

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
No similar problems found
Editorial

No editorial available for this problem.