
ZOJ Problem Set  2425
The inversion number of an integer sequence a_{1}, a_{2}, ... , a_{n} is the number of pairs (a_{i}, a_{j}) that satisfy i < j and a_{i} > a_{j}. Given n and the inversion number m, your task is to find the smallest permutation of the set { 1, 2, ... , n }, whose inversion number is exactly m. A permutation a_{1}, a_{2}, ... , a_{n} is smaller than b_{1}, b_{2}, ... , b_{n} if and only if there exists an integer k such that a_{j} = b_{j} for 1 <= j < k but a_{k} < b_{k}. Input The input consists of several test cases. Each line of the input contains two integers n and m. Both of the integers at the last line of the input is 1, which should not be processed. You may assume that 1 <= n <= 50000 and 0 <= m <= 1/2*n*(n1). Output For each test case, print a line containing the smallest permutation as described above, separates the numbers by single spaces. Don't output any trailing spaces at the end of each line, or you may get an 'Presentation Error'! Sample Input
5 9 Sample Output
4 5 3 2 1 Source: Asia 2004, Shanghai (Mainland China), Preliminary 