Find a permutation with minimal set cost

36 Views Asked by At

Given a permutation $P$ of $1,2, \cdots, n$, for each element $i$, we denote its location in $P$ as $l_i$. We define the cost of a set $S \subseteq \{1,\cdots,n\}$ on the permutation $P$ as the maximum distance of the locations of two elements of $S$. Now given some sets, I'd like to ask how to find the permutation such that the total cost of these sets on the permutation is minimal?

For example, the cost of the set $\{2,3,4\}$ on a permutation $7,\color{red}{3},4,6,5,1,\color{red}{2}$ is $7-2=5$.