Codeforces 637D Running with Obstacles

D. Running with Obstacles

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

题目链接:https://codeforces.com/contest/637/problem/D

题目描述

A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = 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 x1, x2, ..., xn. 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.

Input

The first line of the input containsd four integers nms and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 109, 1 ≤ s, d ≤ 109) — 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 a1, a2, ..., an (1 ≤ ai ≤ 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.

Output

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.

Examples

input

3 10 1 3
3 4 7

output

RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2

input

2 9 2 3
6 4

output

IMPOSSIBLE
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int a[200010],b[200010];
typedef pair<int,int>PII;
vector<PII>c;
vector<int>run,jump;
int main()
{
    int n,m,s,d;
    cin>>n>>m>>s>>d;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    a[0]=-1;
    for(int i=1;i<=n;i++)
    {
        b[i]=a[i]-a[i-1]-2;//记录可以run的距离
    }
    if(b[1]<s)
    {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    int l=0,r=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]<s&&l)//不能起跳
        {
            r=a[i];
        }
        else if(b[i]<s&&!l)
        {
            l=a[i-1];
            r=a[i];
        }
        else if(b[i]>=s)
        {
            if(l&&r)c.erase(c.end()),c.push_back({l,r}),l=0,r=0;
            c.push_back({a[i],a[i]});
        }
    }
    if(l&&r)c.erase(c.end()),c.push_back({l,r}),l=0,r=0;
    for(int i=0;i<c.size();i++)
    {
        if(c[i].second-c[i].first+2>d)
        {
            cout<<"IMPOSSIBLE"<<endl;
            return 0;   
        }
    }
    for(int i=0;i<c.size();i++)
    {
        if(i==0)cout<<"RUN"<<' '<<c[0].first-1<<endl;
        else cout<<"RUN"<<' '<<c[i].first-c[i-1].second-2<<endl;
        cout<<"JUMP"<<' '<<c[i].second-c[i].first+2<<endl;
    }
    if(m-a[n]-1!=0)
    cout<<"RUN"<<' '<<m-a[n]-1<<endl;
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值