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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;

  long long money = 1000;
  long long stock = 0;

  vector<int> A(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]) {
      stock += money / A[i];
      money -= money / A[i] * A[i];

    } else if (A[i] > A[i + 1]) {
      money += stock * A[i];
      stock = 0;
    }
  }

  money += stock * A[N - 1];
  stock = 0;

  cout << money << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;

  long long money = 1000;
  long long stock = 0;

  vector<int> A(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]) {
      while (money >= A[i]) {
        money -= A[i];
        stock += 1;
      }
    } else if (A[i] > A[i + 1]) {
      while (stock > 0) {
        money += A[i];
        stock -= 1;
      }
    }
  }

  while (stock > 0) {
    money += A[N - 1];
    stock -= 1;
  }

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

// Template
#include <algorithm>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmax(T &x, const T &y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}

// Main Code
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll now = 1000, k = 0;
  rep(i, n - 1) {
    if (a[i] < a[i + 1]) {
      k += now / a[i];
      now %= a[i];
    }
    if (a[i] > a[i + 1]) {
      now += k * a[i];
      k = 0;
    }
  }

  now += k * a[n - 1];
  cout << now << "\\n";
  return;
}


Error: 0

Fixed submission:

// Template
#include <algorithm>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmax(T &x, const T &y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}

// Main Code
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<vector<int>> dp(n + 1, vector<int>(2000, -1));
  dp[0][0] = 1000;
  rep(i, n) rep(j, 2000) {
    if (dp[i][j] == -1)
      continue;
    chmax(dp[i + 1][j], dp[i][j]);
    rep(k, j) chmax(dp[i + 1][k], dp[i][j] + (j - k) * a[i]);
    rep(k, dp[i][j] / a[i])
        chmax(dp[i + 1][j + k + 1], dp[i][j] - (k + 1) * a[i]);
  }

  int ans = 0;
  rep(i, 2000) chmax(ans, dp[n][i]);
  cout << ans << "\\n";
  return;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  // your code goes here
  long long n;
  cin >> n;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    long long b;
    cin >> b;
    a.push_back(b);
  }

  long long num = 0;
  long long money = 1000;
  decltype(a)::iterator result = std::unique(a.begin(), a.end());

  // [v.begin(), result)の範囲に、重複を除いた結果が入っている。
  // 不要になった要素を削除
  a.erase(result, a.end());

  if (a.size() == 1) {
    cout << money << endl;
    return 0;
  }

  // 折り返し地点を探す
  string turn[a.size()];
  for (int i = 1; i < a.size() - 1; i++) {
    if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) {
      turn[i] = "down";
    } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) {
      turn[i] = "up";
    } else {
      turn[i] = "keep";
    }
  }

  if (a.at(0) < a.at(1)) {
    num += money / a.at(0);
    money %= a.at(0);
  }

  for (int i = 0; i < a.size() - 1; i++) {
    if (turn[i] == "down") {
      money += a.at(i) * num;
      num = 0;
    } else if (turn[i] == "up") {
      num += money / a.at(i);
      money %= a.at(i);
    }
  }

  if (a.at(a.size() - 2) < a.at(a.size() - 1)) {
    money += a.at(a.size() - 1) * num;
    num = 0;
  }

  cout << money << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  // your code goes here
  long long n;
  cin >> n;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    long long b;
    cin >> b;
    a.push_back(b);
  }

  long long num = 0;
  long long money = 1000;
  decltype(a)::iterator result = std::unique(a.begin(), a.end());

  // [v.begin(), result)の範囲に、重複を除いた結果が入っている。
  // 不要になった要素を削除
  a.erase(result, a.end());

  // 折り返し地点を探す
  string turn[a.size()];
  for (int i = 1; i < a.size() - 1; i++) {
    if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) {
      turn[i] = "down";
    } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) {
      turn[i] = "up";
    } else {
      turn[i] = "keep";
    }
  }

  if (a.at(0) < a.at(1)) {
    num += money / a.at(0);
    money %= a.at(0);
  }

  for (int i = 0; i < a.size() - 1; i++) {
    if (turn[i] == "down") {
      money += a.at(i) * num;
      num = 0;
    } else if (turn[i] == "up") {
      num += money / a.at(i);
      money %= a.at(i);
    }
  }

  if (a.at(a.size() - 2) < a.at(a.size() - 1)) {
    money += a.at(a.size() - 1) * num;
    num = 0;
  }

  cout << money << endl;

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

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

void solve() {

  int n;
  cin >> n;
  ll a[n];
  for (ll &u : a) {
    cin >> u;
  }
  int L = 0;
  ll money = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      money = money / a[L] * a[i] + money % a[L];
      L = i + 1;
    }
  }
  money = money / a[L] * a[n - 1] + money % a[L];
  cout << money << '\\n';
}

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

  boost;

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x, y) make_pair((x), (y))
#define boost                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

const int N = 85;

map<int, int> dp[N];

void solve() {

  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  dp[0][0] = 1000;
  for (int i = 1; i <= n; i++) {
    for (auto u : dp[i - 1]) {
      int money = u.ss, stock = u.ff;
      for (int buy = 0; money - buy * a[i] >= 0; buy++) {
        dp[i][stock + buy] = max(dp[i][stock + buy], money - buy * a[i]);
      }
      for (int sell = 0; sell <= stock; sell++) {
        dp[i][stock - sell] = max(dp[i][stock - sell], money + sell * a[i]);
      }
    }
  }
  int ans = 1000;
  for (auto u : dp[n]) {
    ans = max(ans, u.ss);
  }
  cout << ans << '\\n';
}

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

  boost;

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    // cout << "Case #" << i << ": ";

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

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int MAXP = 800000;
int dp[MAXP + 10];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  ll x = 1000;
  for (int i = 0; i + 1 < N; i++) {
    if (A[i] < A[i + 1]) {
      ll d = x / A[i];
      x = (x % A[i]) + d * A[i + 1];
    }
  }
  cout << x << endl;
  return 0;
}


Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int MAXP = 800000;
int dp[MAXP + 10];

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  int x = 1000;
  for (int i = 0; i + 1 < N; i++) {
    for (int j = 0; j <= x; j++)
      dp[j] = j;
    for (int k = 0; k <= x; k++)
      if (k - A[i] >= 0)
        chmax(dp[k], dp[k - A[i]] + A[i + 1]);
    int y = 0;
    for (int j = 0; j <= x; j++)
      chmax(y, dp[j]);
    x = y;
  }
  cout << x << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long money = 1000;
  for (int i = 1; i < N; i++) {
    if (A[i - 1] < A[i]) {
      money = money / A[i - 1] * A[i] + money % A[i - 1];
    }
  }
  cout << money << endl;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long money = 1000, stock = 0;
  for (int i = 1; i < N; i++) {
    if (A[i - 1] < A[i]) {
      while (money >= A[i - 1]) {
        money -= A[i - 1];
        stock++;
      }
      while (stock > 0) {
        stock--;
        money += A[i];
      }
    }
  }
  cout << money << endl;
}
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 sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
constexpr int INF = 2e9;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<map<ll, ll>> dp(n + 1);

  dp[0][0] = 1000;

  for (int i = 0; i < n; i++) {
    for (auto v : dp[i]) {
      ll j = v.second / a[i];
      dp[i + 1][v.first] = max(dp[i][v.first], dp[i + 1][v.first]);
      dp[i + 1][0] = max(dp[i + 1][0], dp[i][v.first] + v.first * a[i]);
      dp[i + 1][j] = max(dp[i + 1][j], v.second - j * a[i]);
    }
  }
  cout << dp[n][0] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
constexpr int INF = 2e9;
constexpr int M = 80010;
constexpr int A = 810;

int dp[M][A];
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  dp[1000][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < M; j++) {
      for (int k = A - 1; k >= 0; k--) {
        if (j + a[i] < M && k - 1 >= 0)
          dp[j + a[i]][k - 1] |= dp[j][k];
      }
    }

    for (int j = M - 1; j >= 0; j--) {
      for (int k = 0; k < A; k++) {
        if (j - a[i] >= 0 && k + 1 < A)
          dp[j - a[i]][k + 1] |= dp[j][k];
      }
    }
  }
  int res = 0;

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < A; j++)
      if (dp[i][j])
        res = max(res, i);
  }
  cout << res << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define FAST                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll, ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\\n"
using namespace std;

int main() {
  FAST ll mon = 1000, st = 0;
  ll n;
  cin >> n;
  ll a[n];
  f(i, 0, n) cin >> a[i];
  ll start = 0;
  while (start < n - 1 && a[start] >= a[start + 1])
    start++;
  if (start == n - 1) {
    cout << 1000 << endl;
    return 0;
  }
  while (mon - a[start] >= 0)
    mon -= a[start], st++;
  ll pos = start + 1;
  while (1) {
    while (pos < n - 1 && a[pos] <= a[pos + 1])
      pos++;
    while (st)
      mon += a[pos], st--;
    while (pos < n - 1 && a[pos] >= a[pos + 1])
      pos++;
    if (pos != n - 1) {
      st += mon / a[pos];
      mon -= st * a[pos];
    } else if (pos >= n - 1)
      break;
  }
  cout << mon << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define FAST                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll, ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\\n"
using namespace std;

int main() {
  FAST ll mon = 1000, st = 0;
  ll n;
  cin >> n;
  ll a[n];
  f(i, 0, n) cin >> a[i];
  ll start = 0;
  while (start < n - 1 && a[start] >= a[start + 1])
    start++;
  if (start == n - 1) {
    cout << 1000 << endl;
    return 0;
  }
  while (mon - a[start] >= 0)
    mon -= a[start], st++;
  ll pos = start + 1;
  while (1) {
    while (pos < n - 1 && a[pos] <= a[pos + 1])
      pos++;
    while (st)
      mon += a[pos], st--;
    while (pos < n - 1 && a[pos] >= a[pos + 1])
      pos++;
    if (pos != n - 1) {
      while (mon - a[pos] >= 0)
        mon -= a[pos], st++;
    } else if (pos >= n - 1)
      break;
  }
  cout << mon << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie();                                                                   \\
  cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll long long
#define mod 1000000007

int main() {
  FAST;
  ll n;
  ll x = 1000;
  cin >> n;
  ll a[n + 4];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  a[n] = -1;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j <= n; j++) {
      if (a[j] < a[j - 1]) {
        ll c = x / a[i];
        x += ((a[j - 1] - a[i]) * c);
        i = j - 1;
        break;
      }
    }
  }

  cout << x;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie();                                                                   \\
  cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll long long int
#define mod 1000000007

int main() {
  FAST;
  ll n;
  ll x = 1000;
  cin >> n;
  ll a[n + 4];
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<int, int>> v;
  ll k = 0;
  ;
  ll z = 0;
  bool fl = true;
  for (ll i = 0; i < n; i++) {
    if (a[i] > a[i + 1]) {
      fl = false;

      v.push_back({a[z], a[i]});
      z = i + 1;

      k++;
    }
  }
  if (fl == true) {
    v.push_back({a[0], a[n - 1]});
    k++;
  } else if (a[z] < a[n - 1]) {
    v.push_back({a[z], a[n - 1]});
    k++;
  }
  ll y;
  for (ll i = 0; i < k; i++) {
    y = x / v[i].first;
    x -= y * v[i].first;
    x += y * v[i].second;
  }
  cout << x;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int money = 1000;
  vector<int> s(0);
  vector<int> e(0);
  bool bye = false;
  for (int i = 0; i < n; i++) {

    if (i == 0) {
      if (a[i] < a[i + 1]) {
        s.push_back(0);
        bye = true;
      }
      continue;
    }
    if (i == n - 1) {
      e.push_back(i);
      break;
    }
    if (a[i] < a[i + 1] && bye == false) {
      s.push_back(i);
      bye = true;
    }
    if (a[i] > a[i + 1] && bye == true) {
      e.push_back(i);
      bye = false;
    }
  }
  int l = s.size();
  for (int i = 0; i < l; i++) {
    long long int t = money / a[s[i]];
    money %= a[s[i]];
    money += a[e[i]] * t;
  }
  cout << money;
}


Error: WA

Fixed submission:

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

int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int money = 1000;
  vector<int> s(0);
  vector<int> e(0);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] < a[i + 1]) {
        s.push_back(0);
      }
      continue;
    }
    if (i == n - 1) {
      e.push_back(i);
      break;
    }
    if (a[i] < a[i + 1] && a[i] <= a[i - 1]) {
      s.push_back(i);
    }
    if (a[i] > a[i + 1] && a[i] >= a[i - 1]) {
      e.push_back(i);
    }
  }
  auto l = s.size();
  for (int i = 0; i < l; i++) {
    long long int t = money / a[s[i]];
    money %= a[s[i]];
    money += a[e[i]] * t;
  }
  cout << money;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define all(v) (v).begin(), (v).end()
using namespace std;

std::vector<ll> v;
void solve() {
  ll n;
  cin >> n;
  v.resize(n);
  for (auto &i : v)
    cin >> i;
  ll m = 1000, x;
  for (int i = 0; i + 1 < n; i++) {
    x = m / v[i];
    m += max(x * (v[i + 1] - v[i]), 0ll);
  }
  cout << m;
}

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

  int TESTS = 1;
  // cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\\n'
#define pii pair<ll int, ll int>
#define all(v) (v).begin(), (v).end()
using namespace std;

std::vector<ll> v;
ll dp[81][20][5000];
ll get(ll id, ll s, ll m) {
  if (m < 0 || s < 0)
    return INT_MIN;

  if (id == v.size() - 1)
    return m + s * v[id];

  if (dp[id][s][m] != -1)
    return dp[id][s][m];

  ll ans = INT_MIN;
  for (int i = 0; i <= m / v[id]; i++)
    ans = max(ans, get(id + 1, s + i, m - i * v[id]));
  for (int j = 0; j <= s; j++)
    ans = max(ans, get(id + 1, s - j, m + j * v[id]));
  return dp[id][s][m] = ans;
}
void solve() {
  ll n;
  cin >> n;
  v.resize(n);
  for (auto &i : v)
    cin >> i;
  memset(dp, -1, sizeof dp);
  cout << get(0, 0, 1000);
}

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

  int TESTS = 1;
  // cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll money = 1000, kabu = 0;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n - 1) {
    if (a[i] < a[i + 1]) {
      kabu = money / a[i];
      money %= a[i];
      money += kabu * a[i + 1];
    }
  }
  cout << money << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ll money = 1000, kabu = 0;
  int n;
  cin >> n;
  vector<int> a(n + 1);
  repi(i, 1, n + 1) cin >> a[i];
  a[0] = 300, a[n + 1] = 0;
  repi(i, 1, n) {
    if (a[i - 1] < a[i] && a[i] >= a[i + 1]) {
      money += kabu * a[i];
      kabu = 0;
    } else if (a[i - 1] > a[i] && a[i] <= a[i + 1]) {
      kabu = money / a[i];
      money = money % a[i];
    }
  }
  cout << money << endl;
}