Блог пользователя Phantom_Dreams

Автор Phantom_Dreams, история, 7 часов назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 часов назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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})$$$