Problem p03160 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef unordered_map<int, int> uoii;
typedef unordered_map<string, int> uosi;

#define MOD = 1e9 + 7;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

#define de(args...) (Debugger()), args

class Debugger {
public:
  Debugger(const std::string &_separator = " - ")
      : first(true), separator(_separator) {}

  template <typename ObjectType> Debugger &operator,(const ObjectType &v) {
    if (!first)
    std:
      cerr << separator;
    std::cerr << v;
    first = false;
    return *this;
  }
  ~Debugger() {
  std:
    cerr << endl;
  }

private:
  bool first;
  std::string separator;
};

#else
#define debug(args...) // Just strip off all debug tokens
#endif

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

      int n;
  cin >> n;
  vi h(n + 1);
  int inf = 1000 * 1000 * 1000;
  for (int i = 1; i < n + 1; i++)
    cin >> h[i];
  vi dp(n + 1, inf);
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(h[2 - 1] - h[2]);
  for (int i = 3; i <= n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dp[n];
  return 0;
}


Fixed submission:
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define init(a, b) memset(a, b, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef unordered_map<int, int> uoii;
typedef unordered_map<string, int> uosi;

#define MOD = 1e9 + 7;

/******* Debugging Class Template *******/
#define DEBUG

#ifdef DEBUG

#define de(args...) (Debugger()), args

class Debugger {
public:
  Debugger(const std::string &_separator = " - ")
      : first(true), separator(_separator) {}

  template <typename ObjectType> Debugger &operator,(const ObjectType &v) {
    if (!first)
    std:
      cerr << separator;
    std::cerr << v;
    first = false;
    return *this;
  }
  ~Debugger() {
  std:
    cerr << endl;
  }

private:
  bool first;
  std::string separator;
};

#else
#define debug(args...) // Just strip off all debug tokens
#endif

int32_t main() {
  IOS

      int n;
  cin >> n;
  vi h(n + 1);
  int inf = 1000 * 1000 * 1000;
  for (int i = 1; i < n + 1; i++)
    cin >> h[i];
  vi dp(n + 1, inf);
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(h[2 - 1] - h[2]);
  for (int i = 3; i <= n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dp[n];
  return 0;
}