解析:查看每对相邻的障碍,如果距离大于s,那么可以落地并在下一个障碍前起跳。对每次落地和起跳加以判断即可。
[code]:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
const int maxn = 2e5+5;
int n,m,s,d,a[maxn],top;
P ans[4*maxn];
void sol(){
int i,j,run,jump,len;
run = -1;jump = -1;
for(i = 1;i <= n;i++){
if(s+2<=a[i]-a[i-1]){
if(jump!=-1){
if(a[i-1]+1-jump<=d&&(top>0&&ans[top-1].first==0&&ans[top-1].second>=s))ans[top++] = P(1,a[i-1]+1-jump);
else{
puts("IMPOSSIBLE");
return;
}
}
ans[top++] = P(0,a[i]-a[i-1]-2);
jump = a[i]-1;
}
}
if(a[n]+1-jump<=d&&(top>0&&ans[top-1].first==0&&ans[top-1].second>=s)) ans[top++] = P(1,a[n]+1-jump);
else{
puts("IMPOSSIBLE");
return;
}
if(m!=a[n]+1){
ans[top++] = P(0,m-a[n]-1);
}
for(i = 0;i < top;i++){
if(ans[i].first) printf("JUMP %d\n",ans[i].second);
else printf("RUN %d\n",ans[i].second);
}
}
int main(){
int i,j;
scanf("%d%d%d%d",&n,&m,&s,&d);
for(i = 1;i <= n;i++) scanf("%d",&a[i]);
sort(a+1,a+n+1);
a[0] = -1;
a[n+1] = m+1;
sol();
return 0;
}