Solution (source code)

= Solution

The <transport cost> separates into a <function> of $y$ and a <function> of $x$, so for every <transport plan>
$$
\int(y-x)\,d\pi=\int_1^2 y\,d\nu(y)-\int_0^1 x\,d\mu(x).
$$
The value is fixed by the marginals. Hence \b[every <transport map> from $\mu$ to $\nu$ is optimal], and indeed every coupling is optimal.

For an explicit description of the complete set, let $F(x)=\int_0^x f(s)\,ds$ and $G(y)=\int_1^y g(s)\,ds$. Their strictly positive continuous densities make $F:[0,1]\to[0,1]$ and $G:[1,2]\to[0,1]$ increasing homeomorphisms. The full family of deterministic plans is
$$
\boxed{\pi_T=(\operatorname{Id},T)_*\mu,\qquad
T=G^{-1}\circ S\circ F\quad\mu\text{-almost everywhere},}
$$
where $S:[0,1]\to[0,1]$ is any measurable <Lebesgue-measure-preserving map>. Indeed $F_*\mu$ is uniform <measure> and $G_*\nu$ is uniform <measure>, so any such $S$ produces the required pushforward. Conversely, for any <transport map> $T$, the map $S=G\circ T\circ F^{-1}$ preserves uniform <measure>. This is the <measure-preserving parametrization of one-dimensional transport maps>; no monotonicity is required for the linear cost.