CF371E.Subway Innovation

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter!

The President of Berland was forced to leave only k of the currently existing n subway stations.

The subway stations are located on a straight line one after another, the trains consecutively visit the stations as they move. You can assume that the stations are on the Ox axis, the i-th station is at point with coordinate x__i. In such case the distance between stations i and j is calculated by a simple formula |x__i - x__j|.

Currently, the Ministry of Transport is choosing which stations to close and which ones to leave. Obviously, the residents of the capital won't be too enthusiastic about the innovation, so it was decided to show the best side to the people. The Ministry of Transport wants to choose such k stations that minimize the average commute time in the subway!

Assuming that the train speed is constant (it is a fixed value), the average commute time in the subway is calculated as the sum of pairwise distances between stations, divided by the number of pairs (that is ) and divided by the speed of the train.

Help the Minister of Transport to solve this difficult problem. Write a program that, given the location of the stations selects such k stations that the average commute time in the subway is minimized.

伯兰德正经历艰难时期——泥土价格暴跌,这对该国经济造成了沉重打击。众所周知,伯兰德是全球首屈一指的泥土出口国!

伯兰德总统被迫仅保留当前存在的 nn 个地铁站中的 kk 个。

这些地铁站位于一条直线上,依次排开;列车运行时按顺序依次停靠各站。可将这些车站视为位于 OxOx 轴上,第 ii 个车站的坐标为 xix_i。此时,车站 ii 与车站 jj 之间的距离由简单公式 ∣xi−xj∣|x_i - x_j| 给出。

目前,交通运输部正在决定关闭哪些车站、保留哪些车站。显然,首都居民对这项“创新”不会太热情,因此政府决定向民众展现最积极的一面。交通运输部希望选出 kk 个车站,使得地铁系统的平均通勤时间最小!

假设列车速度恒定(为某一固定值),则地铁系统的平均通勤时间定义为:所有车站两两之间距离之和,除以两两组合的对数(即 k(k−1)2\frac{k(k-1)}{2}),再除以列车速度。

请帮助交通运输部部长解决这一难题:编写一个程序,在给定各车站位置的前提下,选出 kk 个车站,使得地铁系统的平均通勤时间最小。

输入格式

The first line of the input contains integer n (3 ≤ n ≤ 3·105) — the number of the stations before the innovation. The second line contains the coordinates of the stations _x_1, _x_2, ..., x__n ( - 108 ≤ x__i ≤ 108). The third line contains integer k (2 ≤ k ≤ n - 1) — the number of stations after the innovation.

The station coordinates are distinct and not necessarily sorted.

输入的第一行包含一个整数 $ n (( 3 \leq n \leq 3 \cdot 10^5 $)—— 创新前的车站数量。
第二行包含车站的坐标 $ x_1,,x_2,,\ldots,,x_n (( -10^8 \leq x_i \leq 10^8 $)。
第三行包含一个整数 $ k (( 2 \leq k \leq n-1 $)—— 创新后的车站数量。

车站坐标互不相同,且不一定有序。

输出格式

Print a sequence of k distinct integers _t_1, _t_2, ..., t__k (1 ≤ t__j ≤ n) — the numbers of the stations that should be left after the innovation in arbitrary order. Assume that the stations are numbered 1 through n in the order they are given in the input. The number of stations you print must have the minimum possible average commute time among all possible ways to choose k stations. If there are multiple such ways, you are allowed to print any of them.

输出一个由 kk 个互不相同的整数 t1, t2, ..., tkt_1,\,t_2,\,...,\,t_k(其中 1≤tj≤n1\le t_j \le n)组成的序列——即创新后应保留的车站编号,顺序任意。假设输入中给出的车站按顺序编号为 11 至 nn。你所输出的车站数量必须使得所有可能的 kk 个车站选择方案中,其平均通勤时间最小。若存在多种满足条件的方案,任选其一输出即可。

输入输出样例

  • 输入#1

    3
    1 100 101
    2

    输出#1

    2 3

说明/提示

In the sample testcase the optimal answer is to destroy the first station (with x = 1). The average commute time will be equal to 1 in this way.

在样例测试用例中,最优方案是摧毁第一个车站(其坐标为 x=1x = 1)。此时平均通勤时间为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页