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, m 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 1. 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.
谢苗正在参加世界海洋最负盛名的比赛,争夺“最危险鲨鱼”的称号。在该比赛中,鲨鱼们需在多个项目中展开角逐:如速度游泳、伪装、地图导航等众多项目。目前,谢苗正参与“多米诺骨牌摧毁”项目。
比赛过程中,m 个多米诺骨牌被放置在鲨鱼前方。所有骨牌均位于同一条直线上,但各骨牌高度可能不同。相邻骨牌之间的距离为 1。此外,每个骨牌均有其自身的成本值(以整数表示)。目标是使所有骨牌全部倒下。为此,鲨鱼可任选一个骨牌向左或向右推动,该骨牌将朝所推方向倾倒。若在倾倒过程中,该骨牌触碰到其他骨牌,则这些被触碰的骨牌也将沿相同方向倾倒,从而引发连锁反应,使得大量骨牌接连倒下。当且仅当一个倾倒中的骨牌与另一骨牌之间的距离严格小于该倾倒骨牌的高度时,二者才视为发生接触(注意:这两块骨牌未必相邻)。
当然,任何鲨鱼都能轻易地以这种方式推倒全部骨牌;因此本项目的真正目标并非简单推倒所有骨牌,而是以最小总成本完成这一任务。所谓摧毁成本,即鲨鱼为使所有骨牌倒下而必须亲自推动的那些骨牌的成本之和。
西蒙已在先前的项目中获胜,但在此项目中却因不够聪明而难以取胜。请帮助谢苗计算:为使所有骨牌倒下,他所需推动的骨牌的最小总成本是多少?
输入格式
In order to reduce input size, the heights and costs of the dominoes are described with blocks.
The first line contains two integers n and m (1≤n≤250000,1≤m≤107) — the number of the blocks and the total number of the dominoes Semyon must drop.
Then descriptions of n blocks follow. Description of every block consists of three lines.
The first line of block's description contains a single integer ki (1≤ki≤250000,∑i=1nki≤250000) — the number of dominoes in the block.
The second line of block's description contains ki integers aj (1≤aj≤m) — the heights of the dominoes in the blocks.
The third line contains ki integers cj (1≤cj≤100000) — 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 q (n≤q≤250000) — the number of blocks in the sequence of domino sequence.
Each of the following q lines contains integers idi,muli (1≤idi≤n, 1≤muli≤100000), denoting that the next kidi dominoes are dominoes of the block idi, with their cost multiplied by muli.
It's guaranteed, that ∑i=1qkidi=m, and that's every block is used in the sequence at least once.
为了减小输入规模,多米诺骨牌的高度和成本以“块”(blocks)的形式描述。
第一行包含两个整数 n 和 m(1≤n≤250000, 1≤m≤107)—— 分别表示块的数量以及谢苗必须推倒的多米诺骨牌总数。
接下来是 n 个块的描述。每个块的描述由三行组成。
块描述的第一行包含一个整数 ki(1≤ki≤250000, ∑i=1nki≤250000)—— 表示该块中包含的多米诺骨牌数量。
块描述的第二行包含 ki 个整数 aj(1≤aj≤m)—— 表示该块中各多米诺骨牌的高度。
块描述的第三行包含 ki 个整数 cj(1≤cj≤100000)—— 表示该块中各多米诺骨牌的成本。
随后描述多米诺骨牌序列(从左到右)。
该描述的第一行包含一个整数 q(n≤q≤250000)—— 表示多米诺骨牌序列中块的数量。
接下来的 q 行每行包含两个整数 idi 和 muli(1≤idi≤n, 1≤muli≤100000),表示接下来的 kidi 张多米诺骨牌来自编号为 idi 的块,且其成本均乘以 muli。
保证 ∑i=1qkidi=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 7 dominoes in front of the Semyon. Their heights are equal to [3,1,2,2,1,2,2], and their costs are equal to [4,3,6,3,1,2,1]. Semyon should drop the domino with index 7 to the left, it will fall and drop the domino 6 as well. The domino 6 during the fall will drop the domino 5, however the latter will not drop any more dominoes. Then Semyon should drop domino with number 1 to the right and it will drop dominoes 2 and 3 after falling. And the domino 3 will drop the domino 4 after falling. Hence all dominoes are fallen this way.
In the second example, there is a single domino of cost 10000000000.
在第一个例子中,谢苗面前有 7 个骨牌,它们的高度分别为 [3,1,2,2,1,2,2],成本分别为 [4,3,6,3,1,2,1]。谢苗应将编号为 7 的骨牌向左推倒,它倒下后会顺势推倒编号为 6 的骨牌;而编号为 6 的骨牌在倒下过程中又会推倒编号为 5 的骨牌,但编号为 5 的骨牌不会再推倒其他骨牌。接着,谢苗应将编号为 1 的骨牌向右推倒,它倒下后会推倒编号为 2 和 3 的骨牌;而编号为 3 的骨牌在倒下后又会推倒编号为 4 的骨牌。因此,所有骨牌均以此方式被推倒。
在第二个例子中,仅有一个成本为 10000000000 的骨牌。
输入解题思路,AI测评打分。不知道怎么写?