###### Codeforces 637D Running with Obstacles (贪心)

[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;
}

#### Codeforces 637D Running with Obstacles 【贪心】

2016-03-19 11:24:12

#### CodeForces 637D Running with Obstacles（贪心模拟）

2016-03-27 11:39:34

#### CF 637D. Running with Obstacles 贪心

2016-04-02 01:48:20

#### CodeForces 140C 贪心+优先队列

2016-11-25 21:39:12

#### Codeforces 796C Bank Hacking 贪心+规律

2017-04-11 04:45:50

#### CodeForces - 808C-贪心-思维

2017-05-21 19:50:54

#### CodeForces 637 D.Running with Obstacles（贪心）

2017-04-28 10:44:01

#### Codeforces 854C. Planning 贪心

2017-09-08 18:10:24

#### Codeforces 3 B. Lorry 暴力 排序 枚举 贪心

2014-10-18 09:03:20

#### Codeforces Round #437-贪心-C. Ordering Pizza

2017-10-16 12:40:24

## 不良信息举报

Codeforces 637D Running with Obstacles (贪心)