CF1283D.Christmas Trees

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn Christmas trees on an infinite number line. The ii -th tree grows at the position xix_i . All xix_i are guaranteed to be distinct.

Each integer point can be either occupied by the Christmas tree, by the human or not occupied at all. Non-integer points cannot be occupied by anything.

There are mm people who want to celebrate Christmas. Let y1,y2,,ymy_1, y_2, \dots, y_m be the positions of people (note that all values x1,x2,,xn,y1,y2,,ymx_1, x_2, \dots, x_n, y_1, y_2, \dots, y_m should be distinct and all yjy_j should be integer). You want to find such an arrangement of people that the value j=1mmini=1nxiyj\sum\limits_{j=1}^{m}\min\limits_{i=1}^{n}|x_i - y_j| is the minimum possible (in other words, the sum of distances to the nearest Christmas tree for all people should be minimized).

In other words, let djd_j be the distance from the jj -th human to the nearest Christmas tree ( dj=mini=1nyjxid_j = \min\limits_{i=1}^{n} |y_j - x_i| ). Then you need to choose such positions y1,y2,,ymy_1, y_2, \dots, y_m that j=1mdj\sum\limits_{j=1}^{m} d_j is the minimum possible.

输入格式

The first line of the input contains two integers nn and mm ( 1n,m21051 \le n, m \le 2 \cdot 10^5 ) — the number of Christmas trees and the number of people.

The second line of the input contains nn integers x1,x2,,xnx_1, x_2, \dots, x_n ( 109xi109-10^9 \le x_i \le 10^9 ), where xix_i is the position of the ii -th Christmas tree. It is guaranteed that all xix_i are distinct.

输出格式

In the first line print one integer resres — the minimum possible value of j=1mmini=1nxiyj\sum\limits_{j=1}^{m}\min\limits_{i=1}^{n}|x_i - y_j| (in other words, the sum of distances to the nearest Christmas tree for all people).

In the second line print mm integers y1,y2,,ymy_1, y_2, \dots, y_m ( 2109yj2109-2 \cdot 10^9 \le y_j \le 2 \cdot 10^9 ), where yjy_j is the position of the jj -th human. All yjy_j should be distinct and all values x1,x2,,xn,y1,y2,,ymx_1, x_2, \dots, x_n, y_1, y_2, \dots, y_m should be distinct.

If there are multiple answers, print any of them.

输入输出样例

  • 输入#1

    2 6
    1 5
    

    输出#1

    8
    -1 2 6 4 0 3 
    
  • 输入#2

    3 5
    0 3 1
    

    输出#2

    7
    5 -2 4 -1 2 
    
首页