prithivMLmods/Coder-Stat huggingface dataset:
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 1e5 + 10;
int a[mxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  for (int i = k + 1; i <= n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes\n";
    else
      cout << "No\n";
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 2e5 + 10;
int a[mxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  for (int i = k + 1; i <= n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes\n";
    else
      cout << "No\n";
  }

  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1001001001
using ll = long long;
using dd = long double;

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());

  ll n, k;
  cin >> n >> k;
  vector<ll> v(n + 10, 1);
  vector<ll> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    if (i < k) {
      v[k - 1] *= A[i];
    };
  }
  for (int i = k; i < n; ++i) {
    // v[i] = (v[i-1]/A[i-k])*A[i];
    // if (v[i] > v[i-1]) {
    if (A[i] > A[i - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1001001001
using ll = long long;
using dd = long double;

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n + 10, 1);
  vector<ll> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    if (i < k) {
      v[k - 1] *= A[i];
    };
  }
  for (int i = k; i < n; ++i) {
    // v[i] = (v[i-1]/A[i-k])*A[i];
    // if (v[i] > v[i-1]) {
    if (A[i] > A[i - k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
bool cmp(long long int x, long long int y) { return x > y; }
int main(void) {
  long long int t, n, m, k, x, y, a[100001];
  vector<long long int> v, v1, v2;
  vector<pair<long long int, long long int>> p, p1, p2;
  set<long long int> st;
  priority_queue<long long int> pq;
  priority_queue<long long int, vector<long long int>, greater<long long int>>
      lpq;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      plpq;
  string s;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = k; i < n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool cmp(long long int x, long long int y) { return x > y; }
int main(void) {
  long long int t, n, m, k, x, y, a[200001];
  vector<long long int> v, v1, v2;
  vector<pair<long long int, long long int>> p, p1, p2;
  set<long long int> st;
  priority_queue<long long int> pq;
  priority_queue<long long int, vector<long long int>, greater<long long int>>
      lpq;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      plpq;
  string s;
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = k; i < n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k;
ll a[100005];
int main(void) {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i >= k) {
      if (a[i] > a[i - k]) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k;
ll a[200005];
int main(void) {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i >= k) {
      if (a[i] > a[i - k]) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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 int INF = 1001001001;
vector<pair<int64_t, int64_t>> prime_factorize(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}
int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int64_t> table(N + 1);
  table[0] = 1;
  int64_t sum = 1;
  for (int i = 0; i < N; i++) {
    sum *= A[i];
    table[i + 1] = sum;
  }

  for (int i = K; i <= N - 1; i++) {
    if (table[i] / table[i - K] < table[i + 1] / table[i + 1 - K]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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 int INF = 1001001001;
vector<pair<int64_t, int64_t>> prime_factorize(int64_t x) {
  vector<pair<int64_t, int64_t>> p;
  for (int64_t i = 2; i * i <= x; i++) {
    int cnt = 0;
    if (x % i == 0) {
      while (x % i == 0) {
        cnt++;
        x /= i;
      }
      p.push_back(make_pair(i, cnt));
    }
  }
  if (x != 1) {
    p.push_back(make_pair(x, 1));
  }
  return p;
}
int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int64_t i = K; i < N; i++) {
    if (A[i - K] < A[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - k; i++) {
    if (a[i + k] > a[i])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--)
    solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - k; i++) {
    if (a[i + k] > a[i])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, K;
  cin >> N >> K;

  long long A[N + 1];

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  long long past = 0;
  long long current = 0;

  for (int i = 1; i <= K; i++) {
    past += A[i];
  }

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

  return 0;
}


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

int main() {
  long long N, K;
  cin >> N >> K;

  long long A[N + 1];

  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  long long past = 0;
  long long current = 0;

  for (int i = 1; i <= K; i++) {
    past += A[i];
  }

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

  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  x *= f;
  return;
}
template <typename T> void write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + '0');
  return;
}
const int MAXN = 100010;
int n, k;
int a[MAXN];
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; ++i)
    read(a[i]);
  for (int i = k + 1; i <= n; ++i)
    if (a[i] > a[i - k])
      printf("Yes\n");
    else
      printf("No\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  x *= f;
  return;
}
template <typename T> void write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + '0');
  return;
}
const int MAXN = 200010;
int n, k;
int a[MAXN];
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; ++i)
    read(a[i]);
  for (int i = k + 1; i <= n; ++i)
    if (a[i] > a[i - k])
      printf("Yes\n");
    else
      printf("No\n");
  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;

int main() {
  std::ios::sync_with_stdio(false);
  lld tc = 1;
  // cin >> tc;
  while (tc--) {
    lld n, k;
    cin >> n >> k;
    vector<lld> v(n);
    for (lld i = 0; i < n; i++) {
      cin >> v[i];
    }
    map<lld, lld> mp;
    for (lld i = 0; i < k; i++) {
      mp[v[i]]++;
    }
    for (lld i = k; i < n; i++) {
      map<lld, lld> pre = mp;
      mp[v[i - k]]--;
      mp[v[i]]++;
      if (v[i] > v[i - k]) {
        cout << "Yes\n";
      } else {
        cout << "No\n";
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;

int main() {
  std::ios::sync_with_stdio(false);
  lld tc = 1;
  // cin >> tc;
  while (tc--) {
    lld n, k;
    cin >> n >> k;
    vector<lld> v(n);
    for (lld i = 0; i < n; i++) {
      cin >> v[i];
    }
    map<lld, lld> mp;
    for (lld i = 0; i < k; i++) {
      mp[v[i]]++;
    }
    for (lld i = k; i < n; i++) {
      mp[v[i - k]]--;
      mp[v[i]]++;
      if (v[i] > v[i - k]) {
        cout << "Yes\n";
      } else {
        cout << "No\n";
      }
    }
  }
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {

  int a[2000], n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n - k; i++) {
    if (a[i] / a[i + k] > 0)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {

  int a[200005], n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n - k; i++) {
    if (a[i] / a[i + k] > 0)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}
Problem p02602 (C++)

Buggy submission (status: Runtime Error):
/***** author :  C0d1ngPhenomena *****/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define TestCases                                                              \
  int T;                                                                       \
  cin >> T;                                                                    \
  while (T--)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define revrep(i, a, b) for (ll i = b - 1; i >= a; i--)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp(x, y) make_pair(x, y)
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define alld(c) c.begin(), c.end(), greater<int>()
#define mem(a, val) memset(a, val, sizeof(a))
#define f first
#define s second
#define pb push_back
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vll arr(n);
  rep(i, 0, n) cin >> arr[i];

  rep(i, 0, n - k) {
    if (arr[i] * arr[k - 1 + i] < arr[i + i] * arr[k + i])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
/***** author :  C0d1ngPhenomena *****/

#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define TestCases                                                              \
  int T;                                                                       \
  cin >> T;                                                                    \
  while (T--)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define revrep(i, a, b) for (ll i = b - 1; i >= a; i--)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp(x, y) make_pair(x, y)
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define alld(c) c.begin(), c.end(), greater<int>()
#define mem(a, val) memset(a, val, sizeof(a))
#define f first
#define s second
#define pb push_back
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, k;
  cin >> n >> k;
  vll arr(n);
  rep(i, 0, n) cin >> arr[i];

  rep(i, 0, n - k) {
    if (arr[i] < arr[k + i])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}
Problem p02603 (C++)

Buggy submission (status: 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)) {
      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;
}

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)) {
      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;
}
Problem p02603 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

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

  ull m = 1000;
  ull c = 0;

  rep(i, n) {
    // cout << i << "日目: " << a[i] << endl;
    int cur = a[i];
    int pos = 0;
    for (int j = i + 1; j <= n; j++) {
      if (cur < a[j]) {
        pos = 1;
        break;
      }
      if (cur > a[j]) {
        pos = -1;
        break;
      }
    }
    ull curm = cur;
    if (pos == 1 && m >= curm) {
      c = m / cur;
      m = m - c * cur;
    } else if (pos == -1) {
      m = m + c * cur;
      c = 0;
    }
    // cout << m << " " << c << endl;
  }
  cout << m;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 100);
  rep(i, n) { cin >> a[i]; }
  a[n + 1] = a[n];

  ull m = 1000;
  ull c = 0;

  rep(i, n) {
    // cout << i << "日目: " << a[i] << endl;
    int cur = a[i];
    int pos = 0;
    for (int j = i + 1; j <= n; j++) {
      if (cur < a[j]) {
        pos = 1;
        break;
      }
      if (cur > a[j]) {
        pos = -1;
        break;
      }
    }
    ull curm = cur;
    if (pos == 1 && m >= curm) {
      c = m / cur;
      m = m - c * cur;
    } else if (pos == -1) {
      m = m + c * cur;
      c = 0;
    }
    // cout << m << " " << c << endl;
  }
  cout << m;
}
Problem p02603 (C++)

Buggy submission (status: 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];
      }

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

  cout << money << endl;
}

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];
       }*/
      beat += money / A[i];
      money = money % A[i];

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

  cout << money << endl;
}
Problem p02603 (C++)

Buggy submission (status: 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]) {
      while (money >= A[i]) {
        money -= A[i];
        stock++;
      }
    } else if (A[i] > A[i + 1]) {
      money += stock * A[i];
      stock = 0;
    }
  }
  cout << money << endl;
}


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]) {
      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;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
  ll money = 1000;
  ll kabu = 0;
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  bool up = false;
  rep(i, n - 1) {
    bool cup;

    if (vec[i + 1] > vec[i])
      cup = true;
    else if (vec[i + 1] < vec[i])
      cup = false;
    else
      continue;

    if (up && cup)
      continue;
    else if (!up && cup) {
      while (money - vec[i] >= 0) {
        money -= vec[i];
        kabu++;
      }
    } else if (up && !cup) {
      money += kabu * vec[i];
      kabu = 0;
    } else
      continue;

    up = cup;
  }
  if (up)
    money += kabu * vec.back();
  cout << money << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
  ll money = 1000;
  ll kabu = 0;
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  bool up = false;
  rep(i, n - 1) {
    bool cup;

    if (vec[i + 1] > vec[i])
      cup = true;
    else if (vec[i + 1] < vec[i])
      cup = false;
    else
      continue;

    if (up && cup)
      continue;
    else if (!up && cup) {
      kabu = money / vec[i];
      money %= vec[i];
    } else if (up && !cup) {
      money += kabu * vec[i];
      kabu = 0;
    } else
      continue;

    up = cup;
  }
  if (up)
    money += kabu * vec.back();
  cout << money << endl;
  return 0;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  ll money = 1000;
  ll stock = 0;
  for (ll i = 0; i < n; i++) {
    money += a[i] * stock;
    stock = 0;
    if (i != n - 1) {
      if (a[i] < a[i + 1]) {
        while (0 <= money - a[i]) {
          money -= a[i];
          stock++;
        }
      }
    }
  }
  cout << money << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  ll money = 1000;
  ll stock = 0;
  for (ll i = 0; i < n; i++) {
    money += a[i] * stock;
    stock = 0;
    if (i != n - 1) {
      if (a[i] < a[i + 1]) {
        stock = money / a[i];
        money = money % a[i];
      }
    }
  }
  cout << money << endl;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, a[87] = {0};
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll money = 1000;
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1]) {
      cnt += money / a[i];
      while (money >= a[i])
        money -= a[i];
    } else {
      money += cnt * a[i];
      cnt = 0;
    }
  }
  cout << money << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, a[87] = {0};
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll money = 1000;
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1]) {
      cnt += money / a[i];
      ll num = money / a[i];
      money -= a[i] * num;
    } else {
      money += cnt * a[i];
      cnt = 0;
    }
  }
  cout << money << endl;
}
Problem p02603 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 1000
for ii in range(2**n):
    tmp = 1000
    kab = 0
    action = "buy"
    for i in range(n):
        if (ii >> i) & 1:
            if action == "buy":
                if tmp < A[i]:
                    break
                kab += tmp // A[i]
                tmp = tmp % A[i]
                action = "sell"

            elif action == "sell":
                if kab == 0:
                    break
                tmp += kab * A[i]
                kab = 0
                action = "buy"
    else:
        ans = max(ans, tmp)

print(ans)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(n - 1):
    if A[i] < A[i + 1]:
        ans += ans // A[i] * (A[i + 1] - A[i])
print(ans)
Problem p02603 (C++)

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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

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

  vector<int64_t> data(n);
  for (int i = 0; i < n; ++i) {
    cin >> data[i];
  }

  int fin = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (data[i] < data[i + 1]) {
      fin = i;
    }
  }

  int64_t g = 1000LL;
  int64_t k = 0LL;
  for (int i = 0; i < n; ++i) {
    if (i > fin) {
      g += (int64_t)data[i] * k;
      k = 0ll;
      break;
    } else if (data[i] < data[i + 1]) {
      while (g >= data[i]) {
        g -= data[i];
        k++;
      }
      // int num = g / data[i];
      // g -= num * (int64_t)data[i];
      // k += num;
    } else if (data[i] > data[i + 1]) {
      g += int64_t(data[i]) * k;
      k = 0LL;
    }
  }

  cout << g;
  return 0;
}


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

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

  vector<int64_t> data(n);
  for (int i = 0; i < n; ++i) {
    cin >> data[i];
  }

  int fin = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (data[i] < data[i + 1]) {
      fin = i;
    }
  }

  int64_t g = 1000LL;
  int64_t k = 0LL;
  for (int i = 0; i < n; ++i) {
    if (i > fin) {
      g += (int64_t)data[i] * k;
      k = 0ll;
      break;
    } else if (data[i] < data[i + 1]) {
      // while(g >= data[i]) {
      //   g -= data[i];
      //   k ++;
      // }
      int64_t num = g / data[i];
      int64_t u = num * (int64_t)data[i];
      g -= u;
      k += num;
    } else if (data[i] > data[i + 1]) {
      g += int64_t(data[i]) * k;
      k = 0LL;
    }
  }

  cout << g;
  return 0;
}
Problem p02603 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  // your code goes here
  long long n;
  cin >> n;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    long long b;
    cin >> b;
    a.push_back(b);
  }

  long long num = 0;
  long long money = 1000;
  decltype(a)::iterator result = std::unique(a.begin(), a.end());

  // [v.begin(), result)の範囲に、重複を除いた結果が入っている。
  // 不要になった要素を削除
  a.erase(result, a.end());

  // 折り返し地点を探す
  string turn[a.size()];
  for (int i = 1; i < a.size() - 1; i++) {
    if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) {
      turn[i] = "down";
    } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) {
      turn[i] = "up";
    } else {
      turn[i] = "keep";
    }
  }

  if (a.at(0) < a.at(1)) {
    num += money / a.at(0);
    money %= a.at(0);
  }

  for (int i = 0; i < a.size() - 1; i++) {
    if (turn[i] == "down") {
      money += a.at(i) * num;
      num = 0;
    } else if (turn[i] == "up") {
      num += money / a.at(i);
      money %= a.at(i);
    }
  }

  if (a.at(a.size() - 2) < a.at(a.size() - 1)) {
    money += a.at(a.size() - 1) * num;
    num = 0;
  }

  cout << money << endl;

  return 0;
}

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

int main() {
  // your code goes here
  long long n;
  cin >> n;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    long long b;
    cin >> b;
    a.push_back(b);
  }

  long long num = 0;
  long long money = 1000;
  decltype(a)::iterator result = std::unique(a.begin(), a.end());

  // [v.begin(), result)の範囲に、重複を除いた結果が入っている。
  // 不要になった要素を削除
  a.erase(result, a.end());

  if (a.size() == 1) {
    cout << money << endl;
    return 0;
  }

  // 折り返し地点を探す
  string turn[a.size()];
  for (int i = 1; i < a.size() - 1; i++) {
    if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) {
      turn[i] = "down";
    } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) {
      turn[i] = "up";
    } else {
      turn[i] = "keep";
    }
  }

  if (a.at(0) < a.at(1)) {
    num += money / a.at(0);
    money %= a.at(0);
  }

  for (int i = 0; i < a.size() - 1; i++) {
    if (turn[i] == "down") {
      money += a.at(i) * num;
      num = 0;
    } else if (turn[i] == "up") {
      num += money / a.at(i);
      money %= a.at(i);
    }
  }

  if (a.at(a.size() - 2) < a.at(a.size() - 1)) {
    money += a.at(a.size() - 1) * num;
    num = 0;
  }

  cout << money << endl;

  return 0;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):

// TO KAISE HAI AAP LOG!! //

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

#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define F first
#define S second
#define all(v) v.begin(), v.end()
ll mod = 1e9 + 7;

/*/----------------------------- Code begins -----------------------------/*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1, tc;
  // cin>>t;
  for (tc = 1; tc <= t; tc++) {
    ll n, k, i, j, s = 1000, f, m, c, pos;
    cin >> n;
    ll a[n + 5];
    for (i = 0; i < n; i++)
      cin >> a[i];
    for (i = 0; i < n - 1;) {
      f = 0;
      m = a[i];
      j = i + 1;
      while (j < n) {
        if (a[j] > m) {
          f = 1;
          pos = j;
          break;
        }
        m = min(a[j], m);
        j++;
      }
      if (f == 0)
        break;
      c = 0;
      while (s - m >= 0) {
        s -= m;
        c++;
      }
      while (c--) {
        s += a[pos];
      }
      i = j;
    }
    cout << s;
  }
  return 0;
}

Fixed submission:

// TO KAISE HAI AAP LOG!! //

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

#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define F first
#define S second
#define all(v) v.begin(), v.end()
ll mod = 1e9 + 7;

/*/----------------------------- Code begins -----------------------------/*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1, tc;
  // cin>>t;
  for (tc = 1; tc <= t; tc++) {
    ll n, k, i, j, s = 1000, f, m, c, pos;
    cin >> n;
    ll a[n + 5];
    for (i = 0; i < n; i++)
      cin >> a[i];
    for (i = 0; i < n - 1;) {
      f = 0;
      m = a[i];
      j = i + 1;
      while (j < n) {
        if (a[j] > m) {
          f = 1;
          pos = j;
          break;
        }
        m = min(a[j], m);
        j++;
      }
      if (f == 0)
        break;
      c = 0;
      ll x = (s / m);
      s = s - (x * m);
      s = s + (x * a[pos]);
      i = j;
    }
    cout << s;
  }
  return 0;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define FAST                                                                   \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
  }
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll, ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

int main() {
  FAST ll mon = 1000, st = 0;
  ll n;
  cin >> n;
  ll a[n];
  f(i, 0, n) cin >> a[i];
  ll start = 0;
  while (start < n - 1 && a[start] >= a[start + 1])
    start++;
  if (start == n - 1) {
    cout << 1000 << endl;
    return 0;
  }
  while (mon - a[start] >= 0)
    mon -= a[start], st++;
  ll pos = start + 1;
  while (1) {
    while (pos < n - 1 && a[pos] <= a[pos + 1])
      pos++;
    while (st)
      mon += a[pos], st--;
    while (pos < n - 1 && a[pos] >= a[pos + 1])
      pos++;
    if (pos != n - 1) {
      while (mon - a[pos] >= 0)
        mon -= a[pos], st++;
    } else if (pos >= n - 1)
      break;
  }
  cout << mon << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define FAST                                                                   \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
  }
#define f(i, a, b) for (ll i = a; i < b; i++)
#define fr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll, ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

int main() {
  FAST ll mon = 1000, st = 0;
  ll n;
  cin >> n;
  ll a[n];
  f(i, 0, n) cin >> a[i];
  ll start = 0;
  while (start < n - 1 && a[start] >= a[start + 1])
    start++;
  if (start == n - 1) {
    cout << 1000 << endl;
    return 0;
  }
  while (mon - a[start] >= 0)
    mon -= a[start], st++;
  ll pos = start + 1;
  while (1) {
    while (pos < n - 1 && a[pos] <= a[pos + 1])
      pos++;
    while (st)
      mon += a[pos], st--;
    while (pos < n - 1 && a[pos] >= a[pos + 1])
      pos++;
    if (pos != n - 1) {
      st += mon / a[pos];
      mon -= st * a[pos];
    } else if (pos >= n - 1)
      break;
  }
  cout << mon << endl;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll tmp = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      ll cnt = 0;
      while (tmp >= a[i]) {
        tmp -= a[i];
        cnt++;
      }
      tmp += cnt * a[i + 1];
      // cout << tmp << endl;
    }
  }
  cout << tmp << endl;
}

Fixed submission:
// g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll tmp = 1000;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      ll cnt = tmp / a[i];
      tmp -= cnt * a[i];
      tmp += cnt * a[i + 1];
      // cout << tmp << endl;
    }
  }
  cout << tmp << endl;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int a[86];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int sum = 1000, stk = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < a[i + 1]) {
      while (sum > 0) {
        if (sum - a[i] >= 0) {
          sum -= a[i];
          stk++;
        } else {
          break;
        }
      }
    } else {
      sum += stk * a[i];
      stk = 0;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int a[86];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int sum = 1000, stk = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] < a[i + 1]) {
      stk += sum / a[i];
      sum = sum - (sum / a[i] * a[i]);
    } else {
      sum += stk * a[i];
      stk = 0;
    }
  }
  cout << sum << endl;
}
Problem p02603 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  int n, i, j, k;
  cin >> n;
  vector<int> a(n, 0);
  j = 0;
  for (i = 0; i < n; i++) {
    cin >> a.at(j);
    if (j == 0 || a.at(j) != a.at(j - 1)) {
      j++;
    }
  }
  n = j;
  /*for(i=0;i<n;i++){
    cout << a.at(i) << endl;
  }*/
  vector<int> vl(n), mt(n);
  j = 0;
  k = 0;
  if (a.at(0) < a.at(1)) {
    vl.at(0) = a.at(0);
    j = 1;
  }
  for (i = 1; i < n - 1; i++) {
    if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) {
      mt.at(k) = a.at(i);
      k++;
    } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) {
      vl.at(j) = a.at(i);
      j++;
    }
  }

  if (a.at(n - 1) > a.at(n - 2)) {
    mt.at(k) = a.at(n - 1);
    k++;
  }

  /*for(i=0;i<k;i++){
    cout << vl.at(i) << " " << mt.at(i) << endl;
  }*/

  ll money = 1000;
  for (i = 0; i < k; i++) {
    money += (money / vl.at(i)) * (mt.at(i) - vl.at(i));
  }
  cout << money << endl;
}

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

int main() {
  int n, i, j, k;
  cin >> n;
  vector<int> a(n, 0);
  j = 0;
  for (i = 0; i < n; i++) {
    cin >> a.at(j);
    if (j == 0 || a.at(j) != a.at(j - 1)) {
      j++;
    }
  }
  n = j;
  if (n == 1) {
    cout << 1000 << endl;
    return 0;
  }
  /*for(i=0;i<n;i++){
    cout << a.at(i) << endl;
  }*/
  vector<int> vl(n), mt(n);
  j = 0;
  k = 0;
  if (a.at(0) < a.at(1)) {
    vl.at(0) = a.at(0);
    j = 1;
  }
  for (i = 1; i < n - 1; i++) {
    if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) {
      mt.at(k) = a.at(i);
      k++;
    } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) {
      vl.at(j) = a.at(i);
      j++;
    }
  }

  if (a.at(n - 1) > a.at(n - 2)) {
    mt.at(k) = a.at(n - 1);
    k++;
  }

  /*for(i=0;i<k;i++){
    cout << vl.at(i) << " " << mt.at(i) << endl;
  }*/

  ll money = 1000;
  for (i = 0; i < k; i++) {
    money += (money / vl.at(i)) * (mt.at(i) - vl.at(i));
  }
  cout << money << endl;
}
Problem p02603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100;
int a[N];
int main() {
  LL n, num = 1000, num1 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1])
      num1 += num / a[i], num %= a[i];
    else
      num += num1 * a[i], num1 = 0;
  }
  printf("%lld", num);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100;
int a[N];
int main() {
  LL n = 0, num = 1000, num1 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < a[i + 1])
      num1 += num / a[i], num %= a[i];
    else
      num += num1 * a[i], num1 = 0;
  }
  printf("%lld", num);
  return 0;
}
Problem p02604 (C++)

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

const ll INF = 1LL << 62;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n), y(n), p(n);
  rep(i, n) cin >> x[i] >> y[i] >> p[i];

  vector<vector<ll>> xsel(1 << n, vector<ll>(n));
  vector<vector<ll>> ysel(1 << n, vector<ll>(n));
  rep(i, 1 << n) {
    rep(j, n) {
      xsel[i][j] = abs(x[j]);
      ysel[i][j] = abs(y[j]);
      rep(k, n) {
        if ((i >> k) & 1) {
          xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k]));
          ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k]));
        }
      }
    }
  }

  vector<ll> ans(n + 1, INF);
  rep(i, pow(3, n)) {
    int info = i;
    vector<vector<int>> state(3); // 0: x train, 1: y train, 2: no train
    rep(j, n) state[info % 3].push_back(j), info /= 3;

    int xi = 0, yi = 0;
    for (auto a : state[0])
      xi += pow(2, a);
    for (auto a : state[1])
      yi += pow(2, a);

    ll cost = 0;
    for (auto k : state[2])
      cost += 1LL * min(xsel[xi][k], ysel[yi][k]) * p[k];

    int cnt = state[0].size() + state[1].size();
    ans[cnt] = min(ans[cnt], cost);
  }

  for (ll i = 0; i <= n; i++)
    cout << ans[i] << endl;
}


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

const ll INF = 1LL << 62;

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n), y(n), p(n);
  rep(i, n) cin >> x[i] >> y[i] >> p[i];

  vector<vector<ll>> xsel(1 << n, vector<ll>(n));
  vector<vector<ll>> ysel(1 << n, vector<ll>(n));
  rep(i, 1 << n) {
    rep(j, n) {
      xsel[i][j] = abs(x[j]);
      ysel[i][j] = abs(y[j]);
      rep(k, n) {
        if ((i >> k) & 1) {
          xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k]));
          ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k]));
        }
      }
    }
  }

  vector<ll> ans(n + 1, INF);
  rep(i, 1 << n) {
    ll cnt = __builtin_popcount(i);
    for (ll j = i; j >= 0; j--) {
      j &= i;
      ll cost = 0;
      rep(k, n) {
        if (!((i >> k) & 1)) {
          cost += 1LL * min(xsel[j][k], ysel[i - j][k]) * p[k];
        }
      }
      ans[cnt] = min(ans[cnt], cost);
    }
  }

  for (ll i = 0; i <= n; i++)
    cout << ans[i] << endl;
}
Problem p02604 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma G++ optimize(O2)
#pragma G++ optimize(O3)
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 16;
LL res[N];
struct node {
  int x, y, p;
} a[N];
int vis[N];
int dis[N];

void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p);
  }
  memset(res, 0x3f, sizeof res);

  // i：选择哪几个点上添加横线，1为添加，0为不添加
  for (int i = 0; i < (1 << n); i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++)
      if ((i >> j) & 1)
        vis[++cnt] = j + 1;

    // j:选择的点的所有状态，1为x方向，0为y方向
    for (int j = 0; j < (1 << cnt); j++) {

      for (int k = 1; k <= n; k++)
        dis[k] = min(abs(a[k].x), abs(a[k].y));

      for (int k = 0; k < cnt; k++) {
        if ((j >> k) & 1) {
          for (int t = 1; t <= n; t++) {
            dis[t] = min(dis[t], abs(a[t].x - a[vis[k + 1]].x));
          }
        } else {
          for (int t = 1; t <= n; t++) {
            dis[t] = min(dis[t], abs(a[t].y - a[vis[k + 1]].y));
          }
        }
      }
      LL sum = 0;
      for (int k = 1; k <= n; k++)
        sum += (LL)dis[k] * a[k].p;
      res[cnt] = min(res[cnt], sum);
    }
  }
  for (int i = 0; i <= n; i++)
    printf("%lld\n", res[i]);
}

int main() {
  //    freopen("in.txt", "r", stdin);
  solve();
  return 0;
}


Fixed submission:
#pragma G++ optimize(O2)
#pragma G++ optimize(O3)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N = 16;
LL res[N];
struct node {
  int x, y, p;
} a[N];
int vis[N];
int dis[N];

void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p);
  }
  memset(res, 0x3f, sizeof res);

  // i：选择哪几个点上添加横线，1为添加，0为不添加
  for (int i = 0; i < (1 << n); i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++)
      if ((i >> j) & 1)
        vis[++cnt] = j + 1;

    // j:选择的点的所有状态，1为x方向，0为y方向
    for (int j = 0; j < (1 << cnt); j++) {

      for (int k = 1; k <= n; k++)
        dis[k] = min(abs(a[k].x), abs(a[k].y));

      for (int k = 0; k < cnt; k++) {
        if ((j >> k) & 1) {
          for (int t = 1; t <= n; t++) {
            dis[t] = min(dis[t], abs(a[t].x - a[vis[k + 1]].x));
          }
        } else {
          for (int t = 1; t <= n; t++) {
            dis[t] = min(dis[t], abs(a[t].y - a[vis[k + 1]].y));
          }
        }
      }
      LL sum = 0;
      for (int k = 1; k <= n; k++)
        sum += (LL)dis[k] * a[k].p;
      res[cnt] = min(res[cnt], sum);
    }
  }
  for (int i = 0; i <= n; i++)
    printf("%lld\n", res[i]);
}

int main() {
  //    freopen("in.txt", "r", stdin);
  solve();
  return 0;
}