CF1244G.Running in Pairs

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Demonstrative competitions will be held in the run-up to the 20NN20NN Berlatov Olympic Games. Today is the day for the running competition!

Berlatov team consists of 2n2n runners which are placed on two running tracks; nn runners are placed on each track. The runners are numbered from 11 to nn on each track. The runner with number ii runs through the entire track in ii seconds.

The competition is held as follows: first runners on both tracks start running at the same time; when the slower of them arrives at the end of the track, second runners on both tracks start running, and everyone waits until the slower of them finishes running, and so on, until all nn pairs run through the track.

The organizers want the run to be as long as possible, but if it lasts for more than kk seconds, the crowd will get bored. As the coach of the team, you may choose any order in which the runners are arranged on each track (but you can't change the number of runners on each track or swap runners between different tracks).

You have to choose the order of runners on each track so that the duration of the competition is as long as possible, but does not exceed kk seconds.

Formally, you want to find two permutations pp and qq (both consisting of nn elements) such that sum=∑i=1nmax(pi,qi)sum = \sum\limits_{i=1}^{n} max(p_i, q_i) is maximum possible, but does not exceed kk. If there is no such pair, report about it.

在 20NN20NN 年贝尔拉托夫奥运会开幕前,将举行一系列示范性比赛。今天举行的是田径赛跑项目!

贝尔拉托夫代表队共有 2n2n 名运动员,被分配在两条跑道上,每条跑道各有 nn 名运动员。每条跑道上的运动员编号均为 11 至 nn。编号为 ii 的运动员跑完整条跑道需 ii 秒。

比赛规则如下:首先,两条跑道上的第 1 名运动员同时起跑;当其中较慢者抵达终点时,两条跑道上的第 2 名运动员立即起跑;所有人继续等待,直至该对运动员中较慢者完成跑步;依此类推,直到全部 nn 对运动员均完成跑步。

主办方希望整个比赛尽可能持续得久一些,但如果总时长超过 kk 秒,观众便会感到乏味。作为该队教练,你可以任意安排每条跑道上运动员的出场顺序(但不能改变每条跑道上的运动员人数,也不能在不同跑道之间交换运动员)。

你需要为每条跑道确定一个运动员出场顺序,使得比赛总时长尽可能长,但不超过 kk 秒。

形式化地,你要找出两个长度为 nn 的排列 pp 和 qq,使得 sum=∑i=1nmax⁡(pi,qi)sum = \sum\limits_{i=1}^{n} \max(p_i, q_i) 尽可能大,但满足 sum≤ksum \leq k。若不存在满足条件的排列对,请报告这一点。

输入格式

The first line contains two integers nn and kk (1≤n≤106,1≤k≤n21 \le n \le 10^6, 1 \le k \le n^2) — the number of runners on each track and the maximum possible duration of the competition, respectively.

第一行包含两个整数 nn 和 kk(1≤n≤1061 \le n \le 10^6,1≤k≤n21 \le k \le n^2),分别表示每条跑道上的跑步者人数以及比赛可能的最大持续时间。

输出格式

If it is impossible to reorder the runners so that the duration of the competition does not exceed kk seconds, print −1-1.

Otherwise, print three lines. The first line should contain one integer sumsum — the maximum possible duration of the competition not exceeding kk. The second line should contain a permutation of nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤n1 \le p_i \le n, all pip_i should be pairwise distinct) — the numbers of runners on the first track in the order they participate in the competition. The third line should contain a permutation of nn integers q1,q2,…,qnq_1, q_2, \dots, q_n (1≤qi≤n1 \le q_i \le n, all qiq_i should be pairwise distinct) — the numbers of runners on the second track in the order they participate in the competition. The value of sum=∑i=1nmax(pi,qi)sum = \sum\limits_{i=1}^{n} max(p_i, q_i) should be maximum possible, but should not exceed kk. If there are multiple answers, print any of them.

如果无法重新排列选手顺序,使得比赛持续时间不超过 kk 秒,则输出 −1-1。

否则,输出三行。第一行应包含一个整数 sumsum —— 不超过 kk 的比赛最大可能持续时间。第二行应包含 nn 个整数的一个排列 p1,p2,…,pnp_1, p_2, \dots, p_n(其中 1≤pi≤n1 \le p_i \le n,且所有 pip_i 两两不同)—— 表示在第一条赛道上参赛的选手编号(按参赛顺序)。第三行应包含 nn 个整数的一个排列 q1,q2,…,qnq_1, q_2, \dots, q_n(其中 1≤qi≤n1 \le q_i \le n,且所有 qiq_i 两两不同)—— 表示在第二条赛道上参赛的选手编号(按参赛顺序)。要求 sum=∑i=1nmax⁡(pi,qi)sum = \sum\limits_{i=1}^{n} \max(p_i, q_i) 尽可能大,但不得超过 kk。若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    5 20

    输出#1

    20
    1 2 3 4 5 
    5 2 4 3 1
  • 输入#2

    3 9

    输出#2

    8
    1 2 3 
    3 2 1
  • 输入#3

    10 54

    输出#3

    -1

说明/提示

In the first example the order of runners on the first track should be [5,3,2,1,4][5, 3, 2, 1, 4], and the order of runners on the second track should be [1,4,2,5,3][1, 4, 2, 5, 3]. Then the duration of the competition is max(5,1)+max(3,4)+max(2,2)+max(1,5)+max(4,3)=5+4+2+5+4=20max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20, so it is equal to the maximum allowed duration.

In the first example the order of runners on the first track should be [2,3,1][2, 3, 1], and the order of runners on the second track should be [2,1,3][2, 1, 3]. Then the duration of the competition is 88, and it is the maximum possible duration for n=3n = 3.

在第一个例子中,第一条跑道上选手的顺序应为 [5,3,2,1,4][5, 3, 2, 1, 4],第二条跑道上选手的顺序应为 [1,4,2,5,3][1, 4, 2, 5, 3]。此时比赛的持续时间为 max(5,1)+max(3,4)+max(2,2)+max(1,5)+max(4,3)=5+4+2+5+4=20max(5, 1) + max(3, 4) + max(2, 2) + max(1, 5) + max(4, 3) = 5 + 4 + 2 + 5 + 4 = 20,等于允许的最大持续时间。

在第一个例子中,第一条跑道上选手的顺序应为 [2,3,1][2, 3, 1],第二条跑道上选手的顺序应为 [2,1,3][2, 1, 3]。此时比赛的持续时间为 88,且这是 n=3n = 3 时可能达到的最大持续时间。

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

首页