CF1283D.Christmas Trees
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
一条无限长的数轴上有 n 棵圣诞树。第 i 棵树生长在位置 xi 处。所有 xi 互不相同。
每个整数点最多只能被一棵圣诞树、一个人占据,或完全空置;非整数点不能被任何东西占据。
有 m 个人希望庆祝圣诞节。设 y1,y2,…,ym 表示这些人的位置(注意:所有值 x1,x2,…,xn,y1,y2,…,ym 必须互不相同,且所有 yj 均为整数)。你需要找出一种人员位置安排方案,使得 j=1∑mi=1minn∣xi−yj∣ 达到最小可能值(即:所有人到其最近的圣诞树的距离之和最小)。
换言之,令 dj 表示第 j 个人到其最近的圣诞树的距离(即 dj=i=1minn∣yj−xi∣)。那么你需要选择位置 y1,y2,…,ym,使得 j=1∑mdj 最小。
输入格式
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.
输入的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105)—— 分别表示圣诞树的数量和人数。
输入的第二行包含 n 个整数 x1,x2,…,xn(−109≤xi≤109),其中 xi 表示第 i 棵圣诞树的位置。保证所有 xi 互不相同。
输出格式
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.
第一行输出一个整数 res —— j=1∑mi=1minn∣xi−yj∣ 的最小可能值(即所有人到最近的圣诞树的距离之和)。
第二行输出 m 个整数 y1,y2,…,ym(满足 −2⋅109≤yj≤2⋅109),其中 yj 表示第 j 个人的位置。所有 yj 必须互不相同,且所有值 x1,x2,…,xn,y1,y2,…,ym 也必须互不相同。
若存在多个答案,输出任意一个即可。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?