Binary inversions
Practice
3.2 (93 votes)
Inversion count
Sorting
Algorithms
Advanced sorting
Problem
95% Success 8184 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Construct an array of size $$n$$ with $$a \leq n$$ 0s and $$b=n-a$$ 1s such that the number of inversions in the array is equal to $$x$$.
Input format
The first and only line of input contains three space-separated integers - $$n$$, $$a$$, and $$x$$.
Output format
Print space-separated lexicographically smallest array that satisfies the constraints. If there is no valid answer, print $$-1$$.
Constraints
$$1 \leq n\leq 10^6$$
$$1 \leq x \leq 10^{12}$$
$$0 \leq a \leq n$$
Note
- A pair $$(i, j)$$ is called an inversion of $$A$$ if $$i < j$$ and $$A_i > A_j$$.
- An array $$A$$ is said to be lexicographically smaller than array $$B$$ if there exists an index $$t$$ such that $$A_i = B_i, \forall i < t$$ and $$A_t < B_t$$.
Submissions
Please login to view your submissions
Similar Problems
Points:20
1 votes
Tags:
AlgorithmsEasySorting
Points:20
173 votes
Tags:
Ad-HocSorting algorithmOpenApprovedEasy
Points:20
Tags:
Ad-HocapprovedEasyApproved
Editorial