A8271 | Take-off Ramps
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya participates in a ski race along the $X$ axis. The start is at point $0$ , and the finish is at $L$ , that is, at a distance $L$ meters from the start in the positive direction of the axis. Vasya has been training so hard that he can run one meter in exactly one second.
Besides, there are $n$ take-off ramps on the track, each ramp is characterized by four numbers:
- $x_{i}$ represents the ramp's coordinate
- $d_{i}$ represents from how many meters Vasya will land if he goes down this ramp
- $t_{i}$ represents the flight time in seconds
- $p_{i}$ is the number, indicating for how many meters Vasya should gather speed to get ready and fly off the ramp. As Vasya gathers speed, he should ski on the snow (that is, he should not be flying), but his speed still equals one meter per second.
Vasya is allowed to move in any direction on the $X$ axis, but he is prohibited to cross the start line, that is go to the negative semiaxis. Vasya himself chooses which take-off ramps he will use and in what order, that is, he is not obliged to take off from all the ramps he encounters. Specifically, Vasya can skip the ramp. It is guaranteed that $x_{i}+d_{i}<=L$ , that is, Vasya cannot cross the finish line in flight.
Vasya can jump from the ramp only in the positive direction of $X$ axis. More formally, when using the $i$ -th ramp, Vasya starts gathering speed at point $x_{i}-p_{i}$ , jumps at point $x_{i}$ , and lands at point $x_{i}+d_{i}$ . He cannot use the ramp in opposite direction.
Your task is to find the minimum time that Vasya will spend to cover the distance.
Besides, there are $n$ take-off ramps on the track, each ramp is characterized by four numbers:
- $x_{i}$ represents the ramp's coordinate
- $d_{i}$ represents from how many meters Vasya will land if he goes down this ramp
- $t_{i}$ represents the flight time in seconds
- $p_{i}$ is the number, indicating for how many meters Vasya should gather speed to get ready and fly off the ramp. As Vasya gathers speed, he should ski on the snow (that is, he should not be flying), but his speed still equals one meter per second.
Vasya is allowed to move in any direction on the $X$ axis, but he is prohibited to cross the start line, that is go to the negative semiaxis. Vasya himself chooses which take-off ramps he will use and in what order, that is, he is not obliged to take off from all the ramps he encounters. Specifically, Vasya can skip the ramp. It is guaranteed that $x_{i}+d_{i}<=L$ , that is, Vasya cannot cross the finish line in flight.
Vasya can jump from the ramp only in the positive direction of $X$ axis. More formally, when using the $i$ -th ramp, Vasya starts gathering speed at point $x_{i}-p_{i}$ , jumps at point $x_{i}$ , and lands at point $x_{i}+d_{i}$ . He cannot use the ramp in opposite direction.
Your task is to find the minimum time that Vasya will spend to cover the distance.
输入格式
The first line contains two integers $n$ and $L$ ( $0<=n<=10^{5}$ , $1<=L<=10^{9}$ ). Then $n$ lines contain the descriptions of the ramps, each description is on a single line. Each description is a group of four non-negative integers $x_{i}$ , $d_{i}$ , $t_{i}$ , $p_{i}$ ( $0<=x_{i}<=L$ , $1<=d_{i},t_{i},p_{i}<=10^{9}$ , $x_{i}+d_{i}<=L$ ).
输出格式
Print in the first line the minimum time in seconds Vasya needs to complete the track. Print in the second line $k$ — the number of take-off ramps that Vasya needs to use, and print on the third line of output $k$ numbers the number the take-off ramps Vasya used in the order in which he used them. Print each number exactly once, separate the numbers with a space. The ramps are numbered starting from 1 in the order in which they are given in the input.
输入输出样例
输入 #1
2 20 5 10 5 5 4 16 1 7
输出 #1
15 1 1
输入 #2
2 20 9 8 12 6 15 5 1 1
输出 #2
16 1 2
In the first sample, Vasya cannot use ramp 2, because then he will need to gather speed starting from point -3, which is not permitted by the statement. The optimal option is using ramp 1, the resulting time is: moving to the point of gathering speed + gathering speed until reaching the takeoff ramp + flight time + moving to the finish line $=0+5+5+5=15$ .
In the second sample using ramp 1 is not optimal for Vasya as $t_{1}>d_{1}$ . The optimal option is using ramp 2, the resulting time is: moving to the point of gathering speed + gathering speed until reaching the takeoff ramp + flight time + moving to the finish line $=14+1+1+0=16$ .
In the second sample using ramp 1 is not optimal for Vasya as $t_{1}>d_{1}$ . The optimal option is using ramp 2, the resulting time is: moving to the point of gathering speed + gathering speed until reaching the takeoff ramp + flight time + moving to the finish line $=14+1+1+0=16$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted