CF1131G.Most Dangerous Shark

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:768MB

AC君温馨提醒

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

题目描述

Semyon participates in the most prestigious competition of the world ocean for the title of the most dangerous shark. During this competition sharks compete in different subjects: speed swimming, masking, map navigation and many others. Now Semyon is taking part in «destruction» contest.

During it, mm dominoes are placed in front of the shark. All dominoes are on the same line, but the height of the dominoes may vary. The distance between adjacent dominoes is 11. Moreover, each Domino has its own cost value, expressed as an integer. The goal is to drop all the dominoes. To do this, the shark can push any domino to the left or to the right, and it will begin falling in this direction. If during the fall the domino touches other dominoes, they will also start falling in the same direction in which the original domino is falling, thus beginning a chain reaction, as a result of which many dominoes can fall. A falling domino touches another one, if and only if the distance between them was strictly less than the height of the falling domino, the dominoes do not necessarily have to be adjacent.

Of course, any shark can easily drop all the dominoes in this way, so the goal is not to drop all the dominoes, but do it with a minimum cost. The cost of the destruction is the sum of the costs of dominoes that the shark needs to push to make all the dominoes fall.

Simon has already won in the previous subjects, but is not smart enough to win in this one. Help Semyon and determine the minimum total cost of the dominoes he will have to push to make all the dominoes fall.

谢苗正在参加世界海洋最负盛名的比赛,争夺“最危险鲨鱼”的称号。在该比赛中,鲨鱼们需在多个项目中展开角逐:如速度游泳、伪装、地图导航等众多项目。目前,谢苗正参与“多米诺骨牌摧毁”项目。

比赛过程中,mm 个多米诺骨牌被放置在鲨鱼前方。所有骨牌均位于同一条直线上,但各骨牌高度可能不同。相邻骨牌之间的距离为 11。此外,每个骨牌均有其自身的成本值(以整数表示)。目标是使所有骨牌全部倒下。为此,鲨鱼可任选一个骨牌向左或向右推动,该骨牌将朝所推方向倾倒。若在倾倒过程中,该骨牌触碰到其他骨牌,则这些被触碰的骨牌也将沿相同方向倾倒,从而引发连锁反应,使得大量骨牌接连倒下。当且仅当一个倾倒中的骨牌与另一骨牌之间的距离严格小于该倾倒骨牌的高度时,二者才视为发生接触(注意:这两块骨牌未必相邻)。

当然,任何鲨鱼都能轻易地以这种方式推倒全部骨牌;因此本项目的真正目标并非简单推倒所有骨牌,而是以最小总成本完成这一任务。所谓摧毁成本,即鲨鱼为使所有骨牌倒下而必须亲自推动的那些骨牌的成本之和。

西蒙已在先前的项目中获胜,但在此项目中却因不够聪明而难以取胜。请帮助谢苗计算:为使所有骨牌倒下,他所需推动的骨牌的最小总成本是多少?

输入格式

In order to reduce input size, the heights and costs of the dominoes are described with blocks.

The first line contains two integers nn and mm (1≤n≤250 000,1≤m≤1071 \leq n \leq 250\,000, 1 \leq m \leq 10^7) — the number of the blocks and the total number of the dominoes Semyon must drop.

Then descriptions of nn blocks follow. Description of every block consists of three lines.

The first line of block's description contains a single integer kik_i (1≤ki≤250 000,∑i=1nki≤250 0001 \leq k_i \leq 250\,000, \sum_{i = 1}^{n}{k_i} \leq 250\,000) — the number of dominoes in the block.

The second line of block's description contains kik_i integers aja_j (1≤aj≤m1 \leq a_j \leq m) — the heights of the dominoes in the blocks.

The third line contains kik_i integers cjc_j (1≤cj≤100 0001 \leq c_j \leq 100\,000) — the costs of the dominoes in the block.

Then the domino sequence is described (from left to right).

The first line of this description contains a single integer qq (n≤q≤250 000n \leq q \leq 250\,000) — the number of blocks in the sequence of domino sequence.

Each of the following qq lines contains integers idi,muliid_i, mul_i (1≤idi≤n1 \leq id_i \leq n, 1≤muli≤100 0001 \leq mul_i \leq 100\,000), denoting that the next kidik_{id_i} dominoes are dominoes of the block idiid_i, with their cost multiplied by mulimul_i.

It's guaranteed, that ∑i=1qkidi=m\sum_{i = 1}^{q}{k_{id_i}} = m, and that's every block is used in the sequence at least once.

为了减小输入规模,多米诺骨牌的高度和成本以“块”(blocks)的形式描述。

第一行包含两个整数 nn 和 mm(1≤n≤250 000, 1≤m≤1071 \leq n \leq 250\,000,\ 1 \leq m \leq 10^7)—— 分别表示块的数量以及谢苗必须推倒的多米诺骨牌总数。

接下来是 nn 个块的描述。每个块的描述由三行组成。

块描述的第一行包含一个整数 kik_i(1≤ki≤250 000, ∑i=1nki≤250 0001 \leq k_i \leq 250\,000,\ \sum_{i = 1}^{n}{k_i} \leq 250\,000)—— 表示该块中包含的多米诺骨牌数量。

块描述的第二行包含 kik_i 个整数 aja_j(1≤aj≤m1 \leq a_j \leq m)—— 表示该块中各多米诺骨牌的高度。

块描述的第三行包含 kik_i 个整数 cjc_j(1≤cj≤100 0001 \leq c_j \leq 100\,000)—— 表示该块中各多米诺骨牌的成本。

随后描述多米诺骨牌序列(从左到右)。

该描述的第一行包含一个整数 qq(n≤q≤250 000n \leq q \leq 250\,000)—— 表示多米诺骨牌序列中块的数量。

接下来的 qq 行每行包含两个整数 idiid_i 和 mulimul_i(1≤idi≤n, 1≤muli≤100 0001 \leq id_i \leq n,\ 1 \leq mul_i \leq 100\,000),表示接下来的 kidik_{id_i} 张多米诺骨牌来自编号为 idiid_i 的块,且其成本均乘以 mulimul_i。

保证 ∑i=1qkidi=m\sum_{i = 1}^{q}{k_{id_i}} = m,且每个块在序列中至少被使用一次。

输出格式

Print exactly one integer — the minimum cost to make all the dominoes fall.

输出一个整数——使所有多米诺骨牌倒下的最小代价。

输入输出样例

  • 输入#1

    2 7
    3
    1 2 2
    1 2 1
    1
    3
    2
    3
    2 2
    1 3
    1 1

    输出#1

    5
  • 输入#2

    1 1
    1
    1
    100000
    1
    1 100000

    输出#2

    10000000000

说明/提示

In the first example, there are 77 dominoes in front of the Semyon. Their heights are equal to [3,1,2,2,1,2,2][3, 1, 2, 2, 1, 2, 2], and their costs are equal to [4,3,6,3,1,2,1][4, 3, 6, 3, 1, 2, 1]. Semyon should drop the domino with index 77 to the left, it will fall and drop the domino 66 as well. The domino 66 during the fall will drop the domino 55, however the latter will not drop any more dominoes. Then Semyon should drop domino with number 11 to the right and it will drop dominoes 22 and 33 after falling. And the domino 33 will drop the domino 44 after falling. Hence all dominoes are fallen this way.

In the second example, there is a single domino of cost 1000000000010000000000.

在第一个例子中,谢苗面前有 77 个骨牌,它们的高度分别为 [3,1,2,2,1,2,2][3, 1, 2, 2, 1, 2, 2],成本分别为 [4,3,6,3,1,2,1][4, 3, 6, 3, 1, 2, 1]。谢苗应将编号为 77 的骨牌向左推倒,它倒下后会顺势推倒编号为 66 的骨牌;而编号为 66 的骨牌在倒下过程中又会推倒编号为 55 的骨牌,但编号为 55 的骨牌不会再推倒其他骨牌。接着,谢苗应将编号为 11 的骨牌向右推倒,它倒下后会推倒编号为 22 和 33 的骨牌;而编号为 33 的骨牌在倒下后又会推倒编号为 44 的骨牌。因此,所有骨牌均以此方式被推倒。

在第二个例子中,仅有一个成本为 1000000000010000000000 的骨牌。

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

首页