Phantom_Dreams's blog

By Phantom_Dreams, history, 7 hours ago, In English

I came up with the following problem:

Given an array $$$A$$$ of $$$N$$$ non-negative integers, output $$$2$$$ permutations $$$X$$$ and $$$Y$$$ such that $$$|X_i - Y_i| \ge A_i$$$ for all $$$(1 \le i \le N)$$$ or report that it is impossible to do so.

For example, given this test case:
$$$N = 5$$$
$$$A = [2,2,4,2,2]$$$

The output could be:
$$$X = [5,2,1,3,4]$$$
$$$Y = [3,4,5,1,2]$$$

I have not given constraints on $$$N$$$ as I am not sure what the best possible time complexity of a solution to this problem is.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

oops i misread

$$$|X_{i} - Y_{i}| \ge A_{i}$$$

construct a graph with 2n nodes

for each $$$i$$$, for every $$$u$$$ so that $$$|i - u| \ge A_{i}$$$ -> add an edge from node $$$i$$$ to node $$$n+u$$$

answer is just checking if maximum bipartite matching is $$$n$$$ or not (this can also solve for $$$R_{i} \ge |X_{i} - Y_{i}| \ge L_{i}$$$ as well)

runtime is $$$O(n^{3})$$$