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

#include "bits/stdc++.h"
using namespace std;

// #define int long long
#define DBG 0
#define dump(o)                                                                \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << " ";                                           \\
  }
#define dumpl(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o << " " << (o) << endl;                                          \\
  }
#define dumpc(o)                                                               \\
  if (DBG) {                                                                   \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  int N, R, T;
  cin >> N >> R >> T;
  vector<int> p(N);
  rep(i, 0, N) { cin >> p[i]; }
  vector<int> cnt(R, 0);
  vector<int> tmp(R, 0);
  vector<int> d(N, 0);
  rep(t, 0, T) {
    rep(i, 0, N) { d[i] += p[i]; }
    rep(i, 0, N) {
      int idx = d[i] % R;
      if (tmp[idx])
        tmp[idx]--;
      else
        cnt[idx]++;
    }
    if (t == 0)
      continue;
    rep(i, 0, N) {
      int idx = d[i] % R;
      tmp[idx]++;
    }
    dumpc(cnt);
    dumpc(tmp);
  }
  cout << accumulate(all(cnt), 0) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  if (DEBUG) {                                                                 \\
    cerr << #o << " " << o << endl;                                            \\
  }
#define dumpc(o)                                                               \\
  if (DEBUG) {                                                                 \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;

signed main() {
  int N, R, T;
  cin >> N >> R >> T;
  int p[110] = {};
  rep(i, 0, N) cin >> p[i];
  sort(p, p + N);
  static int cnt[1010][1010] = {};
  int ans = 0;
  rrep(i, 0, N) {
    rep(j, 1, T + 1) {
      if (p[i] * (j - 1) > R)
        break;
      int c = *max_element(cnt[p[i] * j], cnt[p[i] * j] + j);
      dump(c);
      if (c) {
        c--;
      } else {
        ans++;
      }
      if (j >= 2 && p[i] * j <= R)
        cnt[p[i] * j][j]++;
    }
  }
  cout << ans << endl;
  return 0;
}