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

#include <iostream>

int main() {
  int N, K;
  std::cin >> N >> K;
  int A[N + 1];
  A[0] = 1;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }

  for (int i = K + 1; i <= N; i++) {
    if (A[i] > A[i - K]) {
      std::cout << "Yes" << std::endl;
    } else {
      std::cout << "No" << std::endl;
    }
  }

  // int end;
  // std::cin >> end;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

unsigned long long calcScore(int num, int A[], int idx) {
  unsigned long long score = 1;
  int i = 0;
  while (i < num) {
    // std::cout << A[idx-i] << std::endl;
    score = score * A[idx - i];
    i++;
  }
  return score;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  int A[N + 1];
  A[0] = 1;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }
  unsigned long long hyouka[N + 1];

  for (int i = 0; i <= N; i++) {
    hyouka[i] = 1;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      hyouka[i + j] = hyouka[i + j] * A[i];
    }
  }

  // for(int i=K; i<=N; i++){
  //     std::cout <<hyouka[i] << std::endl;
  // }

  for (int i = K + 1; i <= N; i++) {
    if (hyouka[i] > hyouka[i - 1]) {
      std::cout << "Yes" << std::endl;
    } else {
      std::cout << "No" << std::endl;
    }
  }

  // int end;
  // std::cin >> end;
  return 0;
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define per(i, n, j) for (int i = (n); i >= (j); i--)
using ll = long long;
using unll = unsigned long long;
using namespace std;
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;
}
const ll INF = 1LL << 60;

ll n, k;

int main() {
  cin >> n >> k;
  vector<unll> a(n), sum(n + 1);
  sum[0] = 1;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n - k) {
    if (a[i] < a[i + k])
      cout << "Yes"
           << "\\n";
    else
      cout << "No"
           << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define per(i, n, j) for (int i = (n); i >= (j); i--)
using ll = long long;
using namespace std;
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;
}
const ll INF = 1LL << 60;

ll n, k;

int main() {
  cin >> n >> k;
  vector<ll> a(n), sum(n + 1);
  sum[0] = 1;
  rep(i, 0, n) {
    cin >> a[i];
    sum[i + 1] = sum[i] * a[i];
  }

  rep(i, k + 1, n + 1) {
    if (sum[i] / sum[i - k] > sum[i - 1] / sum[i - k - 1])
      cout << "Yes"
           << "\\n";
    else
      cout << "No"
           << "\\n";
  }
  return 0;
}
Problem p02602 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  for (int i = k; i < n; i++) {
    if (a.at(i - k) < a.at(i)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<int> a(n);
  vector<int> b(n, 1);
  int index = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    for (int j = index; j <= i; j++) {
      b.at(j) += a.at(i);
    }
    if (i >= k - 1)
      index++;
  }

  for (int i = 1; i <= n - k; i++) {
    if (b.at(i - 1) < b.at(i)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
  int N, K;
  cin >> N >> K;
  vecl A(N);
  REP(i, N) cin >> A[i];
  vecl cum(N + 1, 1);
  REP(i, N) {
    cum[i + 1] = cum[i] + A[i];
    // cout << cum[i+1] << " " << A[i] << endl;
  }
  for (int i = K + 1; i <= N; i++) {
    // cout << cum[i-1]-cum[i-1-K] << " " << cum[i]-cum[i-K] << endl;
    if (cum[i] - cum[i - K] > cum[i - 1] - cum[i - 1 - K])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
  int N, K;
  cin >> N >> K;
  vecl A(N);
  REP(i, N) cin >> A[i];
  vecl cum(N + 1, 1);
  REP(i, N) {
    cum[i + 1] = cum[i] * A[i];
    // cout << cum[i+1] << " " << A[i] << endl;
  }
  for (int i = K + 1; i <= N; i++) {
    // cout << cum[i-1]/cum[i-1-K] << " " << cum[i]/cum[i-K] << endl;
    if (cum[i] / cum[i - K] > cum[i - 1] / cum[i - 1 - K])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll n, k;

  cin >> n >> k;

  /// deque<ll> dq(n + 1, 1);
  /// deque<ll> p(n + 1, 1);
  deque<ll> dq = {0};
  deque<ll> p = {0};

  for (ll i = 1; i <= n; i++) {
    ll inp;

    cin >> inp;

    dq.push_back(inp);
    p.push_back(p.back() + dq.back());
  }

  for (ll i = k + 1; i <= n; i++) {
    // cout << "   " << p[i - 1] / p[i - k - 1] << " " << p[i] / p[i - k] <<
    // endl;

    if (p[i] - p[i - k] > p[i - 1] - p[i - k - 1]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll n, k;

  cin >> n >> k;

  /// deque<ll> dq(n + 1, 1);
  /// deque<ll> p(n + 1, 1);
  deque<ll> dq = {1};
  deque<ll> p = {1};

  for (ll i = 1; i <= n; i++) {
    ll inp;

    cin >> inp;

    dq.push_back(inp);
    p.push_back(p.back() * dq.back());
  }

  for (ll i = k + 1; i <= n; i++) {
    // cout << "   " << p[i - 1] / p[i - k - 1] << " " << p[i] / p[i - k] <<
    // endl;

    if (p[i] / p[i - k] > p[i - 1] / p[i - k - 1]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

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

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

int main() {
  ull n, k;
  cin >> n >> k;
  vector<unsigned long long> a(n);

  for (ull i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (ull i = k; i < n; i++) {
    if (a[i] > a[i - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];

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

  for (int i = k; i < n; i++) {
    if (a[i] > a[i - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (int i = K; i < N; i++) {
    if (p[i - K] < p[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> p(N);
  long long m = 1;
  for (int i = 0; i < N; i++) {
    long long ai;
    cin >> ai;
    m *= ai;
    p[i] = m;
  }
  long long pim1 = p[K - 1];
  for (int i = K; i < N; i++) {
    long long pi = p[i] / p[i - K];
    if (pim1 < pi) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    pim1 = pi;
  }
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i <= n - k; ++i) {
    if (a[i] < a[i + k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n / 2; i++) {
    if (a[i] < a[i + k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
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;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  for (int i = k; i < n; ++i) {
    if (a[i - k] < a[i])
      cout << "Yes\\n";
    else
      cout << "No\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
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;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> r(n + 1);
  r[0] = 1;
  ll in;
  REP(i, n) {
    cin >> in;
    r[i + 1] = r[i] * in;
  }
  ll bef = r[k] / r[0];
  for (int i = k + 1; i <= n; ++i) {
    ll now = r[i] / r[i - k];
    if (bef < now)
      cout << "Yes\\n";
    else
      cout << "No\\n";
    bef = now;
  }

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

/**
 *    author:  boutarou
 *    created: 25.07.2020 21:05:37
 **/

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  for (int i = k; i < n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  boutarou
 *    created: 25.07.2020 21:05:37
 **/

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> sum(n + 1);
  sum[0] = 1;
  rep(i, n) sum[i + 1] = sum[i] * a[i];
  vector<ll> ans(n);
  rep(i, k) {
    if (i == k - 1)
      ans[i] = sum[k] / sum[0];
  }
  for (int i = k; i < n; i++) {
    ans[i] = sum[i + 1] / sum[i + 1 - k];
    if (ans[i] > ans[i - 1])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02602 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int main() {
  long long N, K;
  vector<long long> vec;

  cin >> N >> K;
  int x;
  vec.push_back(0);

  for (long long n = 0; n < N; n++) {
    cin >> x;
    vec.push_back(vec.back() + x);
  }

  for (long long i = K; i < N; i++) {
    if (vec.at(i) - vec.at(i - K) < vec.at(i + 1) - vec.at(i + 1 - K)) {
      cout << "Yes"
           << "\\n";
    } else {
      cout << "No"
           << "\\n";
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int main() {
  long long N, K;
  vector<long long> vec;

  cin >> N >> K;
  int x;
  vec.push_back(1);

  for (long long n = 0; n < N; n++) {
    cin >> x;
    vec.push_back(vec.back() * x);
  }

  for (long long i = K; i < N; i++) {
    if (vec.at(i) / vec.at(i - K) < vec.at(i + 1) / vec.at(i + 1 - K)) {
      cout << "Yes"
           << "\\n";
    } else {
      cout << "No"
           << "\\n";
    }
  }
}
Problem p02602 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k;
  long long int a;
  cin >> n >> k;
  std::deque<long long int> deq;
  for (int i = 0; i < n; i++) {
    cin >> a;
    deq.emplace_back(a);
  }
  std::deque<long long int> S(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    if (i < k) {
      S[i] = 0;
    } else if (i == k) {
      S[i] = deq[i - k];
    } else {
      S[i] = deq[i - 1];
    }
  } /*
   for (auto x:S) {
       cout<<x<<" ";
   }cout<<endl;*/
  for (int i = k + 1; i <= n; i++) {
    if (S[i] > S[i - 1]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    S[i] = deq[i - k];
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
int main(void) {
  int n, k;
  boost::multiprecision::cpp_int a;
  cin >> n >> k;
  std::deque<boost::multiprecision::cpp_int> deq;
  for (int i = 0; i < n; i++) {
    cin >> a;
    deq.emplace_back(a);
  }
  std::deque<boost::multiprecision::cpp_int> S(n + 1, 1);
  for (int i = 0; i < n; i++) {
    S[i + 1] = S[i] * deq[i];
  }
  for (int i = k + 1; i <= n; i++) {
    if (S[i] / S[i - k] > S[i - 1] / S[i - 1 - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long int money = 1000, stock = 0;
  A.push_back(0);
  for (int i = 0; i < N; i++) {
    if (A[i] == A[i + 1])
      continue;
    if (A[i] < A[i + 1]) {
      long long int tmp = money / A[i];
      money -= A[i] * tmp;
      stock += tmp;
    } else if (A[i] > A[i + 1]) {
      money += stock * A[i];
      stock = 0;
    }
  }
  cout << money << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long int money = 1000, stock = 0;
  A.push_back(0);
  for (int i = 0; i < N; i++) {
    if (A[i] == A[i + 1])
      continue;
    if (A[i] < A[i + 1]) {
      while (money >= A[i]) {
        money -= A[i];
        stock++;
      }
    } else if (A[i] > A[i + 1]) {
      money += stock * A[i];
      stock = 0;
    }
  }
  cout << money << endl;
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll money = 1000;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool have = false;
  for (ll i = 0; i < n; i++) {
    if (have) {
      if (i == n - 1) {
        while (cnt > 0) {
          money += a[i];
          cnt--;
        }
        continue;
      }
      if (a[i] < a[i + 1]) {
        continue;
      }
      money += cnt * a[i];
      cnt = 0;
      have = false;
    } else {
      if (i == n - 1) {
        continue;
      }
      if (a[i] > a[i + 1]) {
        continue;
      }
      ll div = money / a[i];
      ll mod = money % a[i];
      money = mod;
      cnt = div;
      have = true;
    }
  }
  cout << money << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll money = 1000;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool have = false;
  for (ll i = 0; i < n; i++) {
    if (have) {
      if (i == n - 1) {
        while (cnt > 0) {
          money += a[i];
          cnt--;
        }
        continue;
      }
      if (a[i] < a[i + 1]) {
        continue;
      }
      while (cnt > 0) {
        money += a[i];
        cnt--;
      }
      have = false;
    } else {
      if (i == n - 1) {
        continue;
      }
      if (a[i] > a[i + 1]) {
        continue;
      }
      while (money >= a[i]) {
        money -= a[i];
        cnt++;
      }
      have = true;
    }
  }
  cout << money << endl;
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7 /*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
//
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll total = 1000, cap = 0;
  int cur = 0;
  for (int i = 0; i < n - 1; i++) {
    if (cur == 0) {
      if (a[i] == a[i + 1])
        cur = 0;
      if (a[i] < a[i + 1]) {
        cap = total / a[i];
        total %= a[i];
        cur = 1;
      }
      if (a[i] > a[i + 1])
        cur = -1;
    } else if (cur == 1) {
      if (a[i] > a[i + 1]) {
        total += cap * a[i];
        cap = 0;
        cur = -1;
      }
    } else {
      if (a[i] < a[i + 1]) {
        cap = total / a[i];
        total %= a[i];
        cur = 1;
      }
    }
  }
  total += cap * a[n - 1];
  cout << total;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7 /*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
//
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<vector<int>> dp(n + 1, vector<int>(20000, -1));
  dp[0][1000] = 0;
  for (int i = 0; i < n; i++) {
    // cout << i << "\\n";
    for (int j = 0; j < 20000; j++) {
      if (dp[i][j] >= 0) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        int k = j - a[i];
        while (k >= 0) {
          dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + (j - k) / a[i]);
          k -= a[i];
        }
        int t = dp[i][j];
        for (int l = 1; l <= t; l++) {
          dp[i][j + l * a[i]] = max(dp[i][j + l * a[i]], dp[i][j] - l);
        }
      }
    }
    /*for(int j = 0; j < 20000; j++){
        if(dp[i][j] >= 0){cout << j << " " << dp[i][j] << "\\n";}
    }*/
  }
  for (int i = 19999; i >= 0; i--) {
    if (dp[n][i] >= 0) {
      cout << i << "\\n";
      break;
    }
  }
}
Problem p02603 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long N, std::vector<long long> A) {
  long long money = 1000;
  long long stock = 0;

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

  cout << money << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

long long N;
std::vector<long long> A;

set<int> buy_point;
set<int> sell_point;
map<pair<long long, long long>, long long> memo[81];
long long dfs(long long i, long long money, long long stock) {
  if (i == N)
    return money;
  auto it = memo[i].find(make_pair(money, stock));
  if (it != memo[i].end())
    return it->second;

  auto a = dfs(i + 1, money, stock);
  auto b = 0LL;
  auto c = 0LL;
  if (buy_point.find(i) != buy_point.end()) {
    b = dfs(i + 1, money % A[i], stock + money / A[i]);
  }
  if (sell_point.find(i) != sell_point.end()) {
    c = dfs(i + 1, money + stock * A[i], 0);
  }
  auto ret = max({a, b, c});
  memo[i][make_pair(money, stock)] = ret;
  return ret;
}

void solve(long long N_, std::vector<long long> A_) {
  N = N_;
  A = A_;
  buy_point.insert(0);
  sell_point.insert(N - 1);

  rep(i, N) {
    if (i == 0 || i == N - 1)
      continue;
    if (A[i - 1] < A[i])
      sell_point.insert(i);
    if (A[i - 1] > A[i])
      buy_point.insert(i);
  }
  cout << dfs(0, 1000, 0) << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}
Problem p02603 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int n, now = 1000;
  cin >> n;
  int a[n + 1], j = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[j];
    if (j != 1 && a[j] != a[j - 1]) {
      j++;
    }
    if (j == 1) {
      j++;
    }
  }
  j--;
  for (int i = 1; i < j; i++) {
    if (a[i + 1] > a[i]) {
      now = now % a[i] + now / a[i] * a[i + 1];
    }
  }
  cout << now;
  return 0;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int f[1005][5], a[1005];
signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] /= 1000;
  }
  f[0][0] = 1000;
  for (int i = 1; i <= n; i++) {
    int max0 = 0, max1 = 0;
    for (int j = 0; j < i; j++) {
      if (max0 < f[j][0]) {
        max0 = f[j][0];
      }
      if (max1 < f[j][1]) {
        max1 = f[j][1];
      }
    }
    f[i][1] = max0 * a[i];
    f[i][0] = max1 / a[i];
  }
  int maxv = 0;
  for (int i = 0; i <= n; i++) {
    if (maxv < f[i][0]) {
      maxv = f[i][0];
    }
  }
  cout << maxv;
  return 0;
}