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

/*
 *  WATCH THIS
 */
#include <bits/stdc++.h>

using namespace std;
#define endl '\\n'

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll N = 1e5 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7;

void debug() { cerr << endl; }

template <typename Head, typename... Tail> void debug(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug(T...);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  ll minn = min(v[0], v[1]);
  ll x = (v[0] > v[1] ? 1 : 0);
  ll first = 1000;
  for (int i = x; i < n - 1; ++i) {
    if (v[i + 1] < v[i]) {
      ll buy = first / minn;
      first = first % minn;
      ll sells = v[i] * buy;
      first += sells;
      minn = v[i + 1];
    }
  }
  if (minn != v[n - 1]) {
    ll buy = first / minn;
    first = first % minn;
    ll sells = v[n - 1] * buy;
    first += sells;
  }
  cout << max((ll)1000, first) << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAX_N = 1e5 + 1, mod = 1e9 + 7;
int dp[89][2009][209], n;
int arr[89];
int solve(int idx, int curfee, int tosell) {
  if (idx == n)
    return curfee;

  int &ret = dp[idx][curfee][tosell];
  if (~ret)
    return ret;

  ret = solve(idx + 1, curfee, tosell);

  // sell
  int profit = tosell * arr[idx];

  // buy
  int willbuy = curfee / arr[idx];

  int left = curfee - willbuy * arr[idx];

  ret = max({ret, solve(idx + 1, curfee + profit, 0),
             solve(idx + 1, left, tosell + willbuy)});
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", arr + i);
  memset(dp, -1, sizeof(dp));
  printf("%d", solve(0, 1000, 0));
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;

ll a[100];
int main() {
  ll n, sk = 0;
  ll mn = 1000;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] <= a[i + 1] && (!i || a[i] < a[i - 1])) {
      // cout<<mn/a[i]<<' '<<a[i]<<endl;
      sk += mn / a[i];
      mn -= mn / a[i] * a[i];
    }
    while (a[i] <= a[i + 1] && i < n)
      i++;
    mn += a[i] * sk;
    // cout<<mn<<endl;
    sk = 0;
  }
  printf("%lld", mn);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;

int n, a[100], ans;

void dfs(int mn, int sk, int day) {
  if (day == n) {
    ans = max(ans, mn);
    return;
  }

  // cout<<mn<<' '<<sk<<' '<<day<<endl;
  if (day == n - 1) {
    dfs(mn + sk * a[day], 0, day + 1);
  } else {
    int t = 0;
    while (mn - a[day] * t >= 0) {
      dfs(mn - a[day] * t, sk + t, day + 1);
      t++;
    }
    t = 0;
    while (sk - t >= 0) {
      dfs(mn + a[day] * t, sk - t, day + 1);
      t++;
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  ans = 1000;
  dfs(1000, 0, 0);
  printf("%d", ans);
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

//                             ¯\\_(ツ)_/¯
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define ll long long

void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
}

const int N = 2e5 + 5, M = 2e6 + 5, MOD = 1e9 + 7, OO = 1e9;
int n;
int a[100];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // file();

  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  ll curr = 1000;

  for (int i = 1; i < n; i++) {
    if (a[i] > a[i - 1]) {
      curr = (curr / a[i - 1]) * a[i] + curr % a[i - 1];
    }
  }

  printf("%lld\\n", curr);
}

// CBA

Error: TLE

Fixed submission:

//                             ¯\\_(ツ)_/¯
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define ll long long

void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
}

const int N = 2e5 + 5, M = 2e6 + 5, MOD = 1e9 + 7, OO = 1e9;
int n;
int a[100];

map<pair<int, pair<int, int>>, int> memo;

int solve(int indx, int money, int has) {
  if (indx == n)
    return 0;
  if (memo.count({indx, {money, has}}))
    return memo[{indx, {money, has}}];
  int ret = solve(indx + 1, money, has);
  for (int i = 1; i <= has; i++) {
    int take = i * a[indx];
    ret = max(ret, solve(indx + 1, money + take, has - i) + take);
  }

  for (int i = 1; i * a[indx] <= money; i++) {
    int take = i * a[indx];
    ret = max(ret, solve(indx + 1, money - take, has + i) - take);
  }
  return memo[{indx, {money, has}}] = ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // file();

  scanf("%d", &n);

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

  printf("%d\\n", solve(0, 1000, 0) + 1000);
}

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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define arr array
#define yes                                                                    \\
  cout << "YES"                                                                \\
       << "\\n"
#define no                                                                     \\
  cout << "NO"                                                                 \\
       << "\\n"
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false)
#define out cin.tie(nullptr)
#define task "test"
#define open(task)                                                             \\
  if (fopen(task ".inp", "r")) {                                               \\
    freopen(task ".inp", "r", stdin);                                          \\
    freopen(task ".out", "w", stdout);                                         \\
  }

using namespace std;

const int maxn = 2 * 1e5 + 69;
const ll mod = 2111992;

ll a[maxn], rg[maxn];
int n;
ll dp[81][10000][100];
ll maxx = 0;

int main() {
  fast;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll ans = 1000;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i + 1]) {
      ans += (ans / a[i]) * (a[i + 1] - a[i]);
    }
  }
  cout << ans;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define arr array
#define yes                                                                    \\
  cout << "YES"                                                                \\
       << "\\n"
#define no                                                                     \\
  cout << "NO"                                                                 \\
       << "\\n"
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false)
#define out cin.tie(nullptr)
#define task "test"
#define open(task)                                                             \\
  if (fopen(task ".inp", "r")) {                                               \\
    freopen(task ".inp", "r", stdin);                                          \\
    freopen(task ".out", "w", stdout);                                         \\
  }

using namespace std;

const int maxn = 2 * 1e5 + 69;
const ll mod = 2111992;

ll a[maxn], rg[maxn];
int n;
ll dp[81][10000][100];
ll maxx = 0;

ll dq(int pos, ll val, int have) {
  // cout << pos <<" "<<val<<" "<<have<<"\\n";
  if (dp[pos][val][have] != -1)
    return dp[pos][val][have];
  if (pos == n + 1) {
    return val;
  }
  ll ans = 0;
  for (int i = 0; i <= val / a[pos]; i++) {
    for (int j = 0; j <= have + i; j++) {
      ans = max(ans, dq(pos + 1, val - a[pos] * i + j * a[pos], have + i - j));
    }
  }
  return dp[pos][val][have] = ans;
}

int main() {
  fast;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << dq(1, 1000, 0);
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 85;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  ll cash = 1000;
  for (int i = 1; i < n; i++) {
    if (a[i] > a[i - 1]) {
      ll x = cash / a[i - 1];
      cash += x * (a[i] - a[i - 1]);
    }
  }
  cout << cash << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 85;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  ll cash = 1000;
  for (int i = 2; i <= n; i++) {
    if (a[i] > a[i - 1]) {
      ll x = cash / a[i - 1];
      cash += x * (a[i] - a[i - 1]);
    }
  }
  cout << cash << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  REP(i, N) { cin >> A[i]; }

  ll ans = 1000;
  ll x = 0;
  REP(i, N) {
    if (i < N - 1) {
      if (A[i] < A[i + 1] && x == 0) {
        x = ans / A[i];
        ans %= A[i];
        continue;
      }
    }

    if (i > 0) {
      if (i == N - 1 || (A[i] > A[i + 1] && x > 0)) {
        ans += A[i] * x;
        x = 0;
        continue;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100];
ll dp[83][1500005];

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

  ll N;
  cin >> N;
  REP(i, N) { cin >> A[i]; }

  memset(dp, 0, sizeof(dp));
  ll mx = 0;
  dp[0][0] = 1000;
  REP(i, N) {
    REP(j, mx + 1) {
      dp[i + 1][0] = std::max(dp[i + 1][j], dp[i][j] + j * A[i]);
    }

    REP(j, mx + 1) {
      ll n = dp[i][j];
      dp[i + 1][j] = std::max(dp[i + 1][j], n);
    }

    ll nxt = 0;
    while (true) {
      ll n = dp[i + 1][nxt];
      if (n < A[i])
        break;
      dp[i + 1][nxt + 1] = std::max(dp[i + 1][nxt + 1], n - A[i]);
      nxt++;
    }
    mx = std::max(mx, nxt);
  }

#if false
    REP(i, N) {
        REP(j, mx + 1) {
            cout << dp[i + 1][j] << " ";
        }
        cout << endl;
    }
#endif
  ll ans = 0;
  REP(i, mx + 1) { ans = std::max(ans, dp[N][i] + i * A[N - 1]); }
  cout << ans << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define endl "\\n"
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll mod = 1e9 + 7;
constexpr int NIL = -1;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#pragma endregion
//-------------------
ll a[100];
ll n;
ll dp[100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // cout << fixed << setprecision(15);
  cin >> n;

  FOR(i, 1, n) cin >> a[i];

  // pair<int, int> dp[100][2];
  // dp[0][0] = {1000, 0};
  // dp[0][1] = {1000, 0};

  // FOR(i,1,n){
  //     dp[i][0] = dp[i-1][0].first > dp[i-1][1].first + dp[i-1][1].second *
  //     a[i] ? dp[i-1][0]: make_pair(dp[i-1][1].first + dp[i-1][1].second *
  //     a[i], 0); dp[i][1] = dp[i-1][1].second > dp[i-1][0].first / a[i]?
  //     dp[i-1][1] : make_pair(dp[i-1][0].first - (dp[i-1][0].first/a[i])
  //     *a[i], dp[i-1][0].first/a[i]);
  // }

  // cout << dp[n][0].first << endl;

  dp[0] = 1000;
  FOR(i, 1, n) {
    chmax(dp[i], dp[i - 1]);
    FOR(j, 0, i - 2) {
      ll cnt = dp[j] / a[j + 1];
      chmax(dp[i], dp[j] - cnt * a[j + 1] + cnt * a[i]);
    }
  }

  cout << dp[n] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
#define endl "\\n"
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll mod = 1e9 + 7;
constexpr int NIL = -1;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#pragma endregion
//-------------------
int a[100];
int n;

int dfs(int i, int money, int stock) {
  if (i == n - 1) {
    return money + stock * a[i];
  }
  int mx = 0;
  for (int j = 0; j <= money; j += a[i]) {
    for (int k = 0; k <= stock; k++) {
      chmax(mx, dfs(i + 1, money - j + k * a[i], stock + j / a[i] - k));
    }
  }
  return mx;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // cout << fixed << setprecision(15);
  cin >> n;

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

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

#include <bits/stdc++.h>
using namespace std;
int n, a[105];
typedef unsigned long long ull;
ull v = 1000;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n - 1; i++)
    if (a[i] < a[i + 1]) {
      ull t = v % ull(a[i]);
      v /= ull(a[i]);
      v = t + v * ull(a[i + 1]);
    }
  cout << v << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int w[105], dp[10000005];
int main() {
  int n, v = 1000;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> w[i];
  for (int i = 1; i <= n - 1; i++) {
    memset(dp, 0, sizeof(dp));
    for (int j = w[i]; j <= v; j++)
      dp[j] = max(dp[j], dp[j - w[i]] + w[i + 1] - w[i]);
    v = max(v, v + dp[v]);
  }
  cout << v << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int N;
int main() {
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = 1000;
  ll s = 0;
  for (int i = 0; i < N; i++) {
    ans += a[i] * s;
    s = 0;
    if (i == N - 1)
      break;
    if (a[i] < a[i + 1]) {
      s += ans / a[i];
      ans %= a[i];
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int N;
int smax = 10000;
int main() {
  cin >> N;

  vector<int> a(N);
  vector<vector<ll>> dp(82, vector<ll>(smax, -1));
  dp[0][0] = 1000;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < smax; j++) {
      if (dp[i][j] < 0)
        continue;
      ll tmp = dp[i][j] / a[i];
      for (int k = 0; k <= tmp; k++) {
        chmax(dp[i + 1][j + k], dp[i][j] - k * a[i]);
      }
      for (int k = j; k >= 0; k--) {
        chmax(dp[i + 1][j - k], dp[i][j] + k * a[i]);
      }
    }
  }
  ll ans = -1;
  for (int i = 0; i < smax; i++) {
    if (dp[N][i] < 0)
      continue;
    chmax(ans, dp[N][i] + i * a[N - 1]);
  }
  cout << ans << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error


// Problem : D - Road to Millionaire
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  ll i, j, k, m, n, t;
  cin >> n;
  ll ar[n];
  m = 1000;
  ll s = 0;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  ll b[n + 1] = {0};
  b[0] = 0;
  for (i = 1; i < n; i++) {
    if (ar[i] >= ar[i - 1])
      b[i] = b[i - 1] + 1;
  }
  for (i = 0; i < n; i++) {
    if (b[i] == 0 and b[i + 1] == 1) {
      s = m / ar[i];
      m %= ar[i];
    } else if (b[i] > 0 and b[i + 1] == 0) {
      m += s * ar[i];
      s = 0;
    }
  }
  cout << m;
}

Error: -11

Fixed submission:


// Problem : D - Road to Millionaire
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll int
ll n;
ll dp[81][17001][171];
ll ar[81];
ll func(ll ind, ll m, ll s) {
  if (ind == n)
    return m;
  if (dp[ind][m][s] != -1)
    return dp[ind][m][s];
  ll i, ret = 0;
  for (i = 0; i <= s; i++) {
    ret = max(ret, func(ind + 1, m + i * ar[ind], s - i));
  }
  for (i = 0; i <= m / ar[ind]; i++) {
    ret = max(ret, func(ind + 1, m - i * ar[ind], s + i));
  }
  return dp[ind][m][s] = ret;
}
int main() {
  ll i, j, k, m, t;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  for (i = 0; i <= 80; i++) {
    for (j = 0; j <= 17000; j++) {
      for (k = 0; k <= 170; k++)
        dp[i][j][k] = -1;
    }
  }
  cout << func(0, 1000, 0);
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N);
  forn(i, 0, N) cin >> A[i];
  ll dinero = 1000;
  ll cnt = 0;
  ll res = dinero;
  forn(i, 0, N - 1) {
    if (A[i] < A[i + 1]) {
      ll puedo = dinero / A[i];

      cnt += puedo;
      dinero -= puedo * A[i];

      dinero += cnt * A[i + 1];
      cnt = 0;
      res = max(res, dinero);
    }
    // else if(A[i] > A[i+1]){
    // ll puedo = dinero/A[i+1];
    // cnt += puedo;
    // dinero -= puedo*A[i+1];
    //}
    // cout << dinero << ' ' << cnt << '\\n';
  }
  cout << res << '\\n';
  return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Error: -11

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 80;
const int maxp = 17001;

int memo[maxn][200][maxp];
int A[maxn], N;

int dp(int pos, int cnt, int din) {
  if (pos >= N)
    return din;
  int &res = memo[pos][cnt][din];
  if (res != -1)
    return res;
  res = dp(pos + 1, cnt, din);

  // vender
  if (cnt) {
    res = max(res, dp(pos, cnt - 1, din + A[pos]));
    res = max(res, dp(pos + 1, cnt - 1, din + A[pos]));
  }
  // comprar
  if (din - A[pos] >= 0) {
    res = max(res, dp(pos, cnt + 1, din - A[pos]));
    res = max(res, dp(pos + 1, cnt + 1, din - A[pos]));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  forn(i, 0, maxn) forn(j, 0, 200) forn(k, 0, maxp) memo[i][j][k] = -1;
  cin >> N;
  forn(i, 0, N) cin >> A[i];
  cout << dp(0, 0, 1000) << '\\n';
  return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/