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

#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  long long sum, num;
  int anum;
  sum = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) <= a.at(i + 1)) {
      num += sum / a.at(i);
      sum %= a.at(i);
      anum = a.at(i);
    }
    if (a.at(i) >= a.at(i + 1)) {
      if (num > 0) {
        sum += num * a.at(i);
        num = 0;
      }
    }
  }
  sum += a.at(n - 1) * num;
  cout << sum << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 7) >= this->size() (which is 7)


Fixed submission:

#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int sum, num;
  int anum;
  sum = 1000;
  for (int i = 0; i < n; i++) {
    if (a.at(i) < a.at(i + 1)) {
      num = sum / a.at(i);
      sum %= a.at(i);
      sum += num * a.at(i + 1);
      num = 0;
    }
  }
  cout << sum << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 998244353
#define PI 2 * acos(0.0)
#define dbg(a) cout << #a << " ->->->-> " << a << "\\n"
int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    p >>= 1;
  }
  return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main() {
  io;
  int n;
  cin >> n;
  vi inp(n);
  for (auto &x : inp)
    cin >> x;
  ll ans = 1000;
  for (int i = 0; i < n - 1; i++)
    if (inp[i + 1] > inp[i])
      ans += (ans / inp[i]) * (inp[i + 1] - inp[i]);
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod 998244353
#define PI 2 * acos(0.0)
#define dbg(a) cout << #a << " ->->->-> " << a << "\\n"
int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p) {
  ll res = 1;
  while (p) {
    if (p & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    p >>= 1;
  }
  return res;
}

//=============================================ASIFAZAD==============================================//
vi inp(100);

int n;

int rec(int pos, int stk, int ab) {
  if (pos >= n)
    return ab;
  return max(rec(pos + 1, stk + ab / inp[pos], ab % inp[pos]),
             rec(pos + 1, 0, ab + stk * inp[pos]));
}

int32_t main() {
  io;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> inp[i];
  cout << rec(0, 0, 1000);
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll ans = 1000;
  ll num = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] < A[i + 1]) {
      ll temp = ans / A[i];
      num += temp;
      ans -= temp * A[i];
      if (i == N - 2)
        ans += num * A[i + 1];
    }
    if (A[i] >= A[i + 1]) {
      ans += num * A[i];
      num = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int N;
int ans;
const int m = 1000;
vector<int> A;

void dfs(vector<int> &x) {
  if (x.size() == N) {
    int cnt = 0;
    int temp = m;
    for (int i = 0; i < N; i++) {
      if (x[i] == 1) {
        while (temp >= A[i]) {
          cnt++;
          temp -= A[i];
        }
      } else {
        while (cnt) {
          cnt--;
          temp += A[i];
        }
      }
    }
    ans = max(ans, temp);
    return;
  }

  for (int i = 0; i <= 1; i++) {
    x.push_back(i);
    dfs(x);
    x.pop_back();
  }
}

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ans = m;
  vector<int> x;
  dfs(x);
  cout << ans << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define endl "\\n"
typedef long long ll;
int ans;
/*int dp[80][3000][40];
int find(int arr[],int n,int pos,int have,int c)
{
    if(pos==n)
    {///ans=max(ans,c);
        return 0;
    }
    if(dp[pos][c][have]!=-1)
       {
           return dp[pos][c][have];
       }
    int res=0;
    for(int i=0;i<=have;i++)
    {
        int a=find(arr,n,pos+1,have-i,c+i*arr[pos])+i*arr[pos];
        res=max(a,res);
    }
    for(int i=0;i<=c/arr[pos];i++)
    {
        int b=find(arr,n,pos+1,have+i,c-i*arr[pos])-i*arr[pos];
        res=max(b,res);
    }
    dp[pos][c][have]=res;
    return res;
}
*/
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  /*  for(int i=0;i<n;i++)
    {
        for(int j=0;j<3000;j++)
        {
            for(int k=0;k<40;k++)
                dp[i][j][k]=-1;
        }
    }
  ans=find(arr,n,0,0,1000);
  */
  int ans = 1000;
  for (int i = 1; i < n; i++) {
    if (arr[i] > arr[i - 1]) {
      int x = ans / arr[i - 1];
      ans += arr[i] * x;
      ans -= arr[i - 1] * x;
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();

  return 0;
}


Error: 0

Fixed submission:


#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define endl "\\n"
typedef long long ll;
int ans;
int dp[80][3000][40];
int find(int arr[], int n, int pos, int have, int c) {
  if (pos == n) { /// ans=max(ans,c);
    return 0;
  }
  if (dp[pos][c][have] != -1) {
    return dp[pos][c][have];
  }
  int res = 0;
  for (int i = 0; i <= have; i++) {
    int a = find(arr, n, pos + 1, have - i, c + i * arr[pos]) + i * arr[pos];
    res = max(a, res);
  }
  for (int i = 0; i <= c / arr[pos]; i++) {
    int b = find(arr, n, pos + 1, have + i, c - i * arr[pos]) - i * arr[pos];
    res = max(b, res);
  }
  dp[pos][c][have] = res;
  return res;
}
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3000; j++) {
      for (int k = 0; k < 40; k++)
        dp[i][j][k] = -1;
    }
  }
  ans = find(arr, n, 0, 0, 1000);
  cout << ans + 1000 << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();

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

#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#define debug(x) cout << #x << ": " << x << " "
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 100;
int a[N], n;
int main() {
  IO;
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> a[i];
  ll res = 1000;
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j <= n && a[j + 1] >= a[j])
      j++;
    if (j > i)
      res = res / a[i] * a[j] + res % a[i];
    i = j;
  }
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#define debug(x) cout << #x << ": " << x << " "
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll N = 100000000;
ll a[81], n;
ll f[N];
ll m = 1000;
int main() {
  IO;
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    memset(f, 0, sizeof f);
    if (a[i] < a[i + 1])
      for (int j = a[i]; j <= m; j++)
        f[j] = max(f[j], f[j - a[i]] + a[i + 1] - a[i]);
    m += f[m];
  }
  cout << m << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

const int ss = 3e5 + 5;

// ll ar[84],dp[82][5005][51],n;

// ll f(int idx,int cur,int st)
// {
//     if(idx==n)
//         return cur;
//     ll &res = dp[idx][cur][st];
//     if(res!=-1)
//         return res;
//     res = f(idx+1,cur,st);
//     if(st)
//     {
//         for(int i=0;i<=st;i++)
//         {
//             res = max(res,f(idx+1,cur+i*ar[idx],st-i));
//         }
//     }
//     else
//     {
//         for(int i=0;i*ar[idx]<=cur;i++)
//         {
//             res = max(res,f(idx+1,cur-i*ar[idx],st+i));
//         }
//     }

//     return res;
// }

int main() {

  int t = 1;
  // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll ar[n];
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    int i = 0;
    ll cur = 1000;
    while (i < n - 1) {
      while (i < (n - 1) and ar[i + 1] <= ar[i]) {
        i++;
      }
      if (i == n - 1)
        break;
      ll buy = i;
      ll st = (cur / ar[buy]);
      cur -= (st * ar[buy]);
      i++;
      while (i < n and ar[i] >= ar[i - 1]) {
        i++;
      }
      ll sell = i - 1;
      cur += (st * ar[sell]);
    }

    cout << max(cur, 1000ll) << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

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

const int ss = 3e5 + 5;

ll ar[84], dp[82][5005][51], n;

ll f(int idx, int cur, int st) {
  if (idx == n)
    return cur;
  ll &res = dp[idx][cur][st];
  if (res != -1)
    return res;
  res = f(idx + 1, cur, st);
  if (st) {
    for (int i = 0; i <= st; i++) {
      res = max(res, f(idx + 1, cur + i * ar[idx], st - i));
    }
  } else {
    for (int i = 0; i * ar[idx] <= cur; i++) {
      res = max(res, f(idx + 1, cur - i * ar[idx], st + i));
    }
  }

  return res;
}

int main() {

  int t = 1;
  // cin>>t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= 5000; j++) {
        for (int k = 0; k <= 50; k++) {
          dp[i][j][k] = -1;
        }
      }
    }
    cout << f(0, 1000, 0) << endl;
  }

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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
  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 = 0; i < N - 1; i++) {
    stock = 0;
    if (A[i] < A[i + 1]) {
      stock = money / A[i];
      money += (A[i + 1] - A[i]) * stock;
    }
  }

  cout << money << '\\n';
}

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

  solve();

  return 0;
}

Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
  cout << first << ' ';
  print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

int N;
vector<int> A;
int ans = 0;

void rec(int n, int money, int stock) {

  // print(n, money, stock);

  if (n == N) {
    ans = max(ans, money);
    return;
  }

  int money_copy = money;
  int stock_copy = stock;

  // 買う
  int buy = money / A[n];
  money -= A[n] * buy;
  stock += buy;
  rec(n + 1, money, stock);

  money = money_copy;
  stock = stock_copy;

  // 売る
  int sell = stock;
  money += A[n] * stock;
  stock = 0;
  if (money >= money_copy)
    rec(n + 1, money, stock);
}

void solve() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  rec(0, 1000, 0);

  cout << ans << '\\n';
}

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

  solve();

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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
  ll n;
  cin >> n;
  ll stock = 0, money = 1000;

  vector<ll> A(n + 1);
  rep(i, n) cin >> A[i];

  rep(i, n - 1) {
    if (A[i] < A[i + 1]) {
      stock = money / A[i];
      money %= A[i];
      money += stock * A[i + 1];
    }
  }

  cout << money << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  int stock = 0, money = 1000, value, cnt = 0;

  vector<int> A(n + 1);
  rep(i, n) cin >> A[i];
  A[n] = 0;
  rep(i, n) {
    if (A[0] >= A[i])
      cnt++;
  }
  if (cnt == n) {
    // cout << money << endl;
    // return 0;
  }
  int start_pos = n;
  rep(i, n) {
    int current = A[i];
    for (int j = i + 1; j < n; j++) {
      if (current < A[j]) {
        start_pos = i;
        break;
      }
    }
    if (start_pos != n)
      break;
  }

  bool buy = false;

  if (start_pos != n)
    stock = money / A[start_pos];
  money -= stock * A[start_pos];
  value = A[start_pos];
  // cout << "stock " << stock << " money " << money << endl;
  for (int i = start_pos; i < n; i++) {
    if (buy && i != n - 1) { // 買う時
      // cout << A[i] << " " << A[i + 1] << endl;
      while (A[i] > A[i + 1]) {
        i++;
      }
      stock = money / A[i];
      money -= stock * A[i];
      value = A[i];
      // cout << "buy " << "stock " << stock << " money " << money << " value "
      // << value << " i " << i << " A[i] " << A[i] << endl;
      buy = false;
    } else {
      int ii = i;
      for (int j = ii + 1; j <= n; j++) {
        i++;
        // cout << value << " " << A[j] << " " << A[j + 1] << endl;
        if (value < A[j] && A[j] > A[j + 1]) {
          // cout << " 売る j " << j << " A[j] " << A[j] << endl;
          money += stock * A[j];
          stock = 0;
          break;
        }
      }
      // cout << "sell " << "stock " << stock << " money " << money << " value "
      // << value << " i " << i << endl;

      buy = true;
    }
  }

  money += stock * A[n - 1];

  cout << money << endl;

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

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(s) int(s.size())
#define ENDL endl
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli, lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x ": " << (x) << endl;
const lli N = 1e7;
const lli INF = 1e18;
const lli mod = 1e9 + 7;

// ---- コーディングはここから！ ('-')7

int main() {
  _ int n;
  cin >> n;
  vl v(n);
  fore(i, 0, n) cin >> v[i];
  lli d = 1000, a = 0, mx = 1000;
  fore(i, 0, n - 1) {
    if (v[i] <= v[i + 1]) {
      lli x = d / v[i];
      d -= x * v[i];
      a += x;
    }
    if (v[i] > v[i + 1]) {
      lli x = a * v[i];
      d += x;
      a = 0;
    }
    mx = max(d, mx);
  }
  if (v[n - 1] >= v[n - 2]) {
    lli x = a * v[n - 1];
    d += x;
    a = 0;
    mx = max(d, mx);
  }
  cout << mx << ENDL;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sz(s) int(s.size())
#define ENDL endl
using namespace std;
typedef long double ld;
typedef unsigned long long lli;
typedef pair<lli, lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x ": " << (x) << endl;
const lli N = 1e7;
const lli INF = 1e14;
const lli mod = 1e9 + 7;

// ---- コーディングはここから！ ('-')7
map<int, map<ii, lli>> dp;
vl v;
lli n;
lli f(lli x, lli s, lli day) {
  if (day == n)
    return x;
  if (dp[day].count({x, s}))
    return dp[day][{x, s}];
  lli res = dp[day][{x, s}] = x;
  for (lli i = 0; i * v[day] <= x; i++)
    res = max(res, f(x - (i * v[day]), s + i, day + 1));
  fore(i, 0, s + 1) res = max(res, f(x + (i * v[day]), s - i, day + 1));
  // if(day==2)cout<<x<<" "<<s<<" "<<day<<" "<<res<<ENDL;
  return dp[day][{x, s}] = res;
}
int main() {
  _ cin >> n;
  v = vl(n);
  fore(i, 0, n) cin >> v[i];
  cout << f(1000, 0, 0) << ENDL;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 1000;
  int l = 0;
  for (int i = 0; i < n; ++i) {
    int mn = *min_element(a.begin() + l, a.begin() + i + 1);
    if (mn < a[i]) {
      ans += 1ll * (ans / mn) * (a[i] - mn);
      l = i;
    }
  }
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int a[81], n;

long long solve(int l, int r, long long m) {
  long long ans = m;
  for (int i = l; i <= r; ++i) {
    for (int j = i + 1; j <= r; ++j) {
      if (a[i] < a[j] and (j == n - 1 or a[j] > a[j + 1])) {
        ans = max(ans, solve(j + 1, r, m + (m / a[i]) * (a[j] - a[i])));
      }
    }
  }
  return ans;
}

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

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

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

// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

int n;

ll arr[89];

int main() {

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

  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  ll s = 0;
  ll m = 1000;
  for (int i = 0; i < n; i++) {
    if (arr[i + 1] > arr[i]) {
      s = m / arr[i];
      m += (arr[i + 1] - arr[i]) * s;
    }
  }
  cout << m << endl;

  return 0;
}

Error: -11

Fixed submission:

// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

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

int n;

int arr[89];
int dp[89][20009][109];

int solve(int idx, int money, int stocks) {
  if (idx == n)
    return money;

  if (dp[idx][money][stocks] != -1)
    return dp[idx][money][stocks];

  int ans = solve(idx + 1, money, stocks);

  int t = money / arr[idx];
  if (t > 0)
    ans = max(ans, solve(idx + 1, money - (t * arr[idx]), stocks + t));

  ans = max(ans, solve(idx + 1, money + (stocks * arr[idx]), 0));

  return dp[idx][money][stocks] = ans;
}

int main() {

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

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  memset(dp, -1, sizeof dp);

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

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 2);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll num = 0, sum = 1000;
  ll i = 0;
  while (i < n - 1) {
    ll mx = 0, mi = 1001001001;
    if (i + 1 < n && a[i] <= a[i + 1]) {
      if (i != 0) {
        while (a[i] <= a[i + 1]) {
          mx = max(a[i + 1], mx);
          i += 1;
          if (i == n - 1)
            break;
        }
        sum += num * mx;
        num = 0;
      } else if (i == 0) {
        num += 1000 / a[i];
        sum -= a[i] * num;
        i += 1;
      }
      // cout << "sum: " << sum << endl;
      // cout << "num: " << num << endl;
    } else if (i + 1 < n && a[i] > a[i + 1]) {
      if (num > 0) {
        sum += num * a[i];
        num = 0;
      }
      while (a[i] > a[i + 1]) {
        mi = min(a[i + 1], mi);
        i += 1;
        if (i == n - 1)
          break;
      }
      num += sum / mi;
      sum -= num * mi;
      // cout << "sum: " << sum << endl;
      // cout << "num: " << num << endl;
    }
  }
  if (num > 0) {
    sum += num * a[n - 1];
  }
  cout << sum << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll num = 0, sum = 1000;
  ll mx = 0, mi = 1001001001;
  ll i = 0;
  while (i < n - 1) {
    if (i + 1 < n && a[i] <= a[i + 1]) {
      if (i != 0) {
        while (a[i] <= a[i + 1]) {
          mx = max(a[i + 1], mx);
          i += 1;
          if (i == n)
            break;
        }
        sum += num * mx;
        num = 0;
      } else if (i == 0) {
        num += 1000 / a[i];
        sum -= a[i] * num;
        i += 1;
      }
      // cout << "sum: " << sum << endl;
      // cout << "num: " << num << endl;
    } else if (i + 1 < n && a[i] > a[i + 1]) {
      while (a[i] > a[i + 1]) {
        mi = min(a[i + 1], mi);
        i += 1;
        if (i == n)
          break;
      }
      num += sum / mi;
      sum -= num * mi;
      // cout << "sum: " << sum << endl;
      // cout << "num: " << num << endl;
    }
  }
  if (num > 0) {
    sum += num * a[n - 1];
  }
  cout << sum << endl;
  return 0;
}