Problem p01284 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template <class T> inline void chmin(T &a, const T &b) {
  if (b < a)
    a = b;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  for (int c; cin >> c, c;) {
    vector<int> t(c);
    for (int i = 0; i < c; ++i)
      cin >> t[i];

    int n;
    cin >> n;

    vector<int> get_up(100, 24);
    for (int i = 0; i < n; ++i) {
      int d, m;
      cin >> d >> m;
      chmin(get_up[d - 1], m);
    }

    vector<int> dp(c, 101);
    dp[0] = 0;
    for (int i = 0; i < 100; ++i) {
      vector<int> tmp(c, 101);
      for (int j = 0; j < c; ++j) {
        chmin(tmp[1], dp[j] + 1);
        if (t[j] <= get_up[i])
          chmin(tmp[(j + 1) % c], dp[j]);
      }

      dp.swap(tmp);
    }

    cout << *min_element(dp.begin(), dp.end()) << endl;
  }

  return EXIT_SUCCESS;
}

Error: -6
ce2f340e-7d78-4ffc-b543-242dd662a457.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p01284/C++/s004080578.cpp:57: int dfs(int, int): Assertion `d[idx + 1] > d[idx]' failed.


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define lengthof(array) (sizeof(array) / sizeof(*array))
#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it, c)                                                             \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define RFOR(it, c)                                                            \\
  for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)

template <class T> inline void chmax(T &a, const T &b) {
  if (b > a)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (b < a)
    a = b;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
  return os;
}

int n, c;
int t[30], d[101], m[101];
int memo[101][30];

int dfs(int idx = 0, int cycle = d[0] - 1) {
  if (idx == n)
    return 0;

  if (memo[idx][cycle] != -1)
    return memo[idx][cycle];

  assert(d[idx + 1] > d[idx]);
  int res = dfs(idx + 1, (d[idx + 1] - d[idx]) % c) + 1;
  if (t[cycle] <= m[idx])
    chmin(res, dfs(idx + 1, (cycle + d[idx + 1] - d[idx]) % c));

  return memo[idx][cycle] = res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> c, c) {
    for (int i = 0; i < c; ++i)
      cin >> t[i];

    cin >> n;
    for (int i = 0; i < n; ++i)
      cin >> d[i] >> m[i];

    memset(memo, -1, sizeof(memo));
    cout << dfs() << endl;
  }

  return EXIT_SUCCESS;
}