Codeforces Beta Round 42(Div. 2)
E
赛车
Race
Codeforces
2300
原题
← D→

赛车AI (CI翻译)

Today $*s*$ kilometer long auto race takes place in Berland. The track is represented by a straight line as long as $*s*$ kilometers. There are $*n*$ cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is known its behavior — the system of segments on each of which the speed of the car is constant. The $*j*$-th segment of the $*i*$-th car is pair $(*v*_{*i*, *j*}, *t*_{*i*, *j*})$, where $*v*_{*i*, *j*}$ is the car's speed on the whole segment in kilometers per hour and $*t*_{*i*, *j*}$ is for how many hours the car had been driving at that speed. The segments are given in the order in which they are "being driven on" by the cars.

今天,别尔兰举行一场全程 $*s*$ 公里的汽车比赛。赛道是一条长度为 $*s*$ 公里的直线。共有 $*n*$ 辆汽车参加比赛,它们同时从赛道起点出发。每辆汽车的行驶情况都已知:其行驶过程由若干路段组成,在每一段上速度保持不变。第 $*i*$ 辆汽车的第 $*j*$ 段由一对数 $(*v*_{*i*, *j*}, *t*_{*i*, *j*})$ 表示,其中 $*v*_{*i*, *j*}$ 是汽车在该路段上的速度,单位为公里每小时;$*t*_{*i*, *j*}$ 是汽车以该速度行驶的小时数。每辆汽车的路段按行驶顺序给出。AI (CI翻译)

Your task is to find out how many times during the race some car managed to have a lead over another car. A lead is considered a situation when one car appears in front of another car. It is known, that all the leads happen instantly, i. e. there are no such time segment of positive length, during which some two cars drive "together". At one moment of time on one and the same point several leads may appear. In this case all of them should be taken individually. Meetings of cars at the start and finish are not considered to be counted as leads.

请你求出比赛期间有多少次某辆汽车超过了另一辆汽车。若一辆汽车出现在另一辆汽车前方,则称其领先另一辆汽车。已知所有超车都在瞬间发生,也就是说,不存在一段长度大于零的时间,使得两辆汽车在这段时间内并排行驶。同一时刻、同一地点可能发生多次超车,此时应分别计数。比赛起点和终点处汽车相遇不计作超车。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains two integers $*n*$ and $*s*$ ($2 ≤ *n* ≤ 100, 1 ≤ *s* ≤ 10^{6}$) — the number of cars and the length of the track in kilometers. Then follow $*n*$ lines — the description of the system of segments for each car. Every description starts with integer $*k*$ ($1 ≤ *k* ≤ 100$) — the number of segments in the system. Then $*k*$ space-separated pairs of integers are written. Each pair is the speed and time of the segment. These integers are positive and don't exceed 1000. It is guaranteed, that the sum of lengths of all segments (in kilometers) for each car equals to $*s*$; and all the leads happen instantly.

第一行包含两个整数 $*n*$ 和 $*s*$($2 ≤ *n* ≤ 100, 1 ≤ *s* ≤ 10^{6}$),分别表示汽车数量和赛道长度(单位:公里)。接下来 $*n*$ 行描述每辆汽车的路段信息。每行描述以整数 $*k*$($1 ≤ *k* ≤ 100$)开头,表示该车行驶路段的数量。随后给出 $*k*$ 对以空格分隔的整数,每对整数分别表示该路段的速度和行驶时间。这些整数均为正数且不超过 1000。保证每辆汽车所有路段的长度之和(单位:公里)等于 $*s*$,并且所有超车都在瞬间发生。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Print the single number — the number of times some car managed to take the lead over another car during the race.

输出一个整数,表示比赛期间某辆汽车超过另一辆汽车的总次数。AI (CI翻译)

样例

Input #1
2 33
2 5 1 2 14
1 3 11
Output #1
1
InputCopy OutputCopy
Input #2
2 33
2 1 3 10 3
1 11 3
Output #2
0
InputCopy OutputCopy
Input #3
5 33
2 1 3 3 10
1 11 3
2 5 3 3 6
2 3 1 10 3
2 6 3 3 5
Output #3
2
InputCopy OutputCopy
题目信息
题号
43E
时间限制
2 s
内存限制
256 MB
标签
暴力
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。