CF732E.Sockets

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.

There are n computers for participants, the i-th of which has power equal to positive integer p__i. At the same time there are m sockets available, the j-th of which has power euqal to positive integer s__j. It is possible to connect the i-th computer to the j-th socket if and only if their powers are the same: p__i = s__j. It is allowed to connect no more than one computer to one socket. Thus, if the powers of all computers and sockets are distinct, then no computer can be connected to any of the sockets.

In order to fix the situation professor Puch Williams urgently ordered a wagon of adapters — power splitters. Each adapter has one plug and one socket with a voltage divider between them. After plugging an adapter to a socket with power x, the power on the adapter's socket becomes equal to , it means that it is equal to the socket's power divided by two with rounding up, for example and .

Each adapter can be used only once. It is possible to connect several adapters in a chain plugging the first to a socket. For example, if two adapters are plugged one after enother to a socket with power 10, it becomes possible to connect one computer with power 3 to this socket.

The organizers should install adapters so that it will be possible to supply with electricity the maximum number of computers c at the same time. If there are several possible connection configurations, they want to find the one that uses the minimum number of adapters u to connect c computers.

Help organizers calculate the maximum number of connected computers c and the minimum number of adapters u needed for this.

The wagon of adapters contains enough of them to do the task. It is guaranteed that it's possible to connect at least one computer.

ICM ACPC 世界总决赛即将来临!不幸的是,本次比赛的组织者忙于准备题目,完全忽略了一个重要的技术问题——为所有参赛选手的工作站提供电力保障。

共有 nn 台参赛用计算机,其中第 ii 台的额定功率为正整数 pip_i;同时有 mm 个可用插座,其中第 jj 个插座的额定功率为正整数 sjs_j。当且仅当两者的功率相等(即 pi=sjp_i = s_j)时,才允许将第 ii 台计算机连接至第 jj 个插座。每个插座最多只能连接一台计算机。因此,若所有计算机与所有插座的功率互不相同,则无法将任何一台计算机连接至任意插座。

为解决这一问题,Puch Williams 教授紧急订购了一车适配器——即电源分压器。每个适配器具有一个插头和一个插座,二者之间连接有一个电压分压电路。当将一个适配器插入额定功率为 xx 的插座后,该适配器插座端输出的功率变为 ,即等于原插座功率除以 2 后向上取整。例如:,以及 。

每个适配器仅能使用一次。允许多个适配器串联使用:即先将第一个适配器插入某个插座,再将第二个适配器插入第一个适配器的输出插座,依此类推。例如,若将两个适配器依次接入一个额定功率为 10 的插座,则可使一台额定功率为 3 的计算机成功连接至该插座。

主办方需安装适配器,使得在任一时刻能够供电的计算机数量 cc 达到最大。若存在多种方案均可实现最大连接数 cc,则主办方希望从中选出所用适配器总数 uu 最小的一种方案。

请帮助主办方计算最大可连接计算机数 cc,以及实现该最大连接数所需的最小适配器数 uu。

该车适配器数量充足,足以完成任务。题目保证至少可以连接一台计算机。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of computers and the number of sockets.

The second line contains n integers _p_1, _p_2, ..., p__n (1 ≤ p__i ≤ 109) — the powers of the computers.

The third line contains m integers _s_1, _s_2, ..., s__m (1 ≤ s__i ≤ 109) — the power of the sockets.

第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 200 0001 ≤ n, m ≤ 200\,000)—— 分别表示计算机的数量和插座的数量。

第二行包含 nn 个整数 p1, p2, ..., pnp_1, p_2, ..., p_n(1 ≤ pi ≤ 1091 ≤ p_i ≤ 10^9)—— 表示各台计算机的功率。

第三行包含 mm 个整数 s1, s2, ..., sms_1, s_2, ..., s_m(1 ≤ si ≤ 1091 ≤ s_i ≤ 10^9)—— 表示各插座的功率。

输出格式

In the first line print two numbers c and u — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect c computers.

In the second line print m integers _a_1, _a_2, ..., a__m (0 ≤ a__i ≤ 109), where a__i equals the number of adapters orginizers need to plug into the i-th socket. The sum of all a__i should be equal to u.

In third line print n integers _b_1, _b_2, ..., b__n (0 ≤ b__i ≤ m), where the b__j-th equals the number of the socket which the j-th computer should be connected to. b__j = 0 means that the j-th computer should not be connected to any socket. All b__j that are different from 0 should be distinct. The power of the j-th computer should be equal to the power of the socket b__j after plugging in a__b__j adapters. The number of non-zero b__j should be equal to c.

If there are multiple answers, print any of them.

第一行输出两个数 cc 和 uu —— 分别表示最多可同时接入电源的计算机数量,以及为接入这 cc 台计算机所需的最少适配器总数。

第二行输出 mm 个整数 a1, a2, …, ama_1,\,a_2,\,\dots,\,a_m(满足 0≤ai≤1090\le a_i\le 10^9),其中 aia_i 表示需插入第 ii 个插座的适配器数量。所有 aia_i 的总和应等于 uu。

第三行输出 nn 个整数 b1, b2, …, bnb_1,\,b_2,\,\dots,\,b_n(满足 0≤bi≤m0\le b_i\le m),其中 bjb_j 表示第 jj 台计算机应连接的插座编号;若 bj=0b_j = 0,则表示第 jj 台计算机不连接任何插座。所有非零的 bjb_j 必须互不相同。第 jj 台计算机的供电能力必须等于在插座 bjb_j 上插入 abja_{b_j} 个适配器后的实际供电能力。非零的 bjb_j 的个数应恰好等于 cc。

若存在多个合法解,输出任意一个即可。

输入输出样例

  • 输入#1

    2 2
    1 1
    2 2

    输出#1

    2 2
    1 1
    1 2
  • 输入#2

    2 1
    2 100
    99

    输出#2

    1 6
    6
    1 0

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

首页