UOJ

#define stone int
#define stones std::vector<stone>
stones merge(stones A, stones B)
{
stones C;
while (A.size() && B.size())
if (A[0] <= B[0])
C.push_back(A[0]), A.erase(A.begin());
else
C.push_back(B[0]), B.erase(B.begin());
while(A.size())
C.push_back(A[0]), A.erase(A.begin());
while(B.size())
C.push_back(B[0]), B.erase(B.begin());
return C;
}

样例一

input

3 8 0
1 3 4 2 5 2 7 8



output

540



样例二

input

4 8 0
2 4 1 4 1 2 3 2



output

0



M 蚤的小提示

\begin{aligned} &\mathop{\bf function}\textrm{merge}(\mathop{\bf stones}A,\mathop{\bf stones}B)\\ &\quad\mathop{\bf stones}C\leftarrow\varnothing\\ &\quad\mathop{\bf while}A\neq\varnothing\land B\neq\varnothing\\ &\quad\quad x\leftarrow\textrm{the first stone of }A\\ &\quad\quad y\leftarrow\textrm{the first stone of }B\\ &\quad\quad\mathop{\bf if}x\le y\\ &\quad\quad\quad C\textrm{ push back }x\\ &\quad\quad\quad\textrm{pop the front of }A\\ &\quad\quad\mathop{\bf else}\\ &\quad\quad\quad C\textrm{ push back }y\\ &\quad\quad\quad\textrm{pop the front of }B\\ &\quad\quad\mathop{\bf fi}\\ &\quad\mathop{\bf end}\mathop{\bf while}\\ &\quad\mathop{\bf while}A\neq\varnothing\\ &\quad\quad x\leftarrow\textrm{the first stone of }A\\ &\quad\quad C\textrm{ push back }x\\ &\quad\quad\textrm{pop the front of }A\\ &\quad\mathop{\bf end}\mathop{\bf while}\\ &\quad\mathop{\bf while}B\neq\varnothing\\ &\quad\quad x\leftarrow\textrm{the first stone of }B\\ &\quad\quad C\textrm{ push back }x\\ &\quad\quad\textrm{pop the front of }B\\ &\quad\mathop{\bf end}\mathop{\bf while}\\ &\quad\mathop{\bf return}C\\ &\mathop{\bf end}\mathop{\bf function} \end{aligned}

数据范围

$1$ $\le4$ $\le8$ $=0$ $5$
$2$ $=2$ $\le20$ $=0$ $5$
$3$ $\le100$ $\le300$ $=1$ $10$
$4$ $\le100$ $\le300$ $=0$ $10$ $1,2,3$
$5$ $\le1000$ $\le3000$ $=1$ $10$ $3$
$6$ $\le1000$ $\le3000$ $=0$ $10$ $4,5$
$7$ $\le2\times10^5$ $\le5\times10^5$ $=5$ $10$
$8$ $\le2\times10^5$ $\le5\times10^5$ $=4$ $5$ $7$
$9$ $\le2\times10^5$ $\le5\times10^5$ $=3$ $10$
$10$ $\le2\times10^5$ $\le5\times10^5$ $=2$ $5$ $1,2,9$
$11$ $\le2\times10^5$ $\le5\times10^5$ $=1$ $10$ $5,7,9$
$12$ $\le2\times10^5$ $\le5\times10^5$ $=0$ $10$ $6,8,10,11$

• 当 $o\in\{1,3,5\}$ 时，保证 $\forall1\le i< m,a_i\le a_{i+1}$。
• 当 $2\le o\le3$ 时，保证 $\forall1\le i< m,a_i\le20$。
• 当 $4\le o\le5$ 时，保证每种编号出现次数均不超过 $5$ 次。