Here is the link of problem at atcoder:
I tried it with a naive recursion approach. It's running good with the testcases in my pc but getting RE in atcoder compiler. I have no clue how it is getting RE.
Here is the solution
#include<bits/stdc++.h>
using namespace std;
int N,sum=0,mn=INT_MAX,h[100006];
int recur(int i,int sum)
{
if(N>=4)
{
return mn=min(sum,mn);
}
else
{
recur(i+1,sum+abs(h[i+1]-h[i]));
recur(i+2,sum+abs(h[i+2]-h[i]));
}
}
int main()
{
int n,i,j,k;
cin>>N;
for(i=1;i<=N;i++)
{
cin>>h[i];
}
cout<<recur(1,0)<<endl;
return 0;
}