Problem p03160 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v)                                                         \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define deb4(a, b, c, d)                                                       \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e)                                                    \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f)                                                 \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n)                                                              \
  for (ll i = 0; i < n; i++)                                                   \
    cin >> a[i];
#define gint(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define setZero(a, n)                                                          \
  for (int i = 0; i < n; i++)                                                  \
    a[i] = 0;
#define printArray(a, s, e)                                                    \
  for (int i = s; i < e; i++) {                                                \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    gint(arr, n);

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);

    for (int i = 2; i < n; i++) {
      dp[i] = min((abs(arr[i] - arr[i - 1]) + dp[i - 1]),
                  (abs(arr[i] - arr[i - 2]) + dp[i - 2]));
    }

    cout << dp[n - 1];
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v)                                                         \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z)                                                          \
  cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define deb4(a, b, c, d)                                                       \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e)                                                    \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f)                                                 \
  cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl

#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n)                                                              \
  for (ll i = 0; i < n; i++)                                                   \
    cin >> a[i];
#define gint(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define setZero(a, n)                                                          \
  for (int i = 0; i < n; i++)                                                  \
    a[i] = 0;
#define printArray(a, s, e)                                                    \
  for (int i = s; i < e; i++) {                                                \
    cout << a[i] << " ";                                                       \
  }                                                                            \
  cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
  fast;

  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    gint(arr, n);

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);

    for (int i = 2; i < n; i++) {
      dp[i] = min((abs(arr[i] - arr[i - 1]) + dp[i - 1]),
                  (abs(arr[i] - arr[i - 2]) + dp[i - 2]));
    }

    cout << dp[n - 1];
  }
}