Problem p03160 (C++)

Buggy submission (status: Runtime Error):
/*
    @author : srinathbalaji_99
*/

#include <bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for (long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b) / GCD(a, b)
#define ff first
#define ss second
#define pall(a)                                                                \
  REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " ";                        \
  cout << endl;
#define pvall(v)                                                               \
  REP(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl;
#define gall(a, n) REP(i, n) cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;

using namespace std;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

LL dp[100001], h[100001];

int main() {
  fast();

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  LL t, n, i, j, k, x, y, c;
  cin >> n;
  gall(h, n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  rep(i, 2, n, 1) {
    dp[i] =
        min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dp[n - 1];
}

Fixed submission:
/*
    @author : srinathbalaji_99
*/

#include <bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for (long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b) / GCD(a, b)
#define ff first
#define ss second
#define pall(a)                                                                \
  REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " ";                        \
  cout << endl;
#define pvall(v)                                                               \
  REP(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl;
#define gall(a, n) REP(i, n) cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;

using namespace std;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

LL dp[100001], h[100001];

int main() {
  fast();

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif

  LL t, n, i, j, k, x, y, c;
  cin >> n;
  gall(h, n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  rep(i, 2, n, 1) {
    dp[i] =
        min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dp[n - 1];
}