QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100

#10054. 精准驾驶员

统计

Doitsafe 先生,又名 Mr. D,以其极其安全的驾驶风格而闻名。他不仅总是以最高限速驾驶汽车,而且如果交通信号灯在他刚进入路口时由绿变红,他会立即停车;当交通信号灯由红变绿时,他会立即以最高限速启动汽车。

Mr. D 的下一段驾驶路线是一条长度为 $L$ 个单位的笔直道路,最高限速为每秒 1 个单位。Mr. D 将在时间 0 出发。道路上有 $N$ 个交通信号灯,编号为 1 到 $N$。第 $i$ 个交通信号灯位于距离起点 $x_i$ 个单位的位置。在时间 0,所有 $N$ 个交通信号灯刚刚由红变绿。第 $i$ 个交通信号灯在绿灯持续 $g_i$ 秒后变为红灯,随后在红灯持续 $r_i$ 秒后变为绿灯,之后再次在绿灯持续 $g_i$ 秒后变为红灯,以此类推。

在这种情况下,Mr. D 将从起点出发,以每秒 1 个单位的速度行驶。当 Mr. D 到达 $x_i$ 时,如果第 $i$ 个交通信号灯是绿灯或刚刚由红变绿(但不是刚刚由绿变红),Mr. D 将不会停车,并以每秒 1 个单位的速度通过路口。如果当 Mr. D 到达 $x_i$ 时,第 $i$ 个交通信号灯是红灯或刚刚由绿变红(但不是刚刚由红变绿),Mr. D 将停车等待,直到第 $i$ 个交通信号灯变为绿灯。

给定 $N$ 个交通信号灯的描述,你的任务是计算 Mr. D 到达 $L$ 点时的时刻(以秒为单位)。

输入格式

输入的第一行包含两个整数,交通信号灯的数量 $N$ ($1 \le N \le 100\,000$) 和道路长度 $L$ ($1 \le L \le 10^9$)。

接下来的 $N$ 行中,第 $i$ 行包含三个整数 $x_i, g_i, r_i$,其中 $x_i$ ($1 \le x_i < L$) 是第 $i$ 个交通信号灯距离起点的距离,$g_i$ ($1 \le g_i \le 10^9$) 是第 $i$ 个交通信号灯绿灯的持续时间,$r_i$ ($1 \le r_i \le 10^9$) 是第 $i$ 个交通信号灯红灯的持续时间。

你可以假设所有交通信号灯的位置各不相同。换句话说,对于所有 $i \neq j$,都有 $x_i \neq x_j$。

输出格式

输出一行,包含一个整数,表示 Mr. D 到达 $L$ 点时的时刻(以秒为单位)。

样例

样例输入 1

3 10
3 3 3
6 2 2
9 3 6

样例输出 1

19

样例输入 2

1 101
50 900 1

样例输出 2

101

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.