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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

deque<int> col;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  col.push_front(a[0]);
  for (int i = 1; i < n; i++) {
    int idx = col.begin() - lower_bound(col.begin(), col.end(), a[i]);
    if (idx == 0) {
      col.push_front(a[i]);
    } else {
      col[idx - 1] = a[i];
    }
  }
  int ans = col.size();
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

deque<int> col;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  col.push_front(a[0]);
  for (int i = 1; i < n; i++) {
    int idx = lower_bound(col.begin(), col.end(), a[i]) - col.begin();
    if (idx == 0) {
      col.push_front(a[i]);
    } else {
      col[idx - 1] = a[i];
    }
  }
  int ans = col.size();
  cout << ans << endl;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), v;
  rep(i, n) cin >> a[i];
  v.push_back(a[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    auto it = lower_bound(v.begin(), v.end(), a[i]);
    while (*it == a[i] && it != v.end()) {
      it++;
    }
    if (it == v.end())
      v.push_back(a[i]);
    else
      *it = a[i];
  }
  cout << v.size() << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n), v;
  rep(i, n) cin >> a[i];
  v.push_back(a[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    auto it = upper_bound(v.begin(), v.end(), a[i]);
    while (*it == a[i] && it != v.end()) {
      it++;
    }
    if (it == v.end())
      v.push_back(a[i]);
    else
      *it = a[i];
  }
  cout << v.size() << endl;
  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  reverse(v.begin(), v.end());

  multiset<int> se;
  for (int i = 0; i < n; i++) {
    auto p = upper_bound(se.begin(), se.end(), v[i]);
    if (p != se.end())
      se.erase(p);

    se.insert(v[i]);
  }

  cout << se.size() << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  reverse(v.begin(), v.end());

  multiset<int> se;
  for (int i = 0; i < n; i++) {
    auto p = se.upper_bound(v[i]);
    if (p != se.end())
      se.erase(p);

    se.insert(v[i]);
  }

  cout << se.size() << endl;
  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc134/tasks/abc134_e
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
struct Dat {
  ll v;
  ll pos;
};
int main() {
#if LOCAL & 01
  std::ifstream in("./test/sample-1.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  ll N;
  cin >> N;
  vector<Dat> an(N);
  for (ll i = 0; i < N; ++i) {
    cin >> an[i].v;
    an[i].pos = i;
  }
#if 1
  multiset<ll> tbl;
  for (auto &a : an) {
    multiset<ll>::iterator it = lower_bound(tbl.begin(), tbl.end(), a.v);
    if (it == tbl.begin()) {
    } else {
      --it;
      tbl.erase(it);
    }
    tbl.insert(a.v);
  }
#else
  vector<Dat> tbl;
  tbl.reserve(N);
  for (auto &a : an) {
    // いれるところ探索
    ll pt = -1;
    ll df = INT64_MAX;
    for (ll i = 0; i < tbl.size(); ++i) {
      auto &&t = tbl[i];
      if (t.v < a.v) {
        ll dff = a.v - t.v;
        if (df > dff) {
          df = dff;
          pt = i;
        }
      }
    }
    if (pt < 0) {
      tbl.push_back(a);
    } else {
      tbl[pt] = a;
    }
  }
#endif
  cout << tbl.size() << endl;
  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/abc134/tasks/abc134_e
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
struct Dat {
  ll v;
  ll pos;
};
int main() {
#if LOCAL & 01
  std::ifstream in("./test/sample-1.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  ll N;
  cin >> N;
  vector<Dat> an(N);
  for (ll i = 0; i < N; ++i) {
    cin >> an[i].v;
    an[i].pos = i;
  }
#if 1
  multiset<ll> tbl;
  for (auto &a : an) {
    // multiset<ll>::iterator it=lower_bound(tbl.begin(),tbl.end(),a.v);
    auto it = tbl.lower_bound(a.v);
    if (it == tbl.begin()) {
    } else {
      --it;
      tbl.erase(it);
    }
    tbl.insert(a.v);
  }
#else
  vector<Dat> tbl;
  tbl.reserve(N);
  for (auto &a : an) {
    // いれるところ探索
    ll pt = -1;
    ll df = INT64_MAX;
    for (ll i = 0; i < tbl.size(); ++i) {
      auto &&t = tbl[i];
      if (t.v < a.v) {
        ll dff = a.v - t.v;
        if (df > dff) {
          df = dff;
          pt = i;
        }
      }
    }
    if (pt < 0) {
      tbl.push_back(a);
    } else {
      tbl[pt] = a;
    }
  }
#endif
  cout << tbl.size() << endl;
  return 0;
}
Problem p02973 (C++)

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

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

long long MOD = 1000000000 + 7;

int main() {
  cout << setprecision(10);
  int N;
  cin >> N;

  deque<ll> q;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    auto itr = lower_bound(q.begin(), q.end(), tmp);
    int index = distance(itr, q.begin());
    if (index == 0) {
      q.push_front(tmp);
    } else {
      q[index - 1] = tmp;
    }
  }
  cout << q.size() << endl;
}


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

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

long long MOD = 1000000000 + 7;

int main() {
  cout << setprecision(10);
  int N;
  cin >> N;

  deque<ll> q;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    auto itr = lower_bound(q.begin(), q.end(), tmp);
    int index = distance(q.begin(), itr);
    if (index == 0) {
      q.push_front(tmp);
    } else {
      q[index - 1] = tmp;
    }
  }
  cout << q.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long> group;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;

    if (group.size() == 0 || group[0] > a) {
      // cout << "Insert top " << a << endl;
      group.insert(group.begin(), a);
    } else {
      auto pos = lower_bound(group.begin(), group.end(), a);
      --pos;
      // cout << "Update " << *pos << " to " << a << endl;
      *pos = a;
    }
  }

  cout << group.size() << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long> group;
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;

    if (group.size() == 0 || group[0] >= a) {
      // cout << "Insert top " << a << endl;
      group.insert(group.begin(), a);
    } else {
      auto pos = lower_bound(group.begin(), group.end(), a);
      --pos;
      // cout << "Update " << *pos << " to " << a << endl;
      *pos = a;
    }
  }

  cout << group.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (int i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  multiset<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    auto it = s.lower_bound(a);
    if ((sz(s) > 0) && (*(--it) < a))
      s.erase(it);
    s.insert(a);
  }
  cout << sz(s) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rreps(i, e, n) for (int i = (n)-1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  multiset<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    auto it = s.lower_bound(a);
    if ((sz(s) > 0) && (it != s.begin()) && (*(--it) < a))
      s.erase(it);
    s.insert(a);
  }
  cout << sz(s) << endl;
  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> p_que;
  int ans = 1;
  p_que.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    auto itr = lower_bound(p_que.begin(), p_que.end(), A[i]);
    int dist = itr - p_que.begin();
    if (dist == 0) {
      ans++;
      p_que.push_back(A[i]);
      sort(p_que.begin(), p_que.end());
    } else {
      p_que[dist - 1] = A[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> p_que;
  int ans = 1;
  p_que.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    auto itr = lower_bound(p_que.begin(), p_que.end(), A[i]);
    int dist = itr - p_que.begin();
    if (dist == 0) {
      ans++;
      p_que.insert(p_que.begin(), A[i]);
    } else {
      p_que[dist - 1] = A[i];
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int n, m = 1;
int a[100000];

int main() {
  cin >> n;

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

  vector<pair<int, int>> c;
  c.push_back(make_pair(a[n - 1], 1));

  for (int i = n - 2; i >= 0; i--) {
    if (a[i] >= c.back().first) {
      m++;
      c.push_back(make_pair(a[i], m));
    } else {
      int j = 0;

      while (a[i] >= c[j].first)
        j++;

      c[j].first = a[i];
      sort(c.begin(), c.end());
    }
  }

  cout << m << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int n, m = 1;
int a[100000];

int main() {
  cin >> n;

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

  vector<pair<int, int>> c;
  c.push_back(make_pair(a[n - 1], 1));

  for (int i = n - 2; i >= 0; i--) {
    if (a[i] >= c.back().first) {
      m++;
      c.push_back(make_pair(a[i], m));
    } else {
      int j = 0;

      while (a[i] >= c[j].first)
        j++;

      c[j].first = a[i];

      while (j > 0 && c[j].first < c[j - 1].first) {
        swap(c[j], c[j - 1]);
        j--;
      }
    }
  }

  cout << m << endl;

  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------

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

  multiset<int> st;

  for (int i = 0; i < n; i++) {
    auto itr = lower_bound(st.begin(), st.end(), a[i]);
    if (itr == st.begin()) {
      st.insert(a[i]);
    } else {
      itr--;
      st.erase(itr);
      st.insert(a[i]);
    }
  }

  cout << st.size() << endl;
}

Fixed submission:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCr(ll n, ll r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}

//-----------------------ここから-----------

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

  multiset<int> st;

  for (int i = 0; i < n; i++) {
    auto itr = st.lower_bound(a[i]);
    if (itr == st.begin()) {
      st.insert(a[i]);
    } else {
      itr--;
      st.erase(itr);
      st.insert(a[i]);
    }
  }

  cout << st.size() << endl;
}
Problem p02973 (C++)

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

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

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

  reverse(a.begin(), a.end());
  vector<int> x;
  x.push_back(1e9 + 100);

  rep(i, 0, n) {
    int j = upper_bound(x.begin(), x.end(), a[i]) - x.begin();
    if (x[j] > 1e9) {
      x[j] = a[i];
      x.push_back(1e9 + 100);
    } else {
      x[j] = a[i];
      sort(x.begin(), x.end());
    }
  }
  cout << x.size() - 1 << endl;

  return 0;
}


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

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

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

  reverse(a.begin(), a.end());
  vector<int> x;
  x.push_back(1e9 + 100);

  rep(i, 0, n) {
    int j = upper_bound(x.begin(), x.end(), a[i]) - x.begin();
    if (x[j] > 1e9) {
      x[j] = a[i];
      x.push_back(1e9 + 100);
    } else {
      x[j] = a[i];
    }
  }
  cout << x.size() - 1 << endl;

  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  multiset<int> mst;
  mst.insert(A[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    if (A[i] <= *(mst.rbegin())) {
      auto it = mst.upper_bound(A[i]);
      if (it != mst.end()) {
        int a = *it;
        int num = mst.erase(*it);
        rep(j, num - 1) mst.insert(a);
      }
    }
    mst.insert(A[i]);
  }
  cout << mst.size() << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  multiset<int> mst;
  mst.insert(A[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    if (A[i] <= *(mst.rbegin())) {
      auto beg = mst.upper_bound(A[i]);
      auto en = beg;
      en++;
      if (beg != mst.end()) {
        mst.erase(beg, en);
      }
    }
    mst.insert(A[i]);
  }
  cout << mst.size() << endl;
  return 0;
}
Problem p02973 (C++)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 998244353
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  vector<ll> res;
  res.push_back(A.at(N - 1));
  for (int i = N - 2; i >= 0; i--) {
    sort(begin(res), end(res));
    auto iter = upper_bound(begin(res), end(res), A.at(i));
    ll dist = distance(begin(res), iter);
    if (dist == (ll)res.size()) {
      res.push_back(A.at(i));
    } else {
      res.at(dist) = A.at(i);
    }
  }
  cout << res.size() << endl;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 998244353
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  vector<ll> res;
  res.push_back(A.at(N - 1));
  for (int i = N - 2; i >= 0; i--) {
    // sort(begin(res),end(res));
    auto iter = upper_bound(begin(res), end(res), A.at(i));
    ll dist = distance(begin(res), iter);
    if (dist == (ll)res.size()) {
      res.push_back(A.at(i));
    } else {
      res.at(dist) = A.at(i);
    }
  }
  cout << res.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
constexpr ll mod = 1000000007;
void pPRINTl(ostream &ost) { ost << endl; }
template <class T> void pPRINTL(ostream &ost, T t) { ost << t << endl; }
template <class T, class... U> void pPRINTl(ostream &ost, T t, U... u) {
  ost << t << " ";
  pPRINTl(ost, u...);
}
template <class... T> void PRINTl(T... t) { pPRINTl(cout, t...); }
// #define PRINTl //
void pPRINT(ostream &ost) {}
template <class T> void pPRINT(ostream &ost, T t) { ost << t; }
template <class T, class... U> void pPRINT(ostream &ost, T t, U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T> void PRINT(T... t) { pPRINT(cout, t...); }

#define DEBUG PRINTl("DEBUG line:", __LINE__)
// #define DEBUG

int main() {

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  vector<int> l;
  l.push_back(a[0]);
  ll min = a[0];
  FOR(i, 1, n) {
    if (min >= a[i]) {
      l.push_back(a[i]);
      min = a[i];
    }
    REP(j, l.size()) {
      if (l[j] < a[i]) {
        l[j] = a[i];
        if (j == l.size() - 1) {
          min = a[i];
        }
        break;
      }
    }
  }

  PRINT(l.size());

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
constexpr ll mod = 1000000007;
void pPRINTl(ostream &ost) { ost << endl; }
template <class T> void pPRINTL(ostream &ost, T t) { ost << t << endl; }
template <class T, class... U> void pPRINTl(ostream &ost, T t, U... u) {
  ost << t << " ";
  pPRINTl(ost, u...);
}
template <class... T> void PRINTl(T... t) { pPRINTl(cout, t...); }
// #define PRINTl //
void pPRINT(ostream &ost) {}
template <class T> void pPRINT(ostream &ost, T t) { ost << t; }
template <class T, class... U> void pPRINT(ostream &ost, T t, U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T> void PRINT(T... t) { pPRINT(cout, t...); }

#define DEBUG PRINTl("DEBUG line:", __LINE__)
// #define DEBUG

int main() {

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  vector<int> l;
  l.push_back(a[0]);
  ll min = a[0];
  FOR(i, 1, n) {
    if (min >= a[i]) {
      l.push_back(a[i]);
      min = a[i];
      continue;
    }
    REP(j, l.size()) {
      if (l[j] < a[i]) {
        l[j] = a[i];
        if (j == l.size() - 1) {
          min = a[i];
        }
        break;
      }
    }
  }

  PRINT(l.size());

  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

namespace multiset {

class multiset {
private:
  std::vector<int> tree;
  int MSB;

  void add(int i, int x) {
    for (; i < tree.size(); i += i & -i) {
      tree[i] += x;
    }
  }

  int sum(int i) {
    int res = 0;
    for (; i > 0; i -= i & -i) {
      res += tree[i];
    }
    return res;
  }

  int bisect(int w) {
    int i = 0;
    for (int k = MSB; k > 0; k /= 2) {
      if (i + k < tree.size() && tree[i + k] < w) {
        w -= tree[i + k];
        i += k;
      }
    }
    return i + 1;
  }

  int get_MSB(int N) {
    int i = 1;
    while (i < N) {
      i *= 2;
    }
    return i / 2;
  }

public:
  multiset(int N) : tree(N + 1), MSB(get_MSB(N)) {}
  void insert(int x) { add(x, 1); }
  void erase(int x) { add(x, -1); }
  int lower_bound(int x) {
    int s = sum(x);
    return (s == 0) ? 0 : bisect(s);
  }

  size_t size() { return sum(tree.size() - 1); }
};

} // namespace multiset

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);
  for (auto &&a : A) {
    std::cin >> a;
  }

  std::vector<int> B = A;

  std::sort(begin(B), end(B));
  B.erase(std::unique(begin(B), end(B)), end(B));

  auto f = [&](int val) -> int {
    return std::lower_bound(begin(A), end(A), val) - begin(A) + 1;
  };

  multiset::multiset ms(B.size());
  for (auto a : A) {
    auto i = ms.lower_bound(f(a) - 1);
    if (i != 0) {
      ms.erase(i);
    }
    ms.insert(f(a));
  }

  std::cout << ms.size() << '\n';
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

namespace multiset {

class multiset {
private:
  std::vector<int> tree;
  int MSB;

  void add(int i, int x) {
    for (; i < tree.size(); i += i & -i) {
      tree[i] += x;
    }
  }

  int sum(int i) {
    int res = 0;
    for (; i > 0; i -= i & -i) {
      res += tree[i];
    }
    return res;
  }

  int bisect(int w) {
    int i = 0;
    for (int k = MSB; k > 0; k /= 2) {
      if (i + k < tree.size() && tree[i + k] < w) {
        w -= tree[i + k];
        i += k;
      }
    }
    return i + 1;
  }

  int get_MSB(int N) {
    int i = 1;
    while (i < N) {
      i *= 2;
    }
    return i / 2;
  }

public:
  multiset(int N) : tree(N + 1), MSB(get_MSB(N)) {}
  void insert(int x) { add(x, 1); }
  void erase(int x) { add(x, -1); }
  int lower_bound(int x) {
    int s = sum(x);
    return (s == 0) ? 0 : bisect(s);
  }

  size_t size() { return sum(tree.size() - 1); }
};

} // namespace multiset

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);
  for (auto &&a : A) {
    std::cin >> a;
  }

  std::vector<int> B = A;

  std::sort(begin(B), end(B));
  B.erase(std::unique(begin(B), end(B)), end(B));

  auto f = [&](int val) -> int {
    return std::lower_bound(begin(B), end(B), val) - begin(B) + 1;
  };

  multiset::multiset ms(B.size());
  for (auto a : A) {
    auto i = ms.lower_bound(f(a) - 1);
    if (i != 0) {
      ms.erase(i);
    }
    ms.insert(f(a));
  }

  std::cout << ms.size() << '\n';
}
Problem p02973 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> rights(1, -1);

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (a <= rights[rights.size() - 1]) {
      rights.push_back(a);
      continue;
    }

    for (int j = 0; j < (int)rights.size(); j++) {
      if (rights[j] < a) {
        rights[j] = a;
        sort(rights.begin(), rights.end(), greater<int>());
        break;
      }
    }
  }

  cout << rights.size() << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> rights(1, -1);

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (a <= rights[rights.size() - 1]) {
      rights.push_back(a);
      continue;
    }

    for (int j = 0; j < (int)rights.size(); j++) {
      if (rights[j] < a) {
        rights[j] = a;
        break;
      }
    }
  }

  cout << rights.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> v;
  int ans = 200000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    auto j = upper_bound(v.begin(), v.end(), a, greater<int>());
    if (j == v.end())
      v.push_back(a);
    else
      v[j - v.begin() - 1] = a;
  }
  cout << v.size();
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> v;
  int ans = 200000;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    auto j = upper_bound(v.begin(), v.end(), a, greater<int>());
    if (j == v.end())
      v.push_back(a);
    else
      *j = a;
  }
  cout << v.size();
}
Problem p02973 (C++)

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  multiset<int> T;
  int cnt = 1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  T.insert(A[0]);
  T.insert(INF);
  for (int i = 1; i < N; i++) {
    if (*T.begin() >= A[i])
      T.insert(A[i]);
    else {
      auto past = T.begin();
      for (auto it = T.begin(); it != T.end(); it++) {
        // cout << i << " " << *it << endl;
        if (*it >= A[i]) {
          T.erase(past);
          T.insert(A[i]);
          break;
        }
        past = it;
      }
    }
    /*cout << i << " ";
    for(auto it1 = T.begin(); it1 != (T.end()++); it1++) cout << " " << (*it1);
    cout << endl;*/
  }
  cout << T.size() - 1 << endl;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  multiset<int> T;
  int cnt = 1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  T.insert(A[0]);
  T.insert(INF);
  for (int i = 1; i < N; i++) {
    if (*T.begin() >= A[i])
      T.insert(A[i]);
    else {
      auto past = T.begin();
      auto it = T.lower_bound(A[i]);
      it--;
      T.erase(it);
      T.insert(A[i]);
      /*for(auto it = T.begin(); it != T.end(); it++){
          //cout << i << " " << *it << endl;
          if(*it >= A[i]){
              T.erase(past);
              T.insert(A[i]);
              break;
          }
          past = it;
      }*/
    }
    /*cout << i << " ";
    for(auto it1 = T.begin(); it1 != (T.end()++); it1++) cout << " " << (*it1);
    cout << endl;*/
  }
  cout << T.size() - 1 << endl;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

#define mmum 1e9
using vint = vector<int>;
using vvint = vector<vector<int>>;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vint a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    t = mmum - t;
    auto it = upper_bound(a.begin(), a.end(), t);
    if (it != a.end()) {
      *it = t;
      sort(a.begin(), a.end());
    } else
      a.push_back(t);
  }
  cout << a.size() << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

#define mmum 1e9
using vint = vector<int>;
using vvint = vector<vector<int>>;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vint a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    t = mmum - t;
    auto it = upper_bound(a.begin(), a.end(), t);
    if (it != a.end()) {
      *it = t;
    } else
      a.push_back(t);
  }
  cout << a.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Runtime Error):
// ~/Remember,remember the 6th of March

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] *= -1;
  }
  vector<int> lcs;
  for (int i = 0; i < n; i++) {
    int ind = upper_bound(lcs.begin(), lcs.end(), arr[i]) - lcs.begin();
    if (ind == lcs.size())
      lcs.push_back(arr[i]);
    else
      lcs[ind] = arr[arr[i]];
  }
  cout << lcs.size() << endl;
  return 0;
}


Fixed submission:
// ~/Remember,remember the 6th of March

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] *= -1;
  }
  vector<int> lcs;
  for (int i = 0; i < n; i++) {
    int ind = upper_bound(lcs.begin(), lcs.end(), arr[i]) - lcs.begin();
    if (ind == lcs.size())
      lcs.push_back(arr[i]);
    else
      lcs[ind] = arr[i];
  }
  cout << lcs.size() << endl;
  return 0;
}
Problem p02973 (C++)

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

using namespace std;
typedef long long ll;

ll N;
ll A[100001];
deque<ll> v;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  v.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    auto itr = lower_bound(v.begin(), v.end(), A[i]);
    if (itr == v.begin())
      v.push_front(A[i]);
    *(itr - 1) = A[i];
  }
  cout << v.size() << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll N;
ll A[100001];
deque<ll> v;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  v.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    auto itr = lower_bound(v.begin(), v.end(), A[i]);
    if (itr == v.begin())
      v.push_front(A[i]);
    else
      *(itr - 1) = A[i];
  }
  cout << v.size() << endl;
  return 0;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  multiset<int> st;
  for (int i = 0; i < n; i++) {
    auto p = upper_bound(ALL(st), -a[i]);
    if (p == st.end()) {
      ans++;
    } else {
      st.erase(p);
    }
    st.insert(-a[i]);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  multiset<int> st;
  for (int i = 0; i < n; i++) {
    auto p = st.upper_bound(-a[i]);
    if (p == st.end()) {
      ans++;
    } else {
      st.erase(p);
    }
    st.insert(-a[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02973 (C++)

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b.push_back(-a[0]);
  for (int i = 1; i < n; i++) {
    auto iter = upper_bound(b.begin(), b.end(), -a[i]);
    // cout << *iter << endl;
    if (iter == b.end()) {
      b.push_back(-a[i]);
      continue;
    }
    *(--iter) = -a[i];
  }
  /*
  for(ll bi: b){
      cout << bi << endl;
  }
  */
  cout << b.size() << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b.push_back(-a[0]);
  for (int i = 1; i < n; i++) {
    auto iter = upper_bound(b.begin(), b.end(), -a[i]);
    // cout << *iter << endl;
    if (iter == b.end()) {
      b.push_back(-a[i]);
      continue;
    }
    *(iter) = -a[i];
  }
  /*
  for(ll bi: b){
      cout << bi << endl;
  }
  */
  cout << b.size() << endl;
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
typedef pair<long long, long long> pll;

ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
bool cmp(int a, int b) { return a > b; }

const ll mod = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod) {
  if (k == 0)
    return 1;
  long long r = modpow(n * n % mod, k >> 1, mod);
  if (k & 1)
    r = r * n % mod;
  return r;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  multiset<int> s;
  int ans = 1;
  s.insert(a[0]);
  for (int i = 1; i < n; i++) {
    auto it = lower_bound(s.begin(), s.end(), a[i]);
    if (it == s.begin())
      s.insert(a[i]);
    else {
      it = prev(it);
      s.erase(it);
      s.insert(a[i]);
    }
  }
  cout << s.size();
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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;
typedef pair<long long, long long> pll;

ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }
bool cmp(int a, int b) { return a > b; }

const ll mod = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
const ld pi = 3.141592653589793;

long long modpow(long long n, long long k, long long mod) {
  if (k == 0)
    return 1;
  long long r = modpow(n * n % mod, k >> 1, mod);
  if (k & 1)
    r = r * n % mod;
  return r;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  multiset<int> s;
  int ans = 1;
  s.insert(a[0]);
  for (int i = 1; i < n; i++) {
    auto it = s.lower_bound(a[i]);
    if (it == s.begin())
      s.insert(a[i]);
    else {
      it = prev(it);
      s.erase(it);
      s.insert(a[i]);
    }
  }
  cout << s.size();
}

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

Buggy submission (status: Time Limit Exceeded):
// q055.cpp
// Tue Aug 25 22:09:54 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

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

  multiset<int> ms;
  rep(i, n) {
    auto itr = lower_bound(ms.begin(), ms.end(), a[i]);
    if (itr != ms.begin()) {
      itr--;
      ms.erase(itr);
    }
    ms.insert(a[i]);
  }

  cout << ms.size() << endl;
  //	printf("%.4f\n",ans);
}

Fixed submission:
// q055.cpp
// Tue Aug 25 22:09:54 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

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

  multiset<int> ms;
  rep(i, n) {
    auto itr = ms.lower_bound(a[i]);
    if (itr != ms.begin()) {
      itr--;
      ms.erase(itr);
    }
    ms.insert(a[i]);
  }

  cout << ms.size() << endl;
  //	printf("%.4f\n",ans);
}
Problem p02973 (C++)

Buggy submission (status: Time Limit Exceeded):
// abc134.cpp
// Sat Oct 12 12:39:21 2019

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

  int a[n];
  vector<int> heads;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (heads.size() == 0) {
      heads.push_back(a);
    } else {
      if (a <= heads[0]) {
        heads.push_back(a);
        sort(heads.begin(), heads.end());
      } else {
        auto iter = lower_bound(heads.begin(), heads.end(), a);
        heads[iter - heads.begin() - 1] = a;
      }
    }
  }

  cout << heads.size() << endl;
  //	printf("%.4f\n",ans);
}

Fixed submission:
// abc134.cpp
// Sat Oct 12 12:39:21 2019

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

  int a[n];
  vector<int> heads;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (heads.size() == 0) {
      heads.push_back(a);
    } else {
      if (a <= heads[0]) {
        heads.insert(heads.begin(), a);
      } else {
        auto iter = lower_bound(heads.begin(), heads.end(), a);
        heads[iter - heads.begin() - 1] = a;
      }
    }
  }

  cout << heads.size() << endl;
  //	printf("%.4f\n",ans);
}
Problem p02973 (C++)

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

int main() {
  int n;
  while (cin >> n) {
    multiset<int> LIS;
    int temp;
    cin >> temp;
    LIS.insert(temp);
    for (int i = 1; i < n; i++) {
      cin >> temp;
      if (temp <= *LIS.begin()) {
        LIS.insert(temp);
      } else {
        auto p = lower_bound(LIS.begin(), LIS.end(), temp);
        if (p != LIS.begin())
          p--;
        LIS.erase(p);
        LIS.insert(temp);
      }
    }
    cout << LIS.size() << endl;
  }
  return 0;
}


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

int main() {
  int n;
  while (cin >> n) {
    multiset<int> LIS;
    int temp;
    cin >> temp;
    LIS.insert(temp);
    for (int i = 1; i < n; i++) {
      cin >> temp;
      if (temp <= *LIS.begin()) {
        LIS.insert(temp);
      } else {
        auto p = LIS.lower_bound(temp);
        if (p != LIS.begin())
          p--;
        LIS.erase(p);
        LIS.insert(temp);
      }
    }
    cout << LIS.size() << endl;
  }
  return 0;
}
Problem p02974 (C++)

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

using namespace std;

using ll = long long;

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

  const ll MOD = 1e9 + 7;

  ll N, K;
  cin >> N >> K;

  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(N + 1, vector<ll>(K + 1)));
  dp[0][0][0] = 1;

  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 2 * j; k <= K; ++k) {
        ll &v = dp[i][j][k];
        (v += (2 * j + 1) * dp[i - 1][j][k - 2 * j]) %= MOD;
        (v += (j + 1) * (j + 1) * dp[i - 1][j + 1][k - 2 * j]) %= MOD;
        if (0 <= j - 1)
          (v += dp[i - 1][j - 1][k - 2 * j]) %= MOD;
      }
    }
  }

  cout << dp[N][0][K] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

  const ll MOD = 1e9 + 7;

  ll N, K;
  cin >> N >> K;

  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(N + 2, vector<ll>(K + 1)));
  dp[0][0][0] = 1;

  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 2 * j; k <= K; ++k) {
        ll &v = dp[i][j][k];
        (v += (2 * j + 1) * dp[i - 1][j][k - 2 * j]) %= MOD;
        (v += (j + 1) * (j + 1) * dp[i - 1][j + 1][k - 2 * j]) %= MOD;
        if (0 <= j - 1)
          (v += dp[i - 1][j - 1][k - 2 * j]) %= MOD;
      }
    }
  }

  cout << dp[N][0][K] << endl;

  return 0;
}
Problem p02974 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

const int mod = (int)1e9 + 7;

inline void addmod(int &a, int b) {
  a += b;
  a %= mod;
}

int main() {
  const int mid = 1300;
  static int pdp[2501][51] = {}, dp[2501][51] = {};
  int n, k;
  cin >> n >> k;
  if (k % 2 != 0) {
    cout << 0 << endl;
    cerr << "bad" << endl;
    return 0;
  }
  k /= 2;
  dp[mid][0] = 1;
  int mxSum = n * (n - 1) / 2;
  int lSum = mid - mxSum, rSum = mid + mxSum;
  for (int step = 0; step < n; ++step) {
    for (int sum = lSum; sum <= rSum; ++sum) {
      for (int p = 0; p <= step; ++p) {
        pdp[sum][p] = dp[sum][p];
        dp[sum][p] = 0;
      }
    }
    for (int sum = lSum; sum <= rSum; ++sum) {
      for (int p = 0; p <= step; ++p) {
        if (!pdp[sum][p]) {
          continue;
        }
        int64_t val = pdp[sum][p];
        // place is L, item is L
        addmod(dp[sum][p], val * (p + 1) % mod);
        // place is L, item is S
        addmod(dp[sum - step][p + 1], val);
        // place is S, item is L
        if (p)
          addmod(dp[sum + step][p - 1], val * p * p % mod);
        // place is S, item is S
        if (p)
          addmod(dp[sum][p], val * p % mod);
      }
    }
  }
  cout << dp[k + mid][0] << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

const int mod = (int)1e9 + 7;

inline void addmod(int &a, int b) {
  a += b;
  a %= mod;
}

int main() {
  const int mid = 1300;
  static int pdp[2601][51] = {}, dp[2601][51] = {};
  int n, k;
  cin >> n >> k;
  if (k % 2 != 0) {
    cout << 0 << endl;
    cerr << "bad" << endl;
    return 0;
  }
  k /= 2;
  dp[mid][0] = 1;
  int mxSum = n * (n - 1) / 2;
  int lSum = mid - mxSum, rSum = mid + mxSum;
  for (int step = 0; step < n; ++step) {
    for (int sum = lSum; sum <= rSum; ++sum) {
      for (int p = 0; p <= step; ++p) {
        pdp[sum][p] = dp[sum][p];
        dp[sum][p] = 0;
      }
    }
    for (int sum = lSum; sum <= rSum; ++sum) {
      for (int p = 0; p <= step; ++p) {
        if (!pdp[sum][p]) {
          continue;
        }
        int64_t val = pdp[sum][p];
        // place is L, item is L
        addmod(dp[sum][p], val * (p + 1) % mod);
        // place is L, item is S
        addmod(dp[sum - step][p + 1], val);
        // place is S, item is L
        if (p)
          addmod(dp[sum + step][p - 1], val * p * p % mod);
        // place is S, item is S
        if (p)
          addmod(dp[sum][p], val * p % mod);
      }
    }
  }
  cout << dp[k + mid][0] << endl;
  return 0;
}