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

#include <bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
#define int long long
#define ff first
#define ss second
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr)
#define endl "\\n"
#include "string"
const int N = 81;
const int M = 1001;
int n;
int a[N];

int32_t main() {
  boost;
  cin >> n;
  int dp[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[i] = 1000;
  }
  int ans = 1000;

  for (int i = 0; i < n; i++) {
    int stoke = dp[i] / a[i];
    int rem = dp[i] % a[i];
    for (int j = i + 1; j < n; j++) {
      dp[j] = max(dp[j], stoke * a[j] + rem);
      dp[j] = max(dp[j], dp[i]);
    }
    ans = max(ans, dp[i]);
  }

  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
#define ff first
#define ss second
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr)
#define endl "\\n"
#include "string"
const int N = 81;
const int M = 8000;
int n;
int a[N];
bool dp[N][500][M];
int ans;

void solve(int id, int stoke, int cur) {
  ans = max(ans, cur);
  if (id >= n)
    return;
  if (dp[id][stoke][cur])
    return;
  dp[id][stoke][cur] = true;
  solve(id + 1, stoke, cur);
  if (cur >= a[id])
    solve(id, stoke + 1, cur - a[id]);
  if (stoke > 0)
    solve(id, stoke - 1, cur + a[id]);
}

int32_t main() {
  boost;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  memset(dp, false, sizeof dp);
  ans = 1000;
  solve(0, 0, 1000);
  cout << ans << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_1 (i, j, n) for (int i = j; i < n; i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
  int n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  ll mon = 1000;
  ll c = 0;
  ll x = 0;
  if (n == 1) {
    cout << 1000 << endl;
    return 0;
  }
  rep(i, n) {
    if (i == 0 || a[i - 1] <= a[i]) {
      x = (mon / a[c]) * (a[i] - a[c]);
      // cout<<x<<endl;
    } else {
      mon += x;
      x = 0;
      c = i;
    }
  }
  mon += x;
  cout << mon << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_1 (i, j, n) for (int i = j; i < n; i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll mon = 1000;
  int l_a, l_k;
  rep(i, n) {
    if (i < n - 1 && a[i] < a[i + 1]) {
      l_k = mon / a[i];
      mon += l_k * (a[i + 1] - a[i]);
      l_a = i;
      i++;
    }
  }
  if (a[l_a + 1] < a[l_a + 2])
    mon += l_k * (a[l_a + 2] - a[l_a + 1]);
  cout << mon << endl;
  // cout<<a[l_a+2];
  // cout<<l_k;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
using vi = vector<int>;

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

  vi a(n);
  rep(i, n) cin >> a.at(i);

  ll money = 1000;
  ll kabu = 0;
  int start = a.at(0);
  for (int i = 1; i < n; i++) {
    if (start < a.at(i)) {
      kabu = money / start;
      money = money % start;
      ll sell = a.at(i) * kabu;
      money += sell;
      kabu = 0;
      start = a.at(i);
    } else {
      start = a.at(i);
    }
  }
  cout << money << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
using vi = vector<int>;

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

  vi a(n);
  rep(i, n) cin >> a.at(i);

  ll money = 1000;
  ll kabu = 0;
  int start = a.at(0);
  for (int i = 1; i < n; i++) {
    if (start < a.at(i)) {
      while (money >= start) {
        money -= start;
        kabu++;
      }
      while (kabu > 0) {
        money += a.at(i);
        kabu--;
      }
      start = a.at(i);
    } else {
      start = a.at(i);
    }
  }
  cout << money << endl;

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

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (ll &i : A)
    cin >> i;
  ll money = 1000;
  ll beat = 0;
  vector<bool> B(N); // BY(0),SE(0);
  for (ll i = 0; i < N - 1; i++) {
    if ((long double)A[i + 1] / A[i] > 1)
      B[i] = true; // BY.push_back(i);
    else
      B[i] = false; // SE.push_back(i);
  }
  for (ll i = 0; i < N; i++) {

    if (B[i]) {
      /* while(money-A[i]>=0){
           beat++;
           money-=A[i];
       }*/
      beat += money / A[i];
      money = money % A[i];

    } else {
      money += beat * A[i];
      beat = 0;
    }
  }

  cout << money << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (ll &i : A)
    cin >> i;
  ll money = 1000;
  ll beat = 0;
  vector<bool> B(N); // BY(0),SE(0);
  for (ll i = 0; i < N - 1; i++) {
    if ((long double)A[i + 1] / A[i] > 1)
      B[i] = true; // BY.push_back(i);
    else
      B[i] = false; // SE.push_back(i);
  }
  for (ll i = 0; i < N; i++) {

    if (B[i]) {
      while (money - A[i] >= 0) {
        beat++;
        money -= A[i];
      }

    } else {
      money += beat * A[i];
      beat = 0;
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  ll ans = 1000;
  int j = 1;
  rep2(i, 1, n) {
    if (a[i - 1] < a[i]) {
      j = i;
      break;
    }
  }
  int l = a[j - 1];
  int h = a[j - 1];
  rep2(i, j, n) {
    if (h <= a[i]) {
      h = a[i];
    } else {
      ans = ans / l * h + ans % l;
      l = a[i];
      h = a[i];
    }
  }
  ans = ans / l * h + ans % l;
  cout << ans << endl;
}


Error: -8

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  int ans = 1000;
  int j = 0;
  rep2(i, 1, n) {
    if (a[0] >= a[i]) {
      j++;
    } else {
      break;
    }
  }
  int l = a[j - 1];
  int h = a[j - 1];
  rep2(i, j, n) {
    if (h <= a[i]) {
      h = a[i];
    } else {
      ans = ans / l * h + ans % l;
      l = a[i];
      h = a[i];
    }
  }
  ans = ans / l * h + ans % l;
  cout << ans << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
long long a[2000];
long long money = 1000;
long long num = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (a[i] != a[i - 1]) {
      v.push_back(a[i]);
    }
  }
  int len = v.size();
  int flag;

  if (v[1] > v[0])
    flag = 1;
  else
    flag = -1;

  if (flag == 1) {
    num = 1000 / v[0];
    money = 1000 - num * v[0];
  }
  bool f = true;
  for (int i = 1; i < len; i++) {
    int temp;
    if (v[i] > v[i - 1]) {
      temp = 1;
    } else {
      temp = -1;
    }
    if (temp != flag) {
      f = false;
      if (flag == 1) { // 卖
        money += num * v[i - 1];
        num = 0;
      }
      if (flag == -1) { // 买
        num = money / v[i - 1];
        money = money - num * v[i - 1];
      }
      flag = -flag;
    }
  }
  if (f == true) {
    if (flag == 1)
      cout << 1000 - 1000 / v[0] * v[0] + 1000 / v[0] * v[len - 1] << endl;
    if (flag == -1)
      cout << 1000 << endl;
  } else {
    if (flag == 1)
      money += num * v[len - 1];
    cout << money << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, SWAP, money = 1000, result;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[n];
  }
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n - 1; i++) {
      if (arr[j] > arr[j + 1]) {
        SWAP = arr[j];
        arr[j] = arr[j + 1];
        arr[j + 1] = SWAP;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    result = money / arr[i];
    for (int j = 0; j < n; j++) {
      // cout << arr[n-1] ;
      result = result * arr[n - 1];
      break;
    }
    break;
  }

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

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define abdelrahman010                                                         \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int n, a[85];
int main() {
  abdelrahman010 cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll k = 1000, s = 0;
  int cur = 0;
  for (int i = 0; i < n; i++) {
    int j = i + 1;
    if (!cur) {
      while (j < n && a[j] < a[j - 1])
        j++;
      j--;
      if (j != n - 1)
        s += k / a[j], k %= a[j];
    } else {
      while (j < n && a[j] > a[j - 1])
        j++;
      j--;
      k += s * a[j], s = 0;
    }
    cur ^= 1, i = j;
  }
  cout << k;
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define abdelrahman010                                                         \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int n, a[85];
map<pair<int, pair<ll, ll>>, ll> memo;
ll solve(int i, ll j, ll k) {
  if (i == n)
    return k;
  if (memo.count({i, {j, k}}))
    return memo[{i, {j, k}}];
  ll ans = solve(i + 1, j + k / a[i], k % a[i]);
  ans = max(ans, solve(i + 1, 0, k + j * a[i]));
  return memo[{i, {j, k}}] = ans;
}
int main() {
  abdelrahman010 cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cout << solve(0, 0, 1000);
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int MAXN = 2e5 + 5;
int main() {
  long long n;
  cin >> n;
  long long last = 0;
  long long mo = 1000;
  cin >> last;
  for (int i = 2; i <= n; i++) {
    long long a;
    cin >> a;
    if (a > last) {
      long long num = mo / last;
      mo = mo + num * (a - last);
    }
    last = a;
  }
  cout << mo << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int MAXN = 2e5 + 5;
int num[205];
int maxn = 0;
int n;
void dfs(int day, int con, int mo) {
  // cout << con<<" "<<mo << endl;
  if (day == n + 1) {
    if (mo > maxn)
      maxn = mo;
    return;
  }
  if (mo >= num[day]) {
    int a = mo / num[day];
    // cout << a << endl;
    dfs(day + 1, con + a, mo - a * num[day]);
  }
  dfs(day + 1, con, mo);
  if (con != 0)
    dfs(day + 1, 0, mo + con * num[day]);
}

int main() {

  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> num[i];
  dfs(1, 0, 1000);
  cout << maxn << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

struct A {
  long money;
  long kabu;
};

long solve(int n, const std::vector<int> &prices) {
  A sisan{1000, 0};

  for (int i = 0; i < n; ++i) {
    const auto p = prices[i];
    sisan.money += p * sisan.kabu;
    sisan.kabu = 0;
    if (i < n - 1 && p < prices[i + 1]) {
      const auto c = sisan.money / p;
      sisan.money -= p * c;
      sisan.kabu += c;
    }
  }

  return sisan.money;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> prices(n);
  for (auto &p : prices) {
    std::cin >> p;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, prices) << std::endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

struct A {
  int money;
  int kabu;
  int max;
  int index;
};

A kau(const A &sisan, int price) {
  A result = sisan;
  int n = result.money / price;
  result.money -= n * price;
  result.kabu += n;
  ++result.index;
  return result;
}

A uru(const A &sisan, int price) {
  A result = sisan;
  result.money += result.kabu * price;
  result.kabu = 0;
  result.max = std::max(result.max, result.money);
  ++result.index;
  return result;
}

long solve(int n, const std::vector<int> &prices) {
  long result = 1000;

  std::queue<A> queue;
  queue.push({1000, 0, 1000, 0});

  while (!queue.empty()) {
    auto s = queue.front();
    queue.pop();
    if (s.money > result)
      result = s.money;
    if (s.index >= n)
      continue;

    auto p = prices[s.index];
    if (s.kabu > 0) {
      if (s.money + s.kabu * p > s.max)
        queue.push(uru(s, p));
    }
    if (s.index < n - 1) {
      if (s.money > 0)
        queue.push(kau(s, p));
      ++s.index;
      queue.push(s);
    }
  }
  return result;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> prices(n);
  for (auto &p : prices) {
    std::cin >> p;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, prices) << std::endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, const T &t) {
  return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second

int n;
// map<array<int, 3>, int> dp;
vector<int> a;

// int f(int i, int j, int k){
//     if(j < 0 || k < 0) return 0;
//     if(i==n) return j;
//     if(dp.count({i,j,k})) return dp[{i,j,k}];

//     int ans = 0;
//     for(int buy = 0; buy <= j/a[i]; ++buy){
//         ans = max(ans, f(i+1, j-buy*a[i], k+buy));
//     }
//     for(int sell = 0; sell <= k; ++sell){
//         ans = max(ans, f(i+1, j+sell*a[i], k-sell));
//     }

//     return dp[{i,j,k}] = ans;
// }

void solve() {
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  ll money = 1000;
  for (int i = 1; i < n; ++i) {
    if (a[i - 1] < a[i]) {
      ll stocks = money / a[i - 1];
      money += stocks * (a[i] - a[i - 1]);
    }
  }

  cout << money << '\\n';
  // cout << f(0, 1000, 0) << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> using v2 = vector<vector<T>>;
template <typename T> inline v2<T> fill(int r, int c, const T &t) {
  return v2<T>(r, vector<T>(c, t));
}
#define F first
#define S second

int n;
map<array<int, 3>, int> dp;
vector<int> a;

int f(int i, int j, int k) {
  if (j < 0 || k < 0)
    return 0;
  if (i == n)
    return j;
  if (dp.count({i, j, k}))
    return dp[{i, j, k}];

  int ans = 0;
  for (int buy = 0; buy <= j / a[i]; ++buy) {
    ans = max(ans, f(i + 1, j - buy * a[i], k + buy));
  }
  for (int sell = 0; sell <= k; ++sell) {
    ans = max(ans, f(i + 1, j + sell * a[i], k - sell));
  }

  return dp[{i, j, k}] = ans;
}

void solve() {
  cin >> n;
  a = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  cout << f(0, 1000, 0) << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll money = 1000;
  ll stock = 0;
  for (int i = 0; i + 1 < n; i++) {
    if (a[i + 1] > a[i]) {
      stock += money / a[i];
      money %= a[i];
      money += stock * a[i + 1];
      stock = 0;
    }
  }
  cout << money << endl;
  return 0;
}


Error: 0

Fixed submission:

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

bool dp[85][25][2005];
int n;
vector<int> a;

void solve(int i, int stock, int money) {
  if (dp[i][stock][money]) {
    return;
  }
  dp[i][stock][money] = true;
  if (i == n) {
    return;
  }
  for (int j = 0; j <= money / a[i]; j++) {
    if (money - j * a[i] < 0)
      continue;
    solve(i + 1, stock + j, money - j * a[i]);
  }
  for (int j = 0; j <= stock; j++) {
    solve(i + 1, stock - j, money + j * a[i]);
  }
}

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 20; j++) {
      for (int k = 0; k <= 2000; k++) {
        dp[i][j][k] = false;
      }
    }
  }
  solve(0, 0, 1000);
  for (int i = 2000; i >= 1000; i--) {
    for (int j = 0; j <= 20; j++) {
      if (dp[n][j][i]) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, sum = 1000;
  cin >> n;
  int64_t a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int64_t cnt = 0;
    if (a[i] < a[i + 1])
      cnt = sum / a[i];
    sum += (a[i + 1] - a[i]) * cnt;
  }
  cout << sum << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, cnt = 0, sum = 1000, a[n];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1])
      cnt = sum / a[i];
    sum += (a[i + 1] - a[i]) * cnt;
  }
  cout << sum << endl;
}
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(i, s, n) for (int i = s; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using Graph = vector<vector<pair<int, int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1, -113);
  rep(i, n) cin >> v[i];
  ll ans = 1000, cnt = 0;
  rep(i, n) {
    int j = 0;
    while (v[i + j] <= v[i + j + 1])
      j++;
    ll tmp = ans / v[i];
    ans -= tmp * v[i];
    ans += tmp * v[i + j];
    i += j;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = s; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using Graph = vector<vector<pair<int, int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll dp[90][1743];
int main() {
  rep(i, 90) rep(j, 1700) dp[i][j] = -312312333;
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  dp[0][0] = 1000;
  rep(i, n) {
    rep(j, 1700) {
      rep(k, 1700) { // 売る
        if (j >= k)
          dp[i + 1][j - k] = max(dp[i + 1][j - k], dp[i][j] + v[i] * k);
      }
      for (int k = 0; dp[i][j] >= k * v[i]; k++) {
        if (dp[i][j] >= k * v[i])
          dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] - v[i] * k);
      }
    }
  }
  ll ans = 0;
  rep(i, 1743) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <array>
#include <bits/stdc++.h>
#include <cassert>
#define ll long long
#define endl "\\n"
#define pb push_back
#define READ(FILE) freopen(FILE, "r", stdin)
#define WRITE(FILE) freopen(FILE, "w", stdout)
#define loop(i, s, e) for (int i = s; i < e; i++)
#define mego fast();
using namespace std;
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll lcm(ll x, ll y) { return (x * y) / __gcd(x, y); }
/*const int N=500000;
ll seg[4*N];
ll arr[N+5];
void bulid(int s,int e,int p)
{
    if(s==e)
    {
         seg[p]=arr[s];
         return;
    }
    bulid(s,(s+e)/2,2*p);
    bulid((s+e)/2 +1,e,2*p +1);
    seg[p]=__gcd(seg[2*p],seg[2*p +1]);
    return;
}
void seti(int s,int e,int p,int i,int v)
{
    if(s==e && s==i)
    {
         seg[p]=arr[i]=v;
         return;
    }
    if(i >(s+e)/2)
    seti((s+e)/2 +1,e,2*p +1,i,v);
    else seti(s,(s+e)/2,2*p,i,v);
    seg[p]=__gcd(seg[2*p],seg[2*p +1]);
    return;
}
int flr(int s,int e,int p,int l,int r)
{
    if(l<=s&&e<=r)return seg[p];
    if(s>r || e<l)return 0;
    return __gcd(flr(s,(s+e)/2,2*p,l,r),flr((s+e)/2+1 ,e ,2*p +1 ,l,r));
}
*/
int main() {
  mego int n, x;
  cin >> n;
  vector<int> v;
  loop(i, 0, n) {
    cin >> x;
    v.pb(x);
  }

  ll cur = (1000);
  loop(i, 0, n - 1) {
    ll s = (cur / v[i]);
    if (v[i + 1] > v[i])
      cur += (v[i + 1] - v[i]) * s;
  }
  cout << cur;
  return 0;
}


Error: -11

Fixed submission:

#define ll long long int

#include <bits/stdc++.h>

using namespace std;
const int N = 1e4;
int arr[N];

string convert(ll n) {
  string temp = "";
  while (n) {
    if (n % 2) {
      temp += '1';
    } else
      temp += '0';
    n = n / 2;
  }
  reverse(temp.begin(), temp.end());
  return temp;
}

ll power(ll n) {
  ll res = 1;
  while (n) {
    res = res * 2;
    n--;
  }
  return res;
}

ll binary(string s) {
  ll res = 0;
  ll cnt = 0;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == '1')
      res += power(cnt);
    cnt++;
  }
  return res;
}

int n;
ll dp[81][N][161];

ll go(int i, int have, int candy) {

  if (i == n) {
    return 1000;
  }
  ll &ret = dp[i][have][candy];
  if (~ret)
    return ret;

  ret = -1e9;
  ret = max(ret, go(i + 1, have, candy));

  if (candy > 0) {
    ret = max(ret, go(i, have + arr[i], candy - 1) + arr[i]);
  }
  if (have >= arr[i]) {
    ret = max(ret, go(i, have - arr[i], candy + 1) - arr[i]);
  }
  //  cout << i <<" " << have <<endl;
  return ret;
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  cout << go(0, 1000, 0) << endl;
  return 0;
}