alexjercan/bugnet huggingface dataset:
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;

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

  ll money = 1000, s = 0;

  REP(i, n - 1) {
    if (a[i + 1] - a[i] <= 0)
      continue;
    s = money / a[i];
    money -= s * a[i];
    money += s * (a[i + 1]);
  }
  cout << money << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;

int n;
vector<int> a;
int dp[100] = {};
int diff[100] = {};

void make(int d) {

  int k = dp[d - 1] / a[d - 1] * diff[d - 1] + dp[d - 1];
  dp[d] = max(dp[d - 1], k);
  FORB(i, 2, d) {
    int sum = 0;
    REP(j, i) { sum += diff[d - i + j]; }
    k = dp[d - i] / a[d - i] * sum + dp[d - i];
    dp[d] = max(dp[d], k);
  }
  // cout << d << "* " << k << endl;
  if (d < n)
    make(d + 1);
}
int main() {

  dp[0] = 1000;
  cin >> n;
  REP(i, n) {
    int t;
    cin >> t;
    a.pb(t);
  }

  FOR(i, 0, n - 1) { diff[i] = a[i + 1] - a[i]; }
  make(1);
  cout << dp[n] << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Micro Futures scalping to get my tendies
vector<ll> v;
ll n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    v.push_back(x);
  }
  ll amt = 1000;
  ll ma = v[0], mi = v[0];
  for (int i = 1; i < n; i++) {
    if (v[i] < v[i - 1]) {
      ll bal = amt / mi;
      bal = (amt - (bal * mi)) + (bal * ma);
      amt = bal;
      mi = ma = v[i];
    } else {
      mi = min(mi, v[i]);
      ma = max(ma, v[i]);
    }
  }
  ll bal = amt / mi;
  bal = (amt - (bal * mi)) + (bal * ma);
  amt = bal;
  cout << amt << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Micro Futures scalping to get my tendies
vector<int> v;
int ma = 0;
int n;
void dfs(int i, int amt, int stock) {
  if (i >= n) {
    ma = max(ma, amt);
    return;
  }
  int stonks = stock;
  int mon = amt;
  if (!stock) {
    stock = (amt / v[i]);
    amt = amt - (stock * v[i]);
  } else {
    amt += (stock * v[i]);
    stock = 0;
  }
  dfs(i + 1, amt, stock);
  dfs(i + 1, mon, stonks);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  dfs(0, 1000, 0);
  dfs(0, 1000, 0);
  cout << ma << "\\n";
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  ll n;
  cin >> n;
  vector<ll> trade;
  bool ud = true;
  ll temp = 1000;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ud) { // 谷探し
      if (a <= temp)
        temp = a;
      else {
        ud = false;
        trade.push_back(temp);
        temp = a;
      }
    } else { // 山探し
      if (a >= temp)
        temp = a;
      else {
        ud = true;
        trade.push_back(temp);
        temp = a;
      }
    }
  }
  if (!ud)
    trade.push_back(temp);
  ll money = 1000;
  ll m = trade.size() / 2;
  rep(i, m) {
    money += (money / trade[i * 2]) * (trade[i * 2 + 1] - trade[i * 2]);
  }
  cout << money << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> trade;
  bool ud = true;
  int temp = 1000;
  rep(i, n) {
    int a;
    cin >> a;
    if (ud) { // 谷探し
      if (a <= temp)
        temp = a;
      else {
        ud = false;
        trade.push_back(temp);
        temp = a;
      }
    } else { // 山探し
      if (a >= temp)
        temp = a;
      else {
        ud = true;
        trade.push_back(temp);
        temp = a;
      }
    }
  }
  if (trade.back() < temp)
    trade.push_back(temp);
  int money = 1000;
  int m = trade.size() / 2;
  rep(i, m) {
    money += (money / trade[i * 2]) * (trade[i * 2 + 1] - trade[i * 2]);
  }
  cout << money << endl;

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

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 62;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  ll ans = 1000;
  rep(i, N - 1) {
    // 翌日の方が株価が高い場合
    if (A[i] < A[i + 1]) {
      // 当日に株を買い、翌日に売る。
      ll count = ans / A[i];
      ans %= A[i];
      ans += count * A[i + 1];
    }
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;

const ll INF = 1LL << 62;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

vector<int> A;
int ans = 0;
int N;
void dfs(int count, int money, int day, int lastbuy, int lastsell) {
  ans = max(ans, money);
  // cout << day << endl;
  if (day == N)
    return;
  dfs(count, money, day + 1, lastbuy, lastsell);
  int mc = count;
  int m = money;
  if (lastsell > A[day] && m > A[day]) {
    int buy_count = m / A[day];
    dfs(count + buy_count, money - A[day] * buy_count, day + 1, A[day],
        lastsell);
  }
  /*
  while(m > A[day]){
      m -= A[day];
      mc++;
      dfs(mc, m, day+1);
  }
  */
  /*
  int sc = count;
  int sm = money;
  */
  if (lastbuy < A[day] && count > 0) {
    // int sell_count = sc;
    dfs(0, money + A[day] * count, day + 1, lastbuy, A[day]);
  }
  /*
  while(sc > 0){
      sm += A[day];
      sc--;
      dfs(sc, sm, day+1);
  }
  */
}

int main() {
  cin >> N;
  A.assign(N, 0);
  rep(i, N) cin >> A[i];

  int money = 1000;

  dfs(0, money, 0, 0, 100000);

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

#include <algorithm>
#include <iomanip> // std::setprecision()
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */

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

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <algorithm>
#include <iomanip> // std::setprecision()
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 1, n + 1) { cin >> a[i]; }
  vector<ll> dp(n + 1);
  dp[1] = 1000;
  rep(i, 2, n + 1) {
    dp[i] = dp[i - 1];
    rep(j, 1, i) {
      ll c = dp[j] / a[j];
      ll m = dp[j] + (a[i] - a[j]) * c;
      dp[i] = max(dp[i], m);
    }
  }
  cout << dp[n] << endl;
  ;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\\n"
#define debug2(x, y)                                                           \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\\n"
#define debug3(x, y, z)                                                        \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \\
            << ": " << z << "\\n"

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

int main() {
  int n;
  int a[100];
  ll mo = 1000, st = 0;

  scanf("%d", &n);
  rep(i, n) { scanf("%lld", &a[i]); }

  rep(i, n) {
    if (i == 0) {
      if (a[0] < a[1]) {
        st = mo / a[0];
        mo -= st * a[0];
      }
    } else if (i == n - 1) {
      if (st == 0)
        break;
      mo += st * a[i];
      st = 0;
    } else {
      if (a[i - 1] <= a[i] && a[i] > a[i + 1]) {
        if (st == 0)
          continue;
        mo += st * a[i];
        st = 0;
      } else if (a[i - 1] >= a[i] && a[i] < a[i + 1]) {
        if (st > 0)
          continue;
        st = mo / a[i];
        mo -= st * a[i];
      }
    }
  }

  printf("%lld", mo);

  return 0;
}


Error: TLE

Fixed submission:

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

#define rep(ver, n) rep2(ver, 0, n)
#define rep2(ver, m, n) for (int ver = m; ver < (n); ver++)
#define loop while (true)
#define dup(x, y) (((x) + (y)-1) / (y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr << #x << ": " << x << "\\n"
#define debug2(x, y)                                                           \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\\n"
#define debug3(x, y, z)                                                        \\
  std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z        \\
            << ": " << z << "\\n"

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

int main() {
  ll n, mo = 1000, st = 0;
  ll a[100];

  scanf("%d", &n);
  rep(i, n) { scanf("%d", &a[i]); }

  rep(i, n) {
    if (i == 0) {
      if (a[0] < a[1]) {
        st = mo / a[0];
        mo -= st * a[0];
      }
    } else if (i == n - 1) {
      if (st == 0)
        break;
      mo += st * a[i];
      st = 0;
    } else {
      if (a[i - 1] <= a[i] && a[i] > a[i + 1]) {
        if (st == 0)
          continue;
        mo += st * a[i];
        st = 0;
      } else if (a[i - 1] >= a[i] && a[i] < a[i + 1]) {
        if (st > 0)
          continue;
        st = mo / a[i];
        mo -= st * a[i];
      }
    }
  }

  printf("%d", mo);

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

#include <bits/stdc++.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);
#define endl '\\n'
#define ll long long int
#define pb push_back
#define sz(x) (int)(x).size()
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * 1LL * a) % mod;
    b >>= 1LL;
    a = (a * 1LL * a) % mod;
  }
  return res;
}

//--------------------------------------------------------------------------------------------------------------------------//

int n;
ll a[100];
ll dp[100];

int main() {
  fast
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  dp[1] = 1000;

  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (int j = 1; j < i; j++) {
      dp[i] = max(dp[i], dp[j] + ((dp[j] / a[j]) * (a[i] - a[j])));
    }
  }
  cout << dp[n] << endl;

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
#define fast                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);
#define endl '\\n'
#define ll long long int
#define pb push_back
#define sz(x) (int)(x).size()
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll powm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * 1LL * a) % mod;
    b >>= 1LL;
    a = (a * 1LL * a) % mod;
  }
  return res;
}

//--------------------------------------------------------------------------------------------------------------------------//

int n;
int a[100];
int dp[81][20005][200];

int solve(int day, int rs, int st) {
  if (day == n + 1)
    return rs;
  if (dp[day][rs][st] != -1) {
    return dp[day][rs][st];
  }
  dp[day][rs][st] = 0;
  int canbuy = rs / a[day];

  for (int i = 0; i <= canbuy; i++) {
    dp[day][rs][st] =
        max(dp[day][rs][st], solve(day + 1, rs - (i * a[day]), st + i));
  }
  for (int i = 0; i <= st; i++) {
    dp[day][rs][st] =
        max(dp[day][rs][st], solve(day + 1, rs + i * a[day], st - i));
  }
  return dp[day][rs][st];
}

int main() {
  fast
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  memset(dp, -1, sizeof dp);

  cout << solve(1, 1000, 0) << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

P dp1[100], dp2[100];

int main() {

  int n;
  cin >> n;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  dp1[0] = P(1000, 0);
  dp2[0] = P(0, 1000);

  rep(i, n) {
    dp1[i + 1] = max(dp1[i], P(dp2[i].second + dp2[i].first * a[i], 0));
    dp2[i + 1] = max(dp2[i], P(dp1[i].second + dp1[i].first / a[i],
                               dp1[i].first - dp1[i].first / a[i] * a[i]));
  }
  cout << dp1[n].first << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_lr(i, l, r) for (int i = (l); i < (r); i++)
#define all(x) (x).begin(), (x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int dp[88][1010];

int main() {

  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  rep(i, n + 1) rep(j, 1010) dp[i][j] = -1;
  dp[0][0] = 1000;

  rep(i, n) rep(j, 1010) {
    if (dp[i][j] == -1)
      continue;

    for (int k = 0; dp[i][j] >= k * a[i]; k++) {
      dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] - k * a[i]);
    }
    for (int k = 1; j - k >= 0; k++) {
      dp[i + 1][j - k] = max(dp[i + 1][j - k], dp[i][j] + k * a[i]);
    }
  }
  cout << dp[n][0] << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define Rip(i, n) for (int i = 1; i <= n; i++)
#define RIP(i, a, b) for (int i = a; i < b; i++)
#define all(V) V.begin(), V.end()
#define sec setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using ll = long long;
using ld = long double;
using Pa = std::pair<ll, ll>;
using namespace std;
ll MOD = 998244353;
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll pow(ll x, ll n, ll mod) {
  x %= mod;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return (pow((x * x) % mod, n / 2, mod) % mod);
  else
    return (x * pow(x, n - 1, mod) % mod);
}
vector<ll> primess(ll n) {
  vector<ll> a;
  while (n % 2 == 0)
    n /= 2, a.push_back(2);
  ll sosuu = 3;
  while (n != 1) {
    if (n % sosuu == 0)
      n /= sosuu, a.push_back(sosuu);
    else if (sosuu > sqrt(n) + 2) {
      a.push_back(n);
      break;
    } else
      sosuu += 2;
  }
  return a;
}
signed main() {
  ll n;
  cin >> n;
  ll ans = 1000;
  vector<ll> a(n);
  rip(i, n) cin >> a[i];
  rip(i, n - 1) {
    if (a[i] < a[i + 1])
      ans += (a[i + 1] - a[i]) * (ans / a[i]);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (true)
    cout << 8194 << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
long long N, A[87], CurrentMoney = 1000;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> A[i];
  for (int i = 1; i <= N - 1; i++) {
    long long Stocks = 0;
    if (A[i] < A[i + 1])
      Stocks = CurrentMoney / A[i];
    CurrentMoney += (A[i + 1] - A[i]) * Stocks;
  }
  cout << CurrentMoney << endl;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;
typedef long long int ll;

void solve() {
  int n;
  cin >> n;
  ll a[n], ans = 1000, stocks;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      stocks = ans / a[i];
      ans += (a[i + 1] - a[i]) * stocks;
    }
  }
  cout << ans << "\\n";
}

int main() {
  int t;
  cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n;
  // int temp;
  long long syoji = 1000;
  long long kabun; // kabukin,
  // int kattaflag;
  cin >> n;
  vector<long long> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  kabun = 0;
  for (int i = 0; i < n - 1; i++) {
    long long stocks = 0;
    if (a.at(i) < a.at(i + 1)) { // 買う

      stocks = syoji / a.at(i);
    }
    syoji += (a.at(i + 1) - a.at(i)) * stocks;

    // cout << i << ":" << kabukin << endl;
  }
  cout << syoji << endl;

  return (0);
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  // int temp;
  long syoji = 1000;
  long kabun; // kabukin,
  // int kattaflag;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  // cout << "hahaha" << endl;
  /*if(a.at(0)<a.at(1)){
    kattaflag=1;//次売る
  }else{
    kattaflag=-1;//次買う
  }*/
  kabun = 0;
  // temp=0;
  // kabukin=0;

  for (int i = 0; i < n - 1; i++) {
    // temp=0;
    if (a.at(i) < a.at(i + 1)) { // 買う
      // kabukin=a.at(i);
      // kabun=0;
      while (syoji >= a.at(i)) { //(temp+=a.at(i))<=syoji){
        syoji -= a.at(i);
        kabun++;
      }
      // syoji-=a.at(i)*kabun;
      // kabun=floor(syoji/a.at(i));
      // syoji=syoji-(a.at(i)*kabun);
    } else if (a.at(i) > a.at(i + 1)) { // 売る
      while (kabun > 0) {
        syoji += a.at(i);
        kabun--;
      }
      // kabukin=0;
    }
    // cout << i << ":" << kabukin << endl;
  }
  if (kabun > 0) {
    // while(kabun>0){
    syoji = syoji + (a.at(n - 1) * kabun);
    // kabun--;
    //}
  }
  cout << syoji << endl;

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

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N = 200010; // check the limits, dummy
ll a[N];
int main() {
  int t;
  // while(){
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
  }
  ll mon = 1000, nm = 0;
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i + 1] > a[i]) {
      mon = mon % a[i] + a[i + 1] * (mon / a[i]);
    }
  }
  // memset(mem, -1, sizeof mem);
  // int ans=dp(0, 1000, 0);
  cout << mon << endl;
  // }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N = 200010; // check the limits, dummy
int a[N];
int n, m;
int mem[20010][81][81];
int dp(int x, int mon, int nm) {
  if (x == n) {
    return mon;
  }
  if (mem[mon][x][nm] != -1) {
    return mem[mon][x][nm];
  }
  int res = dp(x + 1, mon, nm);
  if (nm > 0) {
    res = max(res, dp(x + 1, mon + nm * a[x], 0));
  }
  if (mon >= a[x]) {
    res = max(res, dp(x + 1, mon % a[x], nm + mon / a[x]));
  }
  mem[mon][x][nm] = res;
  return res;
}
int main() {
  int t;
  // while(){
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  memset(mem, -1, sizeof mem);
  int ans = dp(0, 1000, 0);
  cout << ans << endl;
  // }
}