CF1244G Running in Pairs

题目描述

找出两个 $1$ 到 $n$ 的全排列 $p$ 和 $q$,使得 $\sum^n_{i=1} \max(p_i,q_i)$ 尽量大且不超过给定的 $k$。

输入格式

输入共一行,包含两个正整数 $n$ 和 $k$。($1\le n\le 10^6$,$1\le k\le n^2$)

输出格式

输出共三行。 第一行,一个整数 $s$,表示 $\sum^n_{i=1} \max(p_i,q_i)$。 第二行和第三行,每行 $n$ 个整数,用空格分隔,代表 $p$ 和 $q$。

说明/提示

In the first example the order of runners on the first track should be $ [5, 3, 2, 1, 4] $ , and the order of runners on the second track should be $ [1, 4, 2, 5, 3] $ . Then the duration of the competition is $ max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20 $ , so it is equal to the maximum allowed duration. In the first example the order of runners on the first track should be $ [2, 3, 1] $ , and the order of runners on the second track should be $ [2, 1, 3] $ . Then the duration of the competition is $ 8 $ , and it is the maximum possible duration for $ n = 3 $ .