alexjercan/bugnet huggingface dataset:
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
#define BUY (0)
#define SELL (1)
#define DONOTHING (2)
vector<int> tradeList;
long long ans = 0;
void checkResult() {
  long long money = 1000;
  long long stock = 0;
  for (int i = 0; i < tradeList.size(); i++) {
    switch (tradeList[i]) {
    case /* constant-expression */ BUY:
      /* code */
      stock += money / a[i];
      money = money % a[i];
      break;
    case /* constant-expression */ SELL:
      /* code */
      money += stock * a[i];
      stock = 0;
      break;
    case /* constant-expression */ DONOTHING:
      /* code */
      break;

    default:
      break;
    }
  }
  ans = max(ans, money);
}
void dfs(int trade) {
  tradeList.push_back(trade);
  if (tradeList.size() == n) {
    checkResult();
  } else {
    dfs(BUY);
    tradeList.pop_back();
    dfs(SELL);
    tradeList.pop_back();
    dfs(DONOTHING);
    tradeList.pop_back();
  }
}
int main() {
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      tradeList.push_back(BUY);
    } else if (a[i] > a[i + 1]) {
      tradeList.push_back(SELL);
    } else {
      tradeList.push_back(SELL);
    }
  }
  tradeList.push_back(SELL);
  checkResult();
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
#define BUY (0)
#define SELL (1)
#define DONOTHING (2)
vector<int> tradeList;
int ans = 0;
void checkResult() {
  int money = 1000;
  int stock = 0;
  for (int i = 0; i < tradeList.size(); i++) {
    switch (tradeList[i]) {
    case /* constant-expression */ BUY:
      /* code */
      stock += money / a[i];
      money = money % a[i];
      break;
    case /* constant-expression */ SELL:
      /* code */
      money += stock * a[i];
      stock = 0;
      break;
    case /* constant-expression */ DONOTHING:
      /* code */
      break;

    default:
      break;
    }
  }
  ans = max(ans, money);
}
void dfs(int trade) {
  tradeList.push_back(trade);
  if (tradeList.size() == n) {
    checkResult();
  } else {
    dfs(BUY);
    tradeList.pop_back();
    dfs(SELL);
    tradeList.pop_back();
    dfs(DONOTHING);
    tradeList.pop_back();
  }
}
int main() {
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dfs(BUY);
  tradeList.pop_back();
  dfs(SELL);
  tradeList.pop_back();
  dfs(DONOTHING);
  tradeList.pop_back();
  cout << ans << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int N;
vector<int64_t> A;

int INIT = 1000;

int64_t MONEY;
int64_t KABU;

int main() {
  // std::cout << std::fixed << std::setprecision(20);

  cin >> N;
  A = vector<int64_t>(N, 0);
  REP(i, N) { cin >> A[i]; }

  MONEY = INIT;
  KABU = 0;

  REP(i, N) {
    // ノーポジ
    if (i == N - 1) {
      MONEY += A[i] * KABU;
      KABU = 0;
      cout << MONEY << endl;
      return 0;
    }

    // 買い時
    if (A[i] < A[i + 1]) {
      double tmp = MONEY / (double)A[i];
      KABU += (int64_t)tmp;
      MONEY -= A[i] * (int64_t)tmp;

      continue;
    }

    // 売り時
    if (A[i] > A[i + 1]) {
      MONEY += A[i] * KABU;
      KABU = 0;
      continue;
    }
  }
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int N;
vector<int> A;

int INIT = 1000;

int64_t MONEY;
int KABU;

int main() {
  // std::cout << std::fixed << std::setprecision(20);

  cin >> N;
  A = vector<int>(N, 0);
  REP(i, N) { cin >> A[i]; }

  MONEY = INIT;
  KABU = 0;

  REP(i, N) {
    // ノーポジ
    if (i == N - 1) {
      while (KABU > 0) {
        KABU--;
        MONEY += A[i];
      }
      cout << MONEY << endl;
      return 0;
    }

    // 買い時
    if (A[i] < A[i + 1]) {
      while (MONEY >= A[i]) {
        KABU++;
        MONEY -= A[i];
      }
      continue;
    }

    // 売り時
    if (A[i] > A[i + 1]) {
      while (KABU > 0) {
        KABU--;
        MONEY += A[i];
      }
      continue;
    }
  }
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, a[88], dp[88];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  dp[0] = 1000;
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (int j = 1; j < i; j++) {
      int tmp = dp[j - 1] / a[j];
      dp[i] = max(dp[i], tmp * a[i] + dp[j - 1] % a[j]);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define N 100
int a[N], dp[N][10000];
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 1000;
  for (int i = 0; i <= 1000 / a[1]; i++) {
    dp[1][i] = 1000 - a[1] * i;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 10000; j++) {
      if (dp[i][j] >= 0) {
        for (int k = 0; k <= dp[i][j] / a[i + 1]; k++) {
          dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] - k * a[i + 1]);
        }
        for (int k = 1; k <= j; k++) {
          dp[i + 1][j - k] = max(dp[i + 1][j - k], dp[i][j] + k * a[i + 1]);
        }
      }
    }
  }
  printf("%d\\n", dp[n][0]);
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100;
int a[N];
int main() {
  LL n = 0, num = 1000, num1 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1])
      num1 += num / a[i], num %= a[i];
    else
      num += num1 * a[i], num1 = 0;
  }
  printf("%lld", num);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100;
int a[N];
int main() {
  LL n, num = 1000, num1 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1])
      num1 += num / a[i], num %= a[i];
    else
      num += num1 * a[i], num1 = 0;
  }
  printf("%lld", num);
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll tmp = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      ll cnt = tmp / a[i];
      tmp -= cnt * a[i];
      tmp += cnt * a[i + 1];
      // cout << tmp << endl;
    }
  }
  cout << tmp << endl;
}


Error: TLE

Fixed submission:

// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll tmp = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      ll cnt = 0;
      while (tmp >= a[i]) {
        tmp -= a[i];
        cnt++;
      }
      tmp += cnt * a[i + 1];
      // cout << tmp << endl;
    }
  }
  cout << tmp << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int a[86];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int sum = 1000, stk = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < a[i + 1]) {
      stk += sum / a[i];
      sum = sum - (sum / a[i] * a[i]);
    } else {
      sum += stk * a[i];
      stk = 0;
    }
  }
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int a[86];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int sum = 1000, stk = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < a[i + 1]) {
      while (sum > 0) {
        if (sum - a[i] >= 0) {
          sum -= a[i];
          stk++;
        } else {
          break;
        }
      }
    } else {
      sum += stk * a[i];
      stk = 0;
    }
  }
  cout << sum << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 82;

int n, a[N];
long long dp[N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  dp[0] = 1000;
  for (int i = 1; i <= n; ++i) {
    dp[i] = dp[i - 1];
    for (int j = 1; j < i; ++j)
      if (a[j] < a[i]) {
        long long cur = dp[j - 1];
        dp[i] = max(dp[i], a[i] * (cur / a[j]) + cur % a[j]);
      }
  }
  cout << dp[n] << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 82;
const int M = 100010;

int n, a[N], dp[N][M];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int j = 0; j < M; ++j) {
    dp[n + 1][j] = j;
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 0; j < M; ++j) {
      dp[i][j] = dp[i + 1][j];
      int buy = j / a[i], rem = j % a[i];
      if (buy) {
        for (int k = i + 1; k <= n; ++k)
          if (a[i] < a[k]) {
            dp[i][j] = max(dp[i][j], dp[k + 1][buy * a[k] + rem]);
          }
      }
    }
  }
  cout << dp[1][1000] << '\\n';
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  int n, i, j, k;
  cin >> n;
  vector<int> a(n, 0);
  j = 0;
  for (i = 0; i < n; i++) {
    cin >> a.at(j);
    if (j == 0 || a.at(j) != a.at(j - 1)) {
      j++;
    }
  }
  n = j;
  if (n == 1) {
    cout << 1000 << endl;
    return 0;
  }
  /*for(i=0;i<n;i++){
    cout << a.at(i) << endl;
  }*/
  vector<int> vl(n), mt(n);
  j = 0;
  k = 0;
  if (a.at(0) < a.at(1)) {
    vl.at(0) = a.at(0);
    j = 1;
  }
  for (i = 1; i < n - 1; i++) {
    if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) {
      mt.at(k) = a.at(i);
      k++;
    } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) {
      vl.at(j) = a.at(i);
      j++;
    }
  }

  if (a.at(n - 1) > a.at(n - 2)) {
    mt.at(k) = a.at(n - 1);
    k++;
  }

  /*for(i=0;i<k;i++){
    cout << vl.at(i) << " " << mt.at(i) << endl;
  }*/

  ll money = 1000;
  for (i = 0; i < k; i++) {
    money += (money / vl.at(i)) * (mt.at(i) - vl.at(i));
  }
  cout << money << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  int n, i, j, k;
  cin >> n;
  vector<int> a(n, 0);
  j = 0;
  for (i = 0; i < n; i++) {
    cin >> a.at(j);
    if (j == 0 || a.at(j) != a.at(j - 1)) {
      j++;
    }
  }
  n = j;
  /*for(i=0;i<n;i++){
    cout << a.at(i) << endl;
  }*/
  vector<int> vl(n), mt(n);
  j = 0;
  k = 0;
  if (a.at(0) < a.at(1)) {
    vl.at(0) = a.at(0);
    j = 1;
  }
  for (i = 1; i < n - 1; i++) {
    if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) {
      mt.at(k) = a.at(i);
      k++;
    } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) {
      vl.at(j) = a.at(i);
      j++;
    }
  }

  if (a.at(n - 1) > a.at(n - 2)) {
    mt.at(k) = a.at(n - 1);
    k++;
  }

  /*for(i=0;i<k;i++){
    cout << vl.at(i) << " " << mt.at(i) << endl;
  }*/

  ll money = 1000;
  for (i = 0; i < k; i++) {
    money += (money / vl.at(i)) * (mt.at(i) - vl.at(i));
  }
  cout << money << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 85;

int arr[maxr];
int32_t main() {
  GO;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  int yan = 1000;
  int stock = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i - 1] < arr[i]) {
      // int times = 0;
      // while (arr[i - 1] * times <= yan)
      // 	times++;
      int times = (yan / arr[i - 1]);
      yan -= arr[i - 1] * times;
      stock += times;
      // while (stock > 0)
      // 	yan += arr[i], stock--;
      yan += (arr[i] * stock);
      stock = 0;
    }
  }
  cout << yan << endl;
  return 0;
}

//!

Error: TLE

Fixed submission:

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 85;

int arr[maxr];
int32_t main() {
  GO;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];

  int yan = 1000;
  int stock = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i - 1] < arr[i]) {
      int times = 0;
      while (arr[i - 1] * times <= yan)
        times++;
      times--;
      yan -= arr[i - 1] * times;
      stock += times;
      while (stock > 0)
        yan += arr[i], stock--;
    }
  }
  cout << yan << endl;
  return 0;
}

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

#include <cstdio>
#include <iostream>
using namespace std;
#define int long long
int a[10001];
int t, n, m;
int ans, sum;
signed main() {
  scanf("%lld", &t);
  ans = 1000;
  for (int i = 1; i <= t; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i < t; i++) {
    sum = 0;
    if (a[i] < a[i + 1])
      sum = ans / a[i];
    ans += (a[i + 1] - a[i]) * sum;
  }
  printf("%lld", ans);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
#define int long long
int f[200000001], a[10001];
int t, n, m;
int ans, sum;
signed main() {
  scanf("%lld", &t);
  ans = 1000;
  for (int i = 1; i <= t; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i < t; i++) {
    for (int j = 1; j <= ans; j++)
      f[j] = -0x3fffffff;
    f[ans] = ans;
    sum = 0;
    for (int k = ans; k >= a[i]; k--)
      f[k - a[i]] = f[k - a[i]] < f[k] + a[i + 1] - a[i]
                        ? f[k] + a[i + 1] - a[i]
                        : f[k - a[i]],
            sum = sum < f[k - a[i]] ? f[k - a[i]] : sum;
    ans = ans < sum ? sum : ans;
  }
  printf("%d", ans);
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
using ll = long long;
const int N = 85;
int a[N];

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);

  ll m = 1000;
  ll now = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i + 1] == a[i])
      continue;
    if (a[i + 1] > a[i]) {
      now += m / a[i];
      m %= a[i];
    } else {
      m += now * a[i];
      now = 0;
    }
  }

  printf("%lld\\n", m);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
const int N = 85;
int a[N];
int p;
int res;
// 钱，当前天，手中股票
void dfs(int m, int u, int n) {
  if (u > p) {
    res = max(res, m);
    return;
  }
  for (int i = 1; i * a[u] <= m; ++i) {
    dfs(m - i * a[u], u + 1, n + i);
  }

  for (int i = 1; i <= n; ++i) {
    dfs(m + i * a[u], u + 1, n - i);
  }
  dfs(m, u + 1, n);
}

int main() {
  scanf("%d", &p);

  for (int i = 1; i <= p; ++i)
    scanf("%d", &a[i]);

  dfs(1000, 1, 0);

  printf("%d\\n", res);

  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

void buystock(int &a, ll &money, ll &cnt) {
  cnt += money / a;
  money -= (money / a) * a;
}

void sellstock(int &a, ll &money, ll &cnt) {
  money += a * cnt;
  cnt = 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i];
  ll money = 1000;
  ll cnt = 0;
  rep(i, n) {
    if (a[i] < a[i + 1])
      buystock(a[i], money, cnt);
    else if (a[i] > a[i + 1])
      sellstock(a[i], money, cnt);
  }
  cout << money << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

void buystock(int &a, ll &money, ll &cnt) {
  while (money >= a) {
    money -= a;
    cnt++;
  }
}

void sellstock(int &a, ll &money, ll &cnt) {
  while (cnt > 0) {
    money += a;
    cnt--;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i];
  ll money = 1000;
  ll cnt = 0;
  rep(i, n) {
    if (a[i] < a[i + 1])
      buystock(a[i], money, cnt);
    if (a[i] > a[i + 1])
      sellstock(a[i], money, cnt);
  }
  cout << money << endl;

  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define maxn 200001
#define int ll
int N, K;

int A[100], mn[100], mx[100];

int32_t main() {
  fast;
  cin >> N;
  FOR(i, 1, N) cin >> A[i];

  int mon = 1000;

  FOR(i, 1, N - 1) {
    if (A[i + 1] > A[i]) { // Sell
      mon += (A[i + 1] - A[i]) * (mon / A[i]);
    }
  }
  cout << mon;
}


Error: -11

Fixed submission:



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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
int N, K;

int dp[81][1000][1000];
int A[100];

int dpf(int i, int j, int k) {
  if (i == N + 1)
    return k;
  if (dp[i][j][k] != -1)
    return dp[i][j][k];
  return dp[i][j][k] = max({dpf(i + 1, j + k / A[i], k % A[i]), // Buy
                            dpf(i + 1, j, k), dpf(i + 1, 0, k + j * A[i]), k});
}
int32_t main() {
  fast;
  cin >> N;
  FOR(i, 1, N) cin >> A[i];
  mem(dp, -1);
  cout << dpf(1, 0, 1000);
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

/*define*/
#define rep(i, n) for (int i = 0; i < n; ++i)
#define endl "\\n"
typedef long long ll;

const long long mod = 1e18;
const long long INF = 1e9;
ll ci;

// dx[5] = {-1, 0, 1, 0, 0};
// dy[5] = {0, 1, 0, -1, 0};
// 1行目を辞書順で繰り返す
// for(int i=0; i<1<<n; ++i){}
// 2進数を入力
// for(int j=0; j<n; ++j) g[0][i] = (i>>j)&1==1;

/*unique文字の確認
    set<int> all;
    all.insert(a[i]);
    map<int, int> count;
    count[a[i++]]++;
    if(count[a[j++]]++==0) num++;
*/
// typedef pair<int, int> P;

// 配列
// vector<long long> v(max_n);
// vector<int> v[max_n];
// vector<vector<int>> v(max_n);
// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; 降順;
// priority_queue<pair<int, int>, vector<pair<int, int>>, less<>> q; 昇順;

// tips
// 最大値の最小化は２分探索
// printf("IMPOSSIBLE"\\n);
// printf("%d%c", opt[i][j], j+1==N? \\n : '');

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];
  vector<ll> dp(n + 1);
  dp[0] = 1000;
  for (int k = 1; k <= n; ++k) {
    dp[k] = 0;
    for (int i = 0; i < k - 1; ++i) {
      int m = 99999;
      for (int j = i + 1; j < k; j++) {
        m = min(m, a[j]);
      }
      dp[k] = max(dp[k], dp[i] / m * a[k] + dp[i] % m);
    }
  }
  ll ans = 0;
  rep(i, n + 1) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

/*define*/
#define rep(i, n) for (int i = 0; i < n; ++i)
#define endl "\\n"
typedef long long ll;

const long long mod = 1e18;
const long long INF = 1e9;
int ci;

// dx[5] = {-1, 0, 1, 0, 0};
// dy[5] = {0, 1, 0, -1, 0};
// 1行目を辞書順で繰り返す
// for(int i=0; i<1<<n; ++i){}
// 2進数を入力
// for(int j=0; j<n; ++j) g[0][i] = (i>>j)&1==1;

/*unique文字の確認
    set<int> all;
    all.insert(a[i]);
    map<int, int> count;
    count[a[i++]]++;
    if(count[a[j++]]++==0) num++;
*/
// typedef pair<int, int> P;

// 配列
// vector<long long> v(max_n);
// vector<int> v[max_n];
// vector<vector<int>> v(max_n);
// priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; 降順;
// priority_queue<pair<int, int>, vector<pair<int, int>>, less<>> q; 昇順;

// tips
// 最大値の最小化は２分探索
// printf("IMPOSSIBLE"\\n);
// printf("%d%c", opt[i][j], j+1==N? \\n : '');

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i + 1];
  vector<ll> dp(n + 1);
  dp[0] = 1000;
  for (int k = 1; k <= n; ++k) {
    dp[k] = 0;
    for (int i = 0; i < k - 1; ++i) {
      int m = 99999;
      for (int j = i + 1; j < k; j++) {
        m = min(m, a[j]);
      }
      dp[k] = max(dp[k], dp[i] / m * a[k] + dp[i] % m);
    }
  }
  ll ans = 0;
  rep(i, n + 1) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}