CF2257E.Busy Beaver

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

The Beaver founded a construction company called "Busy Beaver". And now, in order to build up the company's reputation, it needs to construct the tallest building possible.

The company has an initial capital of xx carrots (a very valuable currency for beavers) and nn projects available for construction. A separate site has been allocated for each project, and nothing has been built there yet. A building project is represented by a sequence of contracts for constructing the next floor. To build the jj-th floor of the ii-th building, it is necessary to spend ai,ja_{i, j} carrots; upon completing it, the company immediately receives bi,jb_{i,j} carrots, which are added to the budget, and the company may use them to build higher floors of the same building or to work on other projects. Since the company is still young, not all contracts are necessarily profitable; in other words, it is possible that ai,j>bi,ja_{i,j} \gt b_{i,j}.

The Beaver hired you to plan the company's course of action. You choose in which order to build which floors. Note that it is not necessary to complete projects, or even to start them at all. Moreover, between constructing floors of the same building, it is allowed to complete an arbitrary number of contracts unrelated to that building. The main goal is — to build the tallest building possible.

海狸创办了一家名为“忙碌的海狸”的建筑公司。如今,为了提升公司的声誉,它需要建造尽可能高的建筑。

该公司初始资金为 xx 根胡萝卜(这是海狸世界中一种极为珍贵的货币),并拥有 nn 个可供施工的项目。每个项目都已分配了独立的施工场地,且目前尚未开始任何建设。每个建筑项目由一系列用于建造上一层楼的合同构成。要建造第 ii 座建筑的第 jj 层,需花费 ai,ja_{i, j} 根胡萝卜;该层完工后,公司会立即获得 bi,jb_{i,j} 根胡萝卜,这笔收入将直接计入公司预算,可用于继续建造同一建筑的更高楼层,或用于其他项目的施工。由于公司尚处初创阶段,并非所有合同都必然盈利;换言之,可能出现 ai,j>bi,ja_{i,j} > b_{i,j} 的情况。

海狸聘请你来规划公司的行动方案。你需要决定建造各楼层的顺序。注意:无需完成某个项目,甚至可以完全不启动某个项目。此外,在建造同一座建筑的两层之间,允许任意穿插执行与该建筑无关的其他合同。主要目标是——建造尽可能高的建筑。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤3⋅1041 \le t \le 3 \cdot 10^4). The description of the test cases follows.

The first line of each input data set contains integers nn and xx — the number of building projects and the initial amount of money (1≤n≤2⋅105;0≤x≤10181 \le n \le 2 \cdot 10^5; 0 \le x \le 10^{18}).

Next, there are nn descriptions of projects. The first line of the description of project number ii contains the number mim_i — the maximum number of floors available for construction in this building (1≤mi≤2⋅1051 \le m_i \le 2 \cdot 10^5).

The second line of the project description contains mim_i integers ai,1,ai,2,…ai,mia_{i, 1}, a_{i, 2}, \ldots a_{i, m_i} — the costs of building the floors. The third line of the project description contains mim_i integers bi,1,bi,2,…bi,mib_{i, 1}, b_{i, 2}, \ldots b_{i, m_i} — the profits from building the floors. (0≤ai,j,bi,j≤109)(0 \leq a_{i, j}, b_{i, j} \leq 10^9).

It is guaranteed that the sum of mim_i over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤3⋅1041 \le t \le 3 \cdot 10^4)。随后是各测试用例的描述。

每个输入数据集的第一行包含两个整数 nn 和 xx —— 分别表示建筑项目的数量以及初始资金数额(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;0≤x≤10180 \le x \le 10^{18})。

接下来是 nn 个项目的描述。第 ii 个项目描述的第一行包含整数 mim_i —— 表示该建筑最多可建造的楼层数(1≤mi≤2⋅1051 \le m_i \le 2 \cdot 10^5)。

项目描述的第二行包含 mim_i 个整数 ai,1,ai,2,…,ai,mia_{i, 1}, a_{i, 2}, \ldots, a_{i, m_i} —— 表示建造各楼层所需的成本。项目描述的第三行包含 mim_i 个整数 bi,1,bi,2,…,bi,mib_{i, 1}, b_{i, 2}, \ldots, b_{i, m_i} —— 表示建造各楼层所能获得的利润。(0≤ai,j,bi,j≤1090 \leq a_{i, j}, b_{i, j} \leq 10^9)

保证所有测试用例中 mim_i 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each set of input data, output two numbers — the height, in floors, of the tallest building that can be constructed, and the smallest index of the building for which it is possible to build that number of floors.

对于每组输入数据,输出两个数:所能建造的最高建筑物的高度(以楼层为单位),以及能够建造该高度的建筑物的最小索引。

输入输出样例

  • 输入#1

    2
    1 6
    4
    4 4 2 1
    2 4 1 1
    2 3
    2
    4 4
    5 5
    2
    2 20
    4 0

    输出#1

    4 1
    2 1

说明/提示

In the first set, there are enough carrots to sequentially build all 44 floors of the only building.

In the second set, you need to first build the first floor of the second building, earning 22 carrots from it, after which you can build both floors of the first building.

在第一套中,胡萝卜的数量足以依次建造唯一一栋建筑的全部 44 层。

在第二套中,你需要先建造第二栋建筑的第一层,从中获得 22 根胡萝卜,之后才能建造第一栋建筑的两层。

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

首页