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

// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)                                                           \\
  do {                                                                         \\
    cout << #args << " -> ";                                                   \\
    err(args);                                                                 \\
  } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg)
    std::cout << v << ' ';
  err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int MAXN = 200005;

int64 a[MAXN];

void run() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int64 ans = 1000;
  for (int i = 2; i <= n; i++) {
    if (a[i] > a[i - 1]) {
      ans = ans % a[i - 1] + ans / a[i - 1] * a[i];
    }
  }
  cout << ans << endl;
}

// Debug Input Redirection
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  run();
}


Error: 0

Fixed submission:

// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)                                                           \\
  do {                                                                         \\
    cout << #args << " -> ";                                                   \\
    err(args);                                                                 \\
  } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg)
    std::cout << v << ' ';
  err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int MAXN = 200005;

int64 a[MAXN];
int dp[85][2005][15];
int n;

int solve(int i, int m, int s) {
  if (i == n)
    return m + s * a[n];
  int &ans = dp[i][m][s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 0; j <= s; j++) {
    ans = max(ans, solve(i + 1, m + j * a[i], s - j));
  }
  for (int j = 0; j * a[i] <= m; j++) {
    ans = max(ans, solve(i + 1, m - j * a[i], s + j));
  }
  return ans;
}

void run() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << solve(1, 1000, 0) << endl;
}

// Debug Input Redirection
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  run();
}