CF1283D.Christmas Trees
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n Christmas trees on an infinite number line. The i -th tree grows at the position xi . All xi 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 m people who want to celebrate Christmas. Let y1,y2,…,ym be the positions of people (note that all values x1,x2,…,xn,y1,y2,…,ym should be distinct and all yj should be integer). You want to find such an arrangement of people that the value j=1∑mi=1minn∣xi−yj∣ 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 dj be the distance from the j -th human to the nearest Christmas tree ( dj=i=1minn∣yj−xi∣ ). Then you need to choose such positions y1,y2,…,ym that j=1∑mdj is the minimum possible.
输入格式
The first line of the input contains two integers n and m ( 1≤n,m≤2⋅105 ) — the number of Christmas trees and the number of people.
The second line of the input contains n integers x1,x2,…,xn ( −109≤xi≤109 ), where xi is the position of the i -th Christmas tree. It is guaranteed that all xi are distinct.
输出格式
In the first line print one integer res — the minimum possible value of j=1∑mi=1minn∣xi−yj∣ (in other words, the sum of distances to the nearest Christmas tree for all people).
In the second line print m integers y1,y2,…,ym ( −2⋅109≤yj≤2⋅109 ), where yj is the position of the j -th human. All yj should be distinct and all values x1,x2,…,xn,y1,y2,…,ym 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