A10344 | Running with Obstacles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A sportsman starts from point $x_{start}=0$ and runs to point with coordinate $x_{finish}=m$ (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than $s$ meters (in this case for these $s$ meters his path should have no obstacles), and after that he can jump over a length of not more than $d$ meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are $n$ obstacles at coordinates $x_{1},x_{2},...,x_{n}$ . He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
On the way of an athlete are $n$ obstacles at coordinates $x_{1},x_{2},...,x_{n}$ . He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
输入格式
The first line of the input containsd four integers $n$ , $m$ , $s$ and $d$ ( $1<=n<=200000$ , $2<=m<=10^{9}$ , $1<=s,d<=10^{9}$ ) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=m-1$ ) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
The second line contains a sequence of $n$ integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=m-1$ ) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
输出格式
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
If the athlete can get from start to finish, print any way to do this in the following format:
- print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters;
- print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
输入输出样例
输入 #1
3 10 1 3 3 4 7
输出 #1
RUN 2 JUMP 3 RUN 1 JUMP 2 RUN 2
输入 #2
2 9 2 3 6 4
输出 #2
IMPOSSIBLE
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted