CF1244G.Running in Pairs
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Demonstrative competitions will be held in the run-up to the 20NN Berlatov Olympic Games. Today is the day for the running competition!
Berlatov team consists of 2n runners which are placed on two running tracks; n runners are placed on each track. The runners are numbered from 1 to n on each track. The runner with number i runs through the entire track in i 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 n pairs run through the track.
The organizers want the run to be as long as possible, but if it lasts for more than k 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 k seconds.
Formally, you want to find two permutations p and q (both consisting of n elements) such that sum=i=1∑nmax(pi,qi) is maximum possible, but does not exceed k. If there is no such pair, report about it.
在 20NN 年贝尔拉托夫奥运会开幕前,将举行一系列示范性比赛。今天举行的是田径赛跑项目!
贝尔拉托夫代表队共有 2n 名运动员,被分配在两条跑道上,每条跑道各有 n 名运动员。每条跑道上的运动员编号均为 1 至 n。编号为 i 的运动员跑完整条跑道需 i 秒。
比赛规则如下:首先,两条跑道上的第 1 名运动员同时起跑;当其中较慢者抵达终点时,两条跑道上的第 2 名运动员立即起跑;所有人继续等待,直至该对运动员中较慢者完成跑步;依此类推,直到全部 n 对运动员均完成跑步。
主办方希望整个比赛尽可能持续得久一些,但如果总时长超过 k 秒,观众便会感到乏味。作为该队教练,你可以任意安排每条跑道上运动员的出场顺序(但不能改变每条跑道上的运动员人数,也不能在不同跑道之间交换运动员)。
你需要为每条跑道确定一个运动员出场顺序,使得比赛总时长尽可能长,但不超过 k 秒。
形式化地,你要找出两个长度为 n 的排列 p 和 q,使得 sum=i=1∑nmax(pi,qi) 尽可能大,但满足 sum≤k。若不存在满足条件的排列对,请报告这一点。
输入格式
The first line contains two integers n and k (1≤n≤106,1≤k≤n2) — the number of runners on each track and the maximum possible duration of the competition, respectively.
第一行包含两个整数 n 和 k(1≤n≤106,1≤k≤n2),分别表示每条跑道上的跑步者人数以及比赛可能的最大持续时间。
输出格式
If it is impossible to reorder the runners so that the duration of the competition does not exceed k seconds, print −1.
Otherwise, print three lines. The first line should contain one integer sum — the maximum possible duration of the competition not exceeding k. The second line should contain a permutation of n integers p1,p2,…,pn (1≤pi≤n, all pi 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 n integers q1,q2,…,qn (1≤qi≤n, all qi 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=1∑nmax(pi,qi) should be maximum possible, but should not exceed k. If there are multiple answers, print any of them.
如果无法重新排列选手顺序,使得比赛持续时间不超过 k 秒,则输出 −1。
否则,输出三行。第一行应包含一个整数 sum —— 不超过 k 的比赛最大可能持续时间。第二行应包含 n 个整数的一个排列 p1,p2,…,pn(其中 1≤pi≤n,且所有 pi 两两不同)—— 表示在第一条赛道上参赛的选手编号(按参赛顺序)。第三行应包含 n 个整数的一个排列 q1,q2,…,qn(其中 1≤qi≤n,且所有 qi 两两不同)—— 表示在第二条赛道上参赛的选手编号(按参赛顺序)。要求 sum=i=1∑nmax(pi,qi) 尽可能大,但不得超过 k。若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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], and the order of runners on the second track should be [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=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], and the order of runners on the second track should be [2,1,3]. Then the duration of the competition is 8, and it is the maximum possible duration for n=3.
在第一个例子中,第一条跑道上选手的顺序应为 [5,3,2,1,4],第二条跑道上选手的顺序应为 [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=20,等于允许的最大持续时间。
在第一个例子中,第一条跑道上选手的顺序应为 [2,3,1],第二条跑道上选手的顺序应为 [2,1,3]。此时比赛的持续时间为 8,且这是 n=3 时可能达到的最大持续时间。
输入解题思路,AI测评打分。不知道怎么写?