CF238B Boring Partition

题目描述

你可以把 $n$ 个元素划分到两个序列里。 对于任意两个的元素 $a_i$ 和 $a_j$($i \ne j$),如果它们在一个序列中,$f(i, \ j) = a_i + a_j$,如果它们在不同序列中,$f(i, \ j) = a_i + a_j + h$,其中 $h$ 是一个给定的参数。 一种划分方式的优美度定义为最大的 $f(i, \ j)$ 与最小的 $f(i, \ j)$ 的差值。 求优美度最小的方案。

输入格式

第一行:两个整数 $n$ 和 $h$。 第二行:$n$ 个整数,第 $i$ 个整数为 $a_i$。

输出格式

两行。 第一行为最小优美度。 第二行为划分方式。第 $i$ 个数表示 $a_i$ 被划分到了哪个序列中。

说明/提示

In the first sample the values of $ f $ are as follows: $ f(1,2)=1+2+2=5 $ , $ f(1,3)=1+3+2=6 $ and $ f(2,3)=2+3=5 $ . So the difference between maximum and minimum values of $ f $ is $ 1 $ . In the second sample the value of $ h $ is large, so it's better for one of the sub-sequences to be empty.