#P2528. Permutation Inversions
Permutation Inversions
Permutation Inversions
Given a sequence of distinct items with parameters , an inversion pair is defined as a pair such that and . In other words, the inversion count of a permutation is
$$I(A)=\#\{(i,j)\mid 1\le iGrant, a sorter at SORT company, is interested in two things given two integers and :
- How many permutations of the numbers have exactly inversions?
- What is the lexicographically smallest permutation among those with exactly inversions?
A permutation is considered lexicographically smaller than if there exists an index such that and .
It is guaranteed that .
inputFormat
The input consists of a single line containing two integers and , separated by a space.
outputFormat
Output two lines:
- The first line contains a single integer representing the total number of permutations of with exactly inversions.
- The second line contains the lexicographically smallest permutation (as space-separated integers) among those with exactly inversions.
sample
3 0
1
1 2 3
</p>