A1135 | [COCI-2007_2008-contest6]#5 SEMAFORI
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Luka is driving his truck along a long straight road with many traffic lights. For each traffic light he knows how long the red and green lights will be on (the cycle repeating endlessly).
When Luka starts his journey, all traffic lights are red and just started their cycle. Luka moves one distance unit per second. When a traffic light is red, he stops and waits until it turns green.
Write a program that determines how much time Luka needs to reach the end of the road. The start of the road is at distance zero, the end at distance L.
When Luka starts his journey, all traffic lights are red and just started their cycle. Luka moves one distance unit per second. When a traffic light is red, he stops and waits until it turns green.
Write a program that determines how much time Luka needs to reach the end of the road. The start of the road is at distance zero, the end at distance L.
输入格式
The first line contains two integers N and L (1 ≤ N ≤ 100, 1 ≤ L ≤ 1000), the number of traffic lights on the road and the length of the road.
Each of the next N lines contains three integers D, R and G, describing one traffic light (1 ≤ D < L, 1 ≤ R ≤ 100, 1 ≤ G ≤ 100). D is the distance of the traffic light from the start of the road. R and G denote how long the red and green lights are on, respectively.
The traffic lights will be ordered in increasing order of D. No two traffic lights will share the same position.
Each of the next N lines contains three integers D, R and G, describing one traffic light (1 ≤ D < L, 1 ≤ R ≤ 100, 1 ≤ G ≤ 100). D is the distance of the traffic light from the start of the road. R and G denote how long the red and green lights are on, respectively.
The traffic lights will be ordered in increasing order of D. No two traffic lights will share the same position.
输出格式
Output the time (in seconds) Luka needs to reach the end of the road.
输入输出样例
输入 #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
In the first example, Luka will wait 2 seconds at the first traffic light. After that he will reach the second
traffic light while it is green and be able to pass through immediately.
traffic light while it is green and be able to pass through immediately.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted