F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Not only STL

Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 283    Accepted Submission(s): 22


Problem Description
As you know in STL there is a function called next_permutation, when you send a array to it, it will Rearranges the elements in the array into the next lexicographically greater permutation.

But today we need a next_k_permutation, you may say we can just apply k times next_permutation function to the array. Yes, you are right, but when k is very large it is not efficient enough.

So you are expected to write a program when given an array and k to find its next_k_permutation.
Note the next permutation of the permutation with largest dictionary order is the permutation with the minimum dictionary order. For example next permutation of (3,2,1) is (1,2,3).
 

Input
Multi test cases(about 1000). Each case contains two lines. The first line contains two integers n which indicates the length of the permutation and k. The second line contains n integers $a_1, a_2, a_3, \ldots, a_n$ Process to the end of file.
$1 \leq n \leq 2000$
$1 \leq k \leq 10^{12}$
$1 \leq a_i \leq 2000$
 

Output
For each case, output the answer in a single line.
 

Sample Input
3 1 1 2 3 3 1 1 1 2
 

Sample Output
1 3 2 1 2 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-02-17 07:17:17, Gzip enabled