QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 32 MB 總分: 30

#17127. SEMAFORI

统计

Luka 正在一条长长的直路上开卡车,路上有许多红绿灯。对于每个红绿灯,他都知道红灯和绿灯会持续多长时间(该循环无限重复)。

当 Luka 开始他的旅程时,所有红绿灯都是红色的,并且刚刚开始它们的循环。Luka 每秒移动一个单位距离。当红绿灯是红灯时,他会停下来等待,直到它变成绿灯。

编写一个程序,确定 Luka 到达道路尽头需要多少时间。道路的起点在距离 $0$ 处,终点在距离 $L$ 处。

输入格式

第一行包含两个整数 $N$ 和 $L$($1 \le N \le 100$,$1 \le L \le 1000$),分别表示道路上的红绿灯数量和道路的长度。

接下来的 $N$ 行,每行包含三个整数 $D$、$R$ 和 $G$,描述一个红绿灯($1 \le D < L$,$1 \le R \le 100$,$1 \le G \le 100$)。$D$ 是红绿灯距离道路起点的距离。$R$ 和 $G$ 分别表示红灯和绿灯持续的时间。

红绿灯将按照 $D$ 递增的顺序给出。没有两个红绿灯会处于相同的位置。

输出格式

输出 Luka 到达道路终点所需的时间(以秒为单位)。

样例

输入样例 1

2 10
3 5 5
5 2 2

输出样例 1

12

输入样例 2

4 30
7 13 5
14 4 4
15 3 10
25 1 1

输出样例 2

36

说明

在第一个样例中,Luka 将在第一个红绿灯处等待 $2$ 秒。之后,他到达第二个红绿灯时正好是绿灯,可以直接通过。

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.