Given list of increasing pairs, cover as much of it as possible with sublists where the pairs increase at most by one at most on one component

39 Views Asked by At

Given the following list of $m$ pairs of non decreasing numbers,

$$ L = [(a_0,b_0), (a_1,b_1), \dots, (a_i,b_i), (a_j,b_j), \dots, (a_{m-2},b_{m-2}), (a_{m-1},b_{m-1})]\quad \text{with } a_i \leq a_j \wedge b_i \leq b_j, \forall i < j $$ and the set $S = \{ [l_1,u_1], [l_2,u_2], \dots, [l_n,u_n]\}$, with $l_1 = 0$, $u_n = m - 1$, $l_i \leq u_i \forall i \in [1,n]$, and $u_i < l_{i+1} \forall i \in [1,n)$, whose generic element $[l_i, u_i]$ is associated to the sublist $[(a_{l_i},b_{l_i}), \dots, (a_{u_i},b_{u_i})] \subset L$, determine $S$ such that all the following holds:

  1. $(a_i = a_{i + 1} \vee b_i = b_{i + 1}) \wedge a_{i + 1} - a_i \leq 1 \wedge b_{i + 1} - b_i \leq 1 \quad \forall i \in [l_j,u_j) \quad \forall j \in [1, n]$, i.e. from a pair in a sublist to the successive pair in the same sublist an increase of at most 1 is permitted at most on one side of the pair;
  2. $a_{u_i} < a_{l_{i+1}} \wedge b_{u_i} < b_{l_{i + 1}}\quad \forall i \in [1,n)$, i.e. from the last pair of a sublist to the first pair of the following sublist both sides must increase by at least 1;
  3. $C_S = \sum_{i = 1}^n (u_i - l_i + 1)$ is maximum, i.e. the intervals in $S$ should cover as much of $L$ as possible ($C_S$ is the coverage of $L$ provided by $S$).

Notice that it's not required that $l_{i+1} = u_i + 1 \quad \forall i \in [1,n)$, i.e. it's not necessary that the sublists $S$ covers the whole $L$, they just need to cover as much of it as possible (point 3), as long as also points 1 and 2 hold. This should imply that the solution to the problem exists.

The following are a few examples, where I've numbered the pairs for convenience.

  • For the input list $$ L = [(2,3)_0,(3,3)_1,(3,5)_2,(3,6)_3,(4,6)_4] $$ The only solution is $S = \{[0,0],[2,4]\}$ which leaves uncovered only the pair $(3,3)_1$; notice that trying to put $(3,3)_1$ in the same sublist as $(2,3)_0$, would imply that $(3,5)_2$ and $(3,6)_3$ should be given up because they have $(3,\cdot)$ in common with $(3,3)_1$, thus resulting in $\bar{S} = \{[0,1], [4,4]\}$, which is not a solution because it has lower coverage than $S$, i.e. $C_\bar{S} = 3 < 4 = C_S$.

  • On the other hand, the solution is not necessarily unique. For instance, given the list $$ L = [(1,1)_0,(1,2)_1,(2,2)_2,(2,4)_3,(3,4)_4,(3,5)_5] $$ the two solutions $S_1 = \{[0,2],[4,5]\}$ and $S_2 = \{[0,1],[3,5]\}$ are equally valid, as requirements 1 and 2 hold, and the summation in 3 have a value of 5 for both.