CF1814C.Search in Parallel

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Suppose you have nn boxes. The ii-th box contains infinitely many balls of color ii. Sometimes you need to get a ball with some specific color; but you're too lazy to do it yourself.

You have bought two robots to retrieve the balls for you. Now you have to program them. In order to program the robots, you have to construct two lists [a1,a2,…,ak][a_1, a_2, \dots, a_k] and [b1,b2,…,bn−k][b_1, b_2, \dots, b_{n-k}], where the list aa represents the boxes assigned to the first robot, and the list bb represents the boxes assigned to the second robot. Every integer from 11 to nn must be present in exactly one of these lists.

When you request a ball with color xx, the robots work as follows. Each robot looks through the boxes that were assigned to that robot, in the order they appear in the list. The first robot spends s1s_1 seconds analyzing the contents of a box; the second robot spends s2s_2. As soon as one of the robots finds the box with balls of color xx (and analyzes its contents), the search ends. The search time is the number of seconds from the beginning of the search until one of the robots finishes analyzing the contents of the xx-th box. If a robot analyzes the contents of all boxes assigned to it, it stops searching.

For example, suppose s1=2s_1 = 2, s2=3s_2 = 3, a=[4,1,5,3,7]a = [4, 1, 5, 3, 7], b=[2,6]b = [2, 6]. If you request a ball with color 33, the following happens:

  • initially, the first robot starts analyzing the box 44, and the second robot starts analyzing the box 22;
  • at the end of the 22-nd second, the first robot finishes analyzing the box 44. It is not the box you need, so the robot continues with the box 11;
  • at the end of the 33-rd second, the second robot finishes analyzing the box 22. It is not the box you need, so the robot continues with the box 66;
  • at the end of the 44-th second, the first robot finishes analyzing the box 11. It is not the box you need, so the robot continues with the box 55;
  • at the end of the 66-th second, the first robot finishes analyzing the box 55. It is not the box you need, so the robot continues with the box 33. At the same time, the second robot finishes analyzing the box 66. It is not the box you need, and the second robot has analyzed all the boxes in its list, so that robot stops searching;
  • at the end of the 88-th second, the first robot finishes analyzing the box 33. It is the box you need, so the search ends;
  • so, the search time is 88 seconds.

You know that you are going to request a ball of color 11 r1r_1 times, a ball of color 22 r2r_2 times, and so on. You want to construct the lists aa and bb for the robots in such a way that the total search time over all requests is the minimum possible.

假设你有 nn 个盒子。第 ii 个盒子中装有无限多个颜色为 ii 的球。有时你需要获取某种特定颜色的球,但你懒得自己动手。

你购买了两个机器人来帮你取球。现在你需要对它们进行编程。为了编程,你需要构造两个列表 [a1,a2,…,ak][a_1, a_2, \dots, a_k] 和 [b1,b2,…,bn−k][b_1, b_2, \dots, b_{n-k}],其中列表 aa 表示分配给第一个机器人的盒子,列表 bb 表示分配给第二个机器人的盒子。11 到 nn 中的每个整数必须且仅能出现在这两个列表之一中。

当你请求一个颜色为 xx 的球时,机器人按如下方式工作:每个机器人依次检查分配给它的盒子(按列表中出现的顺序)。第一个机器人分析一个盒子的内容需花费 s1s_1 秒;第二个机器人则需 s2s_2 秒。一旦某个机器人找到装有颜色为 xx 的球的盒子(并完成对其内容的分析),搜索即终止。搜索时间定义为从搜索开始到任一机器人完成对第 xx 个盒子内容分析所经历的秒数。若某机器人已分析完分配给它的所有盒子,则停止搜索。

例如,设 s1=2s_1 = 2、s2=3s_2 = 3、a=[4,1,5,3,7]a = [4, 1, 5, 3, 7]、b=[2,6]b = [2, 6]。当你请求一个颜色为 33 的球时,过程如下:

  • 初始时刻,第一个机器人开始分析盒子 44,第二个机器人开始分析盒子 22;
  • 第 22 秒末,第一个机器人完成对盒子 44 的分析。这不是你需要的盒子,因此该机器人继续分析下一个盒子 11;
  • 第 33 秒末,第二个机器人完成对盒子 22 的分析。这不是你需要的盒子,因此该机器人继续分析下一个盒子 66;
  • 第 44 秒末,第一个机器人完成对盒子 11 的分析。这不是你需要的盒子,因此该机器人继续分析下一个盒子 55;
  • 第 66 秒末,第一个机器人完成对盒子 55 的分析。这不是你需要的盒子,因此该机器人继续分析下一个盒子 33;与此同时,第二个机器人也完成对盒子 66 的分析。这同样不是你需要的盒子,且第二个机器人已分析完其列表中的全部盒子,因此该机器人停止搜索;
  • 第 88 秒末,第一个机器人完成对盒子 33 的分析。这正是你需要的盒子,因此搜索结束;
  • 因此,搜索时间为 88 秒。

已知你将共请求 r1r_1 次颜色为 11 的球、r2r_2 次颜色为 22 的球,依此类推。你的目标是构造机器人对应的列表 aa 和 bb,使得所有请求的总搜索时间最小。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines:

  • the first line contains three integers nn, s1s_1, s2s_2 (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 1≤s1,s2≤101 \le s_1, s_2 \le 10);
  • the second line contains nn integers r1,r2,…,rnr_1, r_2, \dots, r_n (1≤ri≤1061 \le r_i \le 10^6).

Additional constraint on the input: the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例由两行组成:

  • 第一行包含三个整数 nn、s1s_1、s2s_2(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;1≤s1,s2≤101 \le s_1, s_2 \le 10);
  • 第二行包含 nn 个整数 r1,r2,…,rnr_1, r_2, \dots, r_n(1≤ri≤1061 \le r_i \le 10^6)。

输入的额外约束:所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print two lines. The first line should contain the list aa, the second line — the list bb. Each list has to be printed as follows: first, print the number of elements in it, and then the elements themselves.

If there are multiple answers, you may print any of them.

对于每个测试用例,输出两行。第一行应包含列表 aa,第二行应包含列表 bb。每个列表的输出格式如下:首先输出其中元素的个数,然后输出这些元素本身。

如果存在多个正确答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    3
    7 3 1
    8 6 4 4 4 1 7
    5 1 10
    1 1 1 1 1
    8 1 1
    4 5 6 8 1 7 3 2

    输出#1

    2 5 6
    5 1 7 2 4 3
    5 4 3 5 2 1
    0
    4 4 2 7 5
    4 6 3 1 8

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

首页