Lexicographic Smallest Array
Practice
5 (2 votes)
Math
C++
Basic math
Problem
87% Success 771 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

​Given an array \(A\) consisting of integers, find the lexicographically smallest array possible, if we can swap the elements of the array with a distance greater than or equal to \(K\).
Note: We can swap array \(a_i\) and \(a_j\), if \(|i - j| > K - 1\).

Input:
The first line contains two positive integers \(N\) and \(K\).
The next line contains an array consisting of \(N\) integers.

Output:
The output should be the lexicographic smallest array possible after applying the operations.

Constraints:
\(1 \leq N \leq 10^5\)
\(1 \leq K \leq N\)
\(1 \leq A_i \leq 10^9\)

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:20
5 votes
Tags:
Ad-HocEasyMathematicsSieveOpenApprovedMathamatics
Points:20
4 votes
Tags:
Basic ProgrammingOpenApprovedEasy
Points:20
Tags:
Easy