CF187E.Heaven Tour

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The story was not finished as PMP thought. God offered him one more chance to reincarnate and come back to life. But before he can come back, God told him that PMP should ask n great men including prominent programmers about their life experiences.

The men are standing on a straight line. They are numbered 1 through n from left to right. The coordinate of the i-th man is x__i (x__i < x__i + 1, i < n). PMP should visit all these people one by one in arbitrary order. Each men should be visited exactly once. At the beginning of his tour, he starts at location of s-th man and asks him about his experiences.

Each time PMP wants to change his location, he should give a ticket to an angel and the angel carries him to his destination. Angels take PMP from one location, fly to his destination and put him down there. Nobody else is visited in this movement. Moving from i-th man to j-th man, takes |x__i - x__j| time. PMP can get back to life as soon as he visits all men.

There are two types of angels: Some angels are going to the right and they only accept right tickets. Others are going the left and they only accept left tickets. There are an unlimited number of angels of each type. PMP has l left tickets and n - 1 - l right tickets.

PMP wants to get back to life as soon as possible to be able to compete in this year's final instead of the final he missed last year. He wants to know the quickest way to visit all the men exactly once. He also needs to know the exact sequence moves he should make.

故事并未如PMP所想的那样结束。上帝给了他一次重生并重返人间的机会。但在他能够回归之前,上帝告诉他:PMP必须依次向 n 位伟人(其中包括著名程序员)请教他们的人生经历。

这些伟人站在一条直线上,从左到右依次编号为 1 至 n。第 i 位伟人的坐标为 x__i(满足 x__i < x__i + 1,其中 i < n)。PMP 必须以任意顺序逐一拜访这 n 个人,且每人恰好被拜访一次。旅程开始时,他位于第 s 位伟人的位置,并首先向此人请教其人生经历。

每次 PMP 想要变换位置时,都必须向一位天使出示一张车票,由该天使将他运送至目的地。天使会从当前所在位置接走 PMP,飞抵目标位置后将其放下;此过程中不会顺路拜访其他人。从第 i 位伟人处移动到第 j 位伟人处所需时间为 |x__i - x__j|。当 PMP 完成对所有伟人的拜访后,即可立即重返生命。

天使分为两类:一类只向右飞行,仅接受“右票”;另一类只向左飞行,仅接受“左票”。每类天使的数量均无限。PMP 手中持有 l 张左票和 n - 1 - l 张右票。

PMP 希望尽快重返生命,以便能参加今年的总决赛,而非去年错失的那场总决赛。他想知道拜访所有伟人(每人恰好一次)的最短耗时方案,并需明确自己应执行的具体移动序列。

输入格式

The first line of input contains three space-separated integers n, l, s (2 ≤ n ≤ 105, 0 ≤ l < n, 1 ≤ s ≤ n) — the number of people to visit, the number left tickets PMP got, and initial location of PMP. Next line contains n space-separated integers. The i-th integer in this line is x__i (0 = _x_1 < _x_2 < ... < x__n ≤ 109) — the location of i-th man.

输入的第一行包含三个用空格分隔的整数 nn、ll、ss(2 ≤ n ≤ 1052 \leq n \leq 10^5,0 ≤ l < n0 \leq l < n,1 ≤ s ≤ n1 \leq s \leq n)——分别表示需要拜访的人数、PMP 剩余的车票数量,以及 PMP 的初始位置。
第二行包含 nn 个用空格分隔的整数。该行中第 ii 个整数为 xix_i(满足 0 = x1 < x2 < … < xn ≤ 1090 = x_1 < x_2 < \ldots < x_n \leq 10^9)——表示第 ii 个人所在的位置。

输出格式

If PMP cannot visit all men with the tickets he got print -1 in the only line of output. Otherwise, in the first line you should print the minimum time PMP can visit all men. In the second line you should print n - 1 integers that are the numbers of the men that PMP should visit in order in one optimal solution. If there are multiple answers, output any of them.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

如果 PMP 无法使用他获得的车票访问所有男性,则在输出的唯一一行中打印 -1。否则,在第一行中打印 PMP 访问所有男性的最短时间;在第二行中打印 n−1n-1 个整数,表示在某个最优解中 PMP 应依次访问的男性编号。若存在多个答案,输出任意一个即可。

请注意:在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流或 %I64d 说明符。

输入输出样例

  • 输入#1

    5 2 2
    0 10 11 21 22

    输出#1

    33
    1 3 5 4
  • 输入#2

    4 3 1
    0 1 2 3

    输出#2

    -1
  • 输入#3

    7 3 2
    0 100 200 201 301 303 305

    输出#3

    409
    1 3 4 7 6 5

说明/提示

Let us remind here, a great contestant of all times, who left us about a year ago. May Renat Mullakhanov rest in peace.

让我们在此缅怀一位有史以来最杰出的竞赛选手,他于大约一年前离我们而去。愿列纳特·穆拉赫诺夫安息。

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

首页