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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> f(n, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      if (tmp == 1)
        f[i] += (1 << j);
    }
  vector<vector<int>> p(n, vector<int>(10));
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 10; j++)
      cin >> p[i][j];

  long long ans = -1000000000009;
  for (int i = 1; i < (1 << 10); i++) {
    // cout << bitset<10>(i) << " ";
    long long tmpans = 0;
    for (int j = 0; j < n; j++) {
      int tmp = (i & f[j]);
      int count = 0;
      for (int k = 0; k <= 10; k++)
        if ((tmp & (1 << k)) != 0)
          count++;
      tmpans += p[j][count];
    }
    if (ans < tmpans) {
      for (int j = 0; j < n; j++) {
        int tmp = (i & f[j]);
        //				cout << "i&f[j] : " << "\n" << "\t" <<
        //bitset<10>(i) << "\n" << "\t" << bitset<10>(f[j]) << "\n" << "\t" <<
        //bitset<10>(tmp) << endl;
        int count = 0;
        for (int k = 0; k <= 10; k++)
          if ((tmp & (1 << k)) != 0)
            count++;
        //				cout << "count :" << count << "   point :" <<
        //p[j][count] << endl;
      }
      //			cout << tmpans << endl;
      ans = tmpans;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> f(n, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) {
      int tmp;
      cin >> tmp;
      if (tmp == 1)
        f[i] += (1 << j);
    }
  vector<vector<int>> p(n, vector<int>(11));
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 10; j++)
      cin >> p[i][j];

  long long ans = -1000000000009;
  for (int i = 1; i < (1 << 10); i++) {
    // cout << bitset<10>(i) << " ";
    long long tmpans = 0;
    for (int j = 0; j < n; j++) {
      int tmp = (i & f[j]);
      int count = 0;
      for (int k = 0; k <= 10; k++)
        if ((tmp & (1 << k)) != 0)
          count++;
      tmpans += p[j][count];
    }
    if (ans < tmpans) {
      for (int j = 0; j < n; j++) {
        int tmp = (i & f[j]);
        //				cout << "i&f[j] : " << "\n" << "\t" <<
        //bitset<10>(i) << "\n" << "\t" << bitset<10>(f[j]) << "\n" << "\t" <<
        //bitset<10>(tmp) << endl;
        int count = 0;
        for (int k = 0; k <= 10; k++)
          if ((tmp & (1 << k)) != 0)
            count++;
        //				cout << "count :" << count << "   point :" <<
        //p[j][count] << endl;
      }
      //			cout << tmpans << endl;
      ans = tmpans;
    }
  }
  cout << ans << endl;
}
Problem p03503 (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 ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10));
  rep(i, n) rep(j, 10) cin >> f[i][j];
  vector<vector<int>> p(n, vector<int>(10));
  rep(i, n) rep(j, 11) cin >> p[i][j];
  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); ++bit) {
    vector<int> cnt(n, 0);
    for (int i = 0; i < 10; ++i) {
      if (bit & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          if (f[j][i])
            cnt[j]++;
        }
      }
    }
    ll tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += p[i][cnt[i]];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10));
  rep(i, n) rep(j, 10) cin >> f[i][j];
  vector<vector<int>> p(n, vector<int>(11));
  rep(i, n) rep(j, 11) cin >> p[i][j];
  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); ++bit) {
    vector<int> cnt(n, 0);
    for (int i = 0; i < 10; ++i) {
      if (bit & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          if (f[j][i])
            cnt[j]++;
        }
      }
    }
    ll tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += p[i][cnt[i]];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);

int main() {
  int n, ans = -1e9 + 7, tmp;
  sc(n) vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(10));
  vector<int> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      sc(f[i][j])
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++)
      sc(p[i][j])
  }
  for (int i = 1; i < (1 << 10); i++) {
    tmp = 0;
    fill(cnt.begin(), cnt.end(), 0);
    for (int j = 0; j < 10; j++) {
      if (!(i & (1 << j)))
        continue;
      for (int k = 0; k < n; k++) {
        if (f[k][j] == 1)
          cnt[k] += 1;
      }
    }
    for (int j = 0; j < n; j++)
      tmp += p[j][cnt[j]];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d", &x);

int main() {
  int n;
  sc(n) ll ans = -1e10, tmp;
  vector<vector<int>> f(n, vector<int>(10)), p(n, vector<int>(11));
  vector<int> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      sc(f[i][j])
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++)
      sc(p[i][j])
  }
  for (int i = 1; i < (1 << 10); i++) {
    tmp = 0;
    fill(cnt.begin(), cnt.end(), 0);
    for (int j = 0; j < 10; j++) {
      if (!(i & (1 << j)))
        continue;
      for (int k = 0; k < n; k++) {
        if (f[k][j] == 1)
          cnt[k] += 1;
      }
    }
    for (int j = 0; j < n; j++)
      tmp += p[j][cnt[j]];
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, d;
  cin >> N;
  vector<int> f(N);
  vector<vector<int>> P(N, vector<int>(10));
  for (int i = 0; i < N; ++i) {
    int number = 0;
    for (int j = 0; j < 10; ++j) {
      cin >> d;
      if (d == 1)
        number += (1 << j);
    }
    f[i] = number;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j)
      cin >> P[i][j];
  }
  int ans = -1e9 - 9;
  for (int i = 1; i < (1 << 10); ++i) {
    int number = 0;
    for (int j = 0; j < N; ++j) {
      number += P[j][__builtin_popcount(f[j] & i)];
    }
    ans = max(ans, number);
  }
  cout << ans << "\n";
  return 0;
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, d;
  cin >> N;
  vector<int> f(N);
  vector<vector<int>> P(N, vector<int>(11));
  for (int i = 0; i < N; ++i) {
    int number = 0;
    for (int j = 0; j < 10; ++j) {
      cin >> d;
      if (d == 1)
        number += (1 << j);
    }
    f[i] = number;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 11; ++j)
      cin >> P[i][j];
  }
  int ans = -1e9 - 9;
  for (int i = 1; i < (1 << 10); ++i) {
    int number = 0;
    for (int j = 0; j < N; ++j) {
      number += P[j][__builtin_popcount(f[j] & i)];
    }
    ans = max(ans, number);
  }
  cout << ans << "\n";
  return 0;
}
Problem p03503 (C++)

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

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve() {
  int n, fin;
  cin >> n;
  vector<ll> f(10);
  vector<vector<ll>> p(n, vector<ll>(11));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 10; ++j) {
      cin >> fin;
      f[i] += (fin << j);
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 11; ++j) {
      cin >> p[i][j];
    }
  ll ans = -1e9;
  for (int mask = 1; mask <= (1 << 10) - 1; ++mask) {
    ll ben = 0;
    for (int i = 0; i < n; ++i) {
      bitset<10> b(mask & f[i]);
      ben += p[i][b.count()];
    }
    ans = max(ans, ben);
  }
  cout << ans;
}

int main() {
  fastio;
  solve();

  return 0;
}

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

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve() {
  int n, fin;
  cin >> n;
  vector<ll> f(n);
  vector<vector<ll>> p(n, vector<ll>(11));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 10; ++j) {
      cin >> fin;
      f[i] += (fin << j);
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 11; ++j) {
      cin >> p[i][j];
    }
  ll ans = -1e9;
  for (int mask = 1; mask <= (1 << 10) - 1; ++mask) {
    ll ben = 0;
    for (int i = 0; i < n; ++i) {
      bitset<10> b(mask & f[i]);
      ben += p[i][b.count()];
    }
    ans = max(ans, ben);
  }
  cout << ans;
}

int main() {
  fastio;
  solve();

  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll n, x, p[1010][1001], f[1010][1001];

ll calc(vector<int> &t) {
  ll cnt[11];
  for (int i = 0; i < 11; i++)
    cnt[i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      if (f[i][j] && t[j])
        cnt[i]++;
  ll ret = 0;
  for (int i = 0; i < n; i++)
    ret += p[i][cnt[i]];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  ll ans = -1000000000000000;
  for (ll i = 1; i < (1LL << 10); i++) {
    vector<int> tmp(11);
    for (int j = 0; j < 10; j++)
      if (i & (1 << j))
        tmp[j] = 1;
    ans = max(ans, calc(tmp));
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

ll n, x, p[1010][1001], f[1010][1001];

ll calc(vector<int> &t) {
  ll cnt[101];
  for (int i = 0; i < 101; i++)
    cnt[i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      if (f[i][j] && t[j])
        cnt[i]++;
  ll ret = 0;
  for (int i = 0; i < n; i++)
    ret += p[i][cnt[i]];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  ll ans = -1000000000000000;
  for (ll i = 1; i < (1LL << 10); i++) {
    vector<int> tmp(11);
    for (int j = 0; j < 10; j++)
      if (i & (1 << j))
        tmp[j] = 1;
    ans = max(ans, calc(tmp));
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

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

using namespace std;

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> f(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      scanf("%d", &f[i][j]);
  }
  vector<vector<int>> p(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++)
      scanf("%d", &p[i][j]);
  }
  long long ans = -INFL;
  for (int use = 1; use < (1 << 10); use++) {
    long long res = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (f[i][j] == 1 && use & (1 << j)) {
          cnt++;
        }
      }
      res += p[i][cnt];
    }
    ans = max(ans, res);
  }
  printf("%lld\n", ans);
  return 0;
}


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

using namespace std;

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> f(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      scanf("%d", &f[i][j]);
  }
  vector<vector<int>> p(n, vector<int>(11));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++)
      scanf("%d", &p[i][j]);
  }
  long long ans = -INFL;
  for (int use = 1; use < (1 << 10); use++) {
    long long res = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (f[i][j] == 1 && use & (1 << j)) {
          cnt++;
        }
      }
      res += p[i][cnt];
    }
    ans = max(ans, res);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

  vector<pair<int, int>> st[30];

  vector<int> tt;

  REP(i, n) {
    int si, ti, ci;
    cin >> si >> ti >> ci;
    auto sti = make_pair(si, ti);
    st[ci - 1].push_back(sti);
    tt.push_back(si);
    tt.push_back(ti - 1);
  }

  sort(ALL(tt));

  REP(i, n)
  sort(ALL(st[i]));

  int maxCount = 0;
  int idx[30] = {
      0,
  };

  for (auto t : tt) {
    int count = 0;
    REP(j, cn) {
      for (;;) {
        if (idx[j] == st[j].size())
          break;

        auto k = st[j][idx[j]];
        if (k.first - 1 <= t && t < k.second) {
          count++;
          break;
        } else if (k.second <= t) {
          idx[j]++;
        } else {
          break;
        }
      }
    }
    maxCount = max(maxCount, count);
  }

  cout << maxCount << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

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

  vector<pair<int, int>> st[30];

  vector<int> tt;

  REP(i, n) {
    int si, ti, ci;
    cin >> si >> ti >> ci;
    auto sti = make_pair(si, ti);
    st[ci - 1].push_back(sti);
    tt.push_back(si);
    tt.push_back(ti - 1);
  }

  sort(ALL(tt));

  REP(i, cn)
  sort(ALL(st[i]));

  int maxCount = 0;
  int idx[30] = {
      0,
  };

  for (auto t : tt) {
    int count = 0;
    REP(j, cn) {
      for (;;) {
        if (idx[j] == st[j].size())
          break;

        auto k = st[j][idx[j]];
        if (k.first - 1 <= t && t < k.second) {
          count++;
          break;
        } else if (k.second <= t) {
          idx[j]++;
        } else {
          break;
        }
      }
    }
    maxCount = max(maxCount, count);
  }

  cout << maxCount << endl;

  return 0;
}
Problem p03504 (C++)

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

int main(void) {
  int n, c;
  cin >> n >> c;

  bool record[30][100000] = {{false}};
  int recorder[100000] = {0};
  int s, t;
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> s >> t >> c;
    for (j = s; j <= t; j++) {
      if (!record[c][j]) {
        recorder[j]++;
      }
      record[c][j] = true;
    }
  }

  sort(recorder, recorder + 100000, greater<int>());
  cout << recorder[0] << endl;

  return 0;
}


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

int main(void) {
  int n, c;
  cin >> n >> c;

  bool record[31][100000] = {{false}};
  int recorder[100000] = {0};
  int s, t;
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> s >> t >> c;
    for (j = s; j <= t; j++) {
      if (!record[c][j]) {
        recorder[j]++;
      }
      record[c][j] = true;
    }
  }

  sort(recorder, recorder + 100000, greater<int>());
  cout << recorder[0] << endl;

  return 0;
}
Problem p03504 (C++)

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

int main() {
  int N, C, M = 1e5;
  cin >> N >> C;
  vector<vector<int>> V(C, vector<int>(M));
  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    s--, c--;
    V.at(c).at(s)++;
    V.at(c).at(t)--;
  }
  for (int i = 0; i < C; i++) {
    for (int j = 1; j < M; j++) {
      V.at(i).at(j) += V.at(i).at(j - 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < C; j++) {
      if (V.at(j).at(i) == 2)
        V.at(j).at(i) = 1;
      sum += V.at(j).at(i);
    }
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}

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

int main() {
  int N, C, M = 1e5;
  cin >> N >> C;
  vector<vector<int>> V(C, vector<int>(M));
  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    s--, c--;
    V.at(c).at(s)++;
    if (t < M)
      V.at(c).at(t)--;
  }
  for (int i = 0; i < C; i++) {
    for (int j = 1; j < M; j++) {
      V.at(i).at(j) += V.at(i).at(j - 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < C; j++) {
      if (V.at(j).at(i) == 2)
        V.at(j).at(i) = 1;
      sum += V.at(j).at(i);
    }
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):

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

const int MAX_C = 5;
const int MAX_T = (int)91;
// const int MAX_C = 31;
// const int MAX_T = (int) 1e5 + 1;

int pgm[MAX_C][MAX_T];

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

  int N, C;
  cin >> N >> C;

  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    for (int i = s; i <= t; ++i) {
      pgm[c][i] = 1;
    }
  }

  int max_count = 0;
  for (int i = 1; i < MAX_T; ++i) {
    int count = 0;
    for (int j = 1; j <= C; ++j) {
      count += pgm[j][i];
    }
    max_count = max(max_count, count);
  }

  cout << max_count << '\n';

  return 0;
}


Fixed submission:

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

const int MAX_C = 31;
const int MAX_T = (int)1e5 + 1;

int pgm[MAX_C][MAX_T];

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

  int N, C;
  cin >> N >> C;

  while (N--) {
    int s, t, c;
    cin >> s >> t >> c;
    for (int i = s; i <= t; ++i) {
      pgm[c][i] = 1;
    }
  }

  int max_count = 0;
  for (int i = 1; i < MAX_T; ++i) {
    int count = 0;
    for (int j = 1; j <= C; ++j) {
      count += pgm[j][i];
    }
    max_count = max(max_count, count);
  }

  cout << max_count << '\n';

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, c;
  cin >> n >> c;
  int x = 100;
  vector<vector<int>> ns(c, vector<int>(x, 0));
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    ns[c - 1][s]++;
    ns[c - 1][t]--;
  }

  for (auto &arr : ns)
    for (int i = x - 1; i > 0; i--)
      if (arr[i - 1] < 0) {
        arr[i] += arr[i - 1];
        arr[i - 1] = 0;
      }

  for (auto &arr : ns) {
    int s = 0;
    for (int i = 0; i < x; i++) {
      s += arr[i];
      arr[i] = s;
    }
  }

  vector<int> ms(x, 0);
  for (int i = x - 1; i > 0; i--)
    for (auto &arr : ns)
      ms[i] += arr[i];

  /*
  for (auto &arr: ns) {
      for (int i=0; i<x; i++)
          cout << arr[i] << " ";
      cout << endl;
  }

  for (int i=0; i<x; i++)
      cout << ms[i] << " ";
  cout << endl;
  */
  cout << *max_element(ms.begin(), ms.end()) << endl;
}

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

int main() {
  int n, c;
  cin >> n >> c;
  int x = 100100;
  vector<vector<int>> ns(c, vector<int>(x, 0));
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    ns[c - 1][s]++;
    ns[c - 1][t]--;
  }

  for (auto &arr : ns)
    for (int i = x - 1; i > 0; i--)
      if (arr[i - 1] < 0) {
        arr[i] += arr[i - 1];
        arr[i - 1] = 0;
      }

  for (auto &arr : ns) {
    int s = 0;
    for (int i = 0; i < x; i++) {
      s += arr[i];
      arr[i] = s;
    }
  }

  vector<int> ms(x, 0);
  for (int i = x - 1; i > 0; i--)
    for (auto &arr : ns)
      ms[i] += arr[i];

  /*
  for (auto &arr: ns) {
      for (int i=0; i<x; i++)
          cout << arr[i] << " ";
      cout << endl;
  }

  for (int i=0; i<x; i++)
      cout << ms[i] << " ";
  cout << endl;
  */
  cout << *max_element(ms.begin(), ms.end()) << endl;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int im[30][100010] = {};
int main() {
  int n, C;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    im[c][s]++;
    im[c][t]--;
  }
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j < 100010; j++) {
      im[i][j] += im[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < 100010; i++) {
    int sum = 0;
    for (int j = 1; j <= C; j++) {
      sum += im[j][i];
      if (i && (im[j][i] == 0 && im[j][i - 1] == 1))
        sum++;
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int im[31][100010] = {};
int main() {
  int n, C;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    im[c][s]++;
    im[c][t]--;
  }
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j < 100010; j++) {
      im[i][j] += im[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < 100010; i++) {
    int sum = 0;
    for (int j = 1; j <= C; j++) {
      sum += im[j][i];
      if (i && (im[j][i] == 0 && im[j][i - 1] == 1))
        sum++;
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  vector<vector<P>> ch(c + 10), ch2(c + 10);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    x--;
    ch[x].push_back(P(s, t));
  }
  rep(i, c) {
    sort(begin(ch[i]), end(ch[i]));
    int st = ch[i][0].fi, en = ch[i][0].se;
    rep(j, ch[i].size()) {
      if (j + 1 < ch[i].size() && en == ch[i][j + 1].fi) {
        en = ch[i][j + 1].se;
        if (j == ch[i].size() - 1) {
          ch2[i].push_back(P(st, en));
        }
      } else {
        ch2[i].push_back(P(st, en));
        if (j + 1 < ch[i].size()) {
          st = ch[i][j + 1].fi;
          en = ch[i][j + 1].se;
        }
      }
    }
  }
  vector<int> sum(100110, 0);
  rep(i, c) {
    // cout<<i<<endl;
    rep(j, ch2[i].size()) {
      sum[ch2[i][j].fi - 1]++;
      sum[ch2[i][j].se]--;
      // cout<<ch2[i][j].fi<<' '<<ch2[i][j].se<<' ';
      // cout<<endl;
    }
  }
  FOR(i, 1, 100010) sum[i] += sum[i - 1];
  cout << *max_element(begin(sum), end(sum)) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, c;
  cin >> n >> c;
  vector<vector<P>> ch(c + 10), ch2(c + 10);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    x--;
    ch[x].push_back(P(s, t));
  }
  rep(i, c) {
    if (ch[i].empty())
      continue;
    sort(begin(ch[i]), end(ch[i]));
    int st = ch[i][0].fi, en = ch[i][0].se;
    rep(j, ch[i].size()) {
      if (j + 1 < ch[i].size() && en == ch[i][j + 1].fi) {
        en = ch[i][j + 1].se;
        if (j == ch[i].size() - 1) {
          ch2[i].push_back(P(st, en));
        }
      } else {
        ch2[i].push_back(P(st, en));
        if (j + 1 < ch[i].size()) {
          st = ch[i][j + 1].fi;
          en = ch[i][j + 1].se;
        }
      }
    }
  }
  vector<int> sum(100110, 0);
  rep(i, c) {
    // cout<<i<<endl;
    rep(j, ch2[i].size()) {
      sum[ch2[i][j].fi - 1]++;
      sum[ch2[i][j].se]--;
      // cout<<ch2[i][j].fi<<' '<<ch2[i][j].se<<' ';
      // cout<<endl;
    }
  }
  FOR(i, 1, 100010) sum[i] += sum[i - 1];
  cout << *max_element(begin(sum), end(sum)) << endl;
}
Problem p03504 (C++)

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

const int INF = 25000;
int main() {
  int N, C;
  cin >> N >> C;
  vector<int> s(N), t(N), c(N);
  for (int i = 0; i < N; ++i) {
    cin >> s[i] >> t[i] >> c[i];
    s[i] *= 2;
    t[i] *= 2;
  }

  vector<vector<int>> sum(C + 1, vector<int>(INF));
  for (int i = 0; i < N; ++i) {
    ++sum[c[i]][s[i] - 1];
    --sum[c[i]][t[i] + 1];
  }

  for (int i = 1; i <= C; ++i) {
    for (int j = 1; j < INF; ++j) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  int cnt = 0;
  for (int i = 0; i < INF; ++i) {
    int subcnt = 0;
    for (int j = 1; j <= C; ++j) {
      if (sum[j][i] > 0)
        ++subcnt;
    }
    cnt = max(cnt, subcnt);
  }
  cout << cnt << endl;
}


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

const int INF = 250000;
int main() {
  int N, C;
  cin >> N >> C;
  vector<int> s(N), t(N), c(N);
  for (int i = 0; i < N; ++i) {
    cin >> s[i] >> t[i] >> c[i];
    s[i] *= 2;
    t[i] *= 2;
  }

  vector<vector<int>> sum(C + 1, vector<int>(INF));
  for (int i = 0; i < N; ++i) {
    ++sum[c[i]][s[i] - 1];
    --sum[c[i]][t[i] + 1];
  }

  for (int i = 1; i <= C; ++i) {
    for (int j = 1; j < INF; ++j) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  int cnt = 0;
  for (int i = 0; i < INF; ++i) {
    int subcnt = 0;
    for (int j = 1; j <= C; ++j) {
      if (sum[j][i] > 0)
        ++subcnt;
    }
    cnt = max(cnt, subcnt);
  }
  cout << cnt << endl;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int r[30][100010];
int N, C;

int main() {
  cin >> N >> C;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    c--;
    r[c][a]++;
    r[c][b]--;
  }

  REP(c, C) REPS(i, 100001) { r[c][i] += r[c][i - 1]; }
  REP(c, C) REP(i, 100001) if (r[c][i]) r[c][i] = 1;

  int ans = 0;
  REP(i, 10e5 + 1) {
    int cur = 0;
    REP(c, C) cur += r[c][i];
    ans = max(ans, cur);
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int r[30][100010];
int N, C;

int main() {
  cin >> N >> C;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    c--;
    r[c][a]++;
    r[c][b]--;
  }

  REP(c, C) REPS(i, 100001) { r[c][i] += r[c][i - 1]; }
  REP(c, C) REP(i, 100001) if (r[c][i]) r[c][i] = 1;

  int ans = 0;
  REP(i, 100001) {
    int cur = 0;
    REP(c, C) cur += r[c][i];
    ans = max(ans, cur);
  }

  cout << ans << endl;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

constexpr int limit = 1e5;
constexpr int climit = 30;

int channel[climit][limit + 1];
int all[limit + 1];

int main() {
  int n, cs;
  cin >> n >> cs;
  int s[n + 1], t[n + 1], c[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> t[i] >> c[i];
    channel[c[i]][s[i]] += 1;
    channel[c[i]][t[i]] += -1;
  }

  for (int i = 1; i <= cs; i++) {
    for (int j = 1; j <= limit; j++) {
      channel[i][j] += channel[i][j - 1];
    }
  }

  for (int i = 1; i <= n; i++) {
    channel[c[i]][s[i] - 1] = 1;
  }

  int ans = 0;
  for (int i = 1; i <= cs; i++) {
    for (int j = 1; j <= limit; j++) {
      all[j] += channel[i][j];
      ans = max(all[j], ans);
    }
  }

  cout << ans << endl;

  return 0;
}

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

constexpr int limit = 1e5;
constexpr int climit = 30;

int channel[climit + 1][limit + 1];
int all[limit + 1];

int main() {
  int n, cs;
  cin >> n >> cs;
  int s[n + 1], t[n + 1], c[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> t[i] >> c[i];
    channel[c[i]][s[i]] += 1;
    channel[c[i]][t[i]] += -1;
  }

  for (int i = 1; i <= cs; i++) {
    for (int j = 1; j <= limit; j++) {
      channel[i][j] += channel[i][j - 1];
    }
  }

  for (int i = 1; i <= n; i++) {
    channel[c[i]][s[i] - 1] = 1;
  }

  int ans = 0;
  for (int i = 1; i <= cs; i++) {
    for (int j = 1; j <= limit; j++) {
      all[j] += channel[i][j];
      ans = max(all[j], ans);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}
#define t_max 100000 + 5
int v[30][t_max];

int main() {
  int N, C;
  cin >> N >> C;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    c--;
    v[c][a]++;
    v[c][b]--;
  }
  // 録画機は、あるチャンネルの時刻
  //  S から時刻 T までを録画するとき、時刻 S
  // − 0.5 から時刻 T までの間、他のチャンネルの録画に使うことができません。
  REP(i, N) {
    REP(j, 100004) { v[i][j + 1] += v[i][j]; }
  }
  // あとから録画開始時刻を1だけ早める（これで、同じチャンネルで連続して録画するときに重複をなくせる）。
  REP(i, C) {
    REP(j, t_max - 1) {
      if (v[i][j] == 0 && v[i][j + 1] == 1)
        v[i][j]++;
    }
  }
  int ans = 0;
  REP(j, t_max) {
    int cnt = 0;
    REP(i, C) {
      if (v[i][j])
        cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}
#define t_max 100000 + 5
int v[30][t_max];

int main() {
  int N, C;
  cin >> N >> C;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    c--;
    v[c][a]++;
    v[c][b]--;
  }
  // 録画機は、あるチャンネルの時刻
  //  S から時刻 T までを録画するとき、時刻 S
  // − 0.5 から時刻 T までの間、他のチャンネルの録画に使うことができません。
  REP(i, C) {
    REP(j, t_max - 1) { v[i][j + 1] += v[i][j]; }
  }
  // あとから録画開始時刻を1だけ早める（これで、同じチャンネルで連続して録画するときに重複をなくせる）。
  REP(i, C) {
    REP(j, t_max - 1) {
      if (v[i][j] == 0 && v[i][j + 1] == 1)
        v[i][j]++;
    }
  }
  int ans = 0;
  REP(j, t_max) {
    int cnt = 0;
    REP(i, C) {
      if (v[i][j])
        cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
Problem p03504 (C++)

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

int main() {
  int n, c, ans = 1;
  cin >> n >> c;
  vector<pair<int, int>> span[30];
  map<int, int> s, t;
  for (int i = 0; i < n; i++) {
    int s0, t0, c0;
    cin >> s0 >> t0 >> c0;
    span[c0 - 1].push_back(make_pair(s0, t0));
    s[s0]++;
    t[t0]++;
  }
  for (int i = 0; i < c; i++) {
    sort(span[i].begin(), span[i].end());
    for (int j = 0; j < span[i].size() - 1; j++) {
      if (span[i][j].second == span[i][j + 1].first) {
        s[span[i][j].second]--;
        t[span[i][j].second]--;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < 1e5 + 1; i++) {
    cnt += s[i];
    ans = max(ans, cnt);
    cnt -= t[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, c, ans = 1;
  cin >> n >> c;
  vector<pair<int, int>> span[30];
  map<int, int> s, t;
  for (int i = 0; i < n; i++) {
    int s0, t0, c0;
    cin >> s0 >> t0 >> c0;
    span[c0 - 1].push_back(make_pair(s0, t0));
    s[s0]++;
    t[t0]++;
  }
  for (int i = 0; i < c; i++) {
    if (!span[i].size())
      continue;
    sort(span[i].begin(), span[i].end());
    for (int j = 0; j < span[i].size() - 1; j++) {
      if (span[i][j].second == span[i][j + 1].first) {
        s[span[i][j].second]--;
        t[span[i][j].second]--;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i < 1e5 + 1; i++) {
    cnt += s[i];
    ans = max(ans, cnt);
    cnt -= t[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

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

ll sm[200020];

void solve() {
  ll n, c;
  cin >> n >> c;
  ll x[n], y[n], z[n], a[200020];
  for (ll i = 0; i < n; i++)
    cin >> x[i] >> y[i] >> z[i];
  ll cnt = 0;
  for (ll j = 1; j <= c; j++) {
    for (ll i = 0; i < 200020; i++)
      a[i] = 0;
    for (ll i = 0; i < n; i++)
      if (z[i] == j)
        a[2 * x[j] - 1]++, a[2 * y[j]]--;
    for (ll i = 1; i < 200020; i++)
      a[i] += a[i - 1];
    for (ll i = 0; i < 200020; i++)
      if (a[i] > 0)
        cnt = max(cnt, ++sm[i]);
  }
  cout << cnt << endl;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  // ll ti;   cin >> ti;  while(ti--)
  solve();
  return 0;
}


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

ll sm[200020];

void solve() {
  ll n, c;
  cin >> n >> c;
  ll x[n], y[n], z[n], a[200020];
  for (ll i = 0; i < n; i++)
    cin >> x[i] >> y[i] >> z[i];
  ll cnt = 0;
  for (ll j = 1; j <= c; j++) {
    for (ll i = 0; i < 200020; i++)
      a[i] = 0;
    for (ll i = 0; i < n; i++)
      if (z[i] == j)
        a[2 * x[i] - 1]++, a[2 * y[i]]--;
    for (ll i = 1; i < 200020; i++)
      a[i] += a[i - 1];
    for (ll i = 0; i < 200020; i++)
      if (a[i] > 0)
        cnt = max(cnt, ++sm[i]);
  }
  cout << cnt << endl;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  // ll ti;   cin >> ti;  while(ti--)
  solve();
  return 0;
}
Problem p03504 (C++)

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

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

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

int N, C;
int main() {
  ios::sync_with_stdio(false);
  const ll term = 40; // 2 * 100000 + 2;

  cin >> N >> C;
  vector<vector<ll>> table(C, vector<ll>(term, 0));
  REP(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    s *= 2;
    t *= 2;
    c--;
    table[c][s - 1] += 1;
    table[c][t] -= 1;
  }

  REP(c, C) {
    int isDup = 0;
    bool isInterval = false;
    REP(i, term) {
      if (isInterval) {
        if (table[c][i] == 1) {
          table[c][i] = 0;
          isDup++;
        } else if (table[c][i] == -1) {
          if (isDup == 0) {
            isInterval = false;
          } else {
            table[c][i] = 0;
            isDup--;
          }
        }
      } else {
        if (table[c][i] == 1)
          isInterval = true;
      }
    }
  }

  ll ans = 0;
  ll tmp = 0;

  REP(i, term) {
    REP(c, C) { tmp += table[c][i]; }
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

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

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

int N, C;
int main() {
  ios::sync_with_stdio(false);
  const ll term = 2 * 100000 + 2;

  cin >> N >> C;
  vector<vector<ll>> table(C, vector<ll>(term, 0));
  REP(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    s *= 2;
    t *= 2;
    c--;
    table[c][s - 1] += 1;
    table[c][t] -= 1;
  }

  REP(c, C) {
    int isDup = 0;
    bool isInterval = false;
    REP(i, term) {
      if (isInterval) {
        if (table[c][i] == 1) {
          table[c][i] = 0;
          isDup++;
        } else if (table[c][i] == -1) {
          if (isDup == 0) {
            isInterval = false;
          } else {
            table[c][i] = 0;
            isDup--;
          }
        }
      } else {
        if (table[c][i] == 1)
          isInterval = true;
      }
    }
  }

  ll ans = 0;
  ll tmp = 0;

  REP(i, term) {
    REP(c, C) { tmp += table[c][i]; }
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[30][100010];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  rep(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    sum[c][s]++;
    sum[c][t + 1]--;
  }
  rep(j, 30) rep(i, 100000) sum[j][i + 1] += sum[j][i];
  int ans = 0;
  rep(i, 100010) {
    int tmp = 0;
    rep(j, 30) tmp += min(1, sum[j][i]);
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[30][100010];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  rep(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    sum[c][s]++;
    sum[c][t + 1]--;
  }
  rep(j, 30) rep(i, 100000) sum[j][i + 1] += sum[j][i];
  int ans = 0;
  rep(i, 100010) {
    int tmp = 0;
    rep(j, 30) tmp += min(1, sum[j][i]);
    ans = max(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}
Problem p03504 (C++)

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

using namespace std;

int main(void) {
  int N, C;
  cin >> N >> C;
  vector<tuple<int, int, int>> program(N);
  for (int i = 0; i < N; i++) {
    cin >> get<0>(program[i]) >> get<1>(program[i]) >> get<2>(program[i]);
  }

  sort(program.begin(), program.end(), [](auto &lhs, auto &rhs) {
    return (get<2>(lhs) == get<2>(rhs)) ? get<1>(lhs) < get<1>(rhs)
                                        : get<2>(lhs) < get<2>(rhs);
  });
  for (int i = 1; i < N; i++) {
    if (get<2>(program[i]) == get<2>(program[i - 1]) &&
        get<1>(program[i - 1]) == get<0>(program[i])) {
      get<1>(program[i - 1]) = get<1>(program[i]);
      program.erase(program.begin() + i);
    }
  }

  vector<int> time(100010);
  for (auto e : program) {
    ++time[get<0>(e) - 1];
    --time[get<1>(e)];
  }
  partial_sum(time.begin(), time.end(), time.begin());

  cout << (*max_element(time.begin(), time.end())) << endl;
  return 0;
}


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

using namespace std;

int main(void) {
  int N, C;
  cin >> N >> C;
  vector<tuple<int, int, int>> program(N);
  for (int i = 0; i < N; i++) {
    cin >> get<0>(program[i]) >> get<1>(program[i]) >> get<2>(program[i]);
  }

  sort(program.begin(), program.end(), [](auto &lhs, auto &rhs) {
    return (get<2>(lhs) == get<2>(rhs)) ? get<1>(lhs) < get<1>(rhs)
                                        : get<2>(lhs) < get<2>(rhs);
  });
  for (int i = 1; i < N; i++) {
    if (get<2>(program[i]) == get<2>(program[i - 1]) &&
        get<1>(program[i - 1]) == get<0>(program[i])) {
      get<0>(program[i]) = get<0>(program[i - 1]);
      get<1>(program[i - 1]) = get<0>(program[i - 1]) - 1;
    }
  }

  vector<int> time(100010);
  for (auto e : program) {
    ++time[get<0>(e) - 1];
    --time[get<1>(e)];
  }
  partial_sum(time.begin(), time.end(), time.begin());

  cout << (*max_element(time.begin(), time.end())) << endl;
  return 0;
}
Problem p03504 (C++)

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

int n, m, ans;
int st[N], ed[N], c[N], pre[N], res[N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d%d", &st[i], &ed[i], &c[i]);

  for (int i = 1; i <= m; i++) {
    memset(pre, 0, sizeof(pre));
    for (int j = 1; j <= n; j++)
      if (c[j] == i)
        pre[st[i]]++, pre[ed[i] + 1]--;
    for (int j = 1; j <= 100000; i++)
      pre[j] += pre[j - 1];
    for (int j = 1; j <= 100000; j++)
      if (pre[j] > 0)
        res[j]++;
  }
  for (int i = 1; i <= 100000; i++)
    ans = max(ans, res[i]);
  printf("%d\n", ans);
  return 0;
}

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

int n, m, ans;
int st[N], ed[N], c[N], pre[N], res[N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d%d%d", &st[i], &ed[i], &c[i]);

  for (int i = 1; i <= m; i++) {
    memset(pre, 0, sizeof(pre));
    for (int j = 1; j <= n; j++)
      if (c[j] == i)
        pre[st[j]]++, pre[ed[j] + 1]--;
    for (int j = 1; j <= 100000; j++)
      pre[j] += pre[j - 1];
    for (int j = 1; j <= 100000; j++)
      if (pre[j] > 0)
        res[j]++;
  }
  for (int i = 1; i <= 100000; i++)
    ans = max(ans, res[i]);
  printf("%d\n", ans);
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<int>> imos(30, vector<int>(100001));
  rep(i, 30) rep(j, 100001) imos[i][j] = 0;
  rep(i, n) {
    int d, e, f;
    cin >> d >> e >> f;
    d--, f--;
    imos[i][d]++, imos[i][e]--;
  }

  rep(i, c) _rep(j, 1, 100001) imos[i][j] += imos[i][j - 1];
  rep(i, c) rep(j, 100001) {
    if (imos[i][j] > 0)
      imos[i][j] = 1;
  }

  int ans = 0;
  rep(i, 100001) {
    int count = 0;
    rep(j, c) { count += imos[j][i]; }
    ans = max(count, ans);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<int>> imos(30, vector<int>(100001));
  rep(i, 30) rep(j, 100001) imos[i][j] = 0;
  rep(i, n) {
    int d, e, f;
    cin >> d >> e >> f;
    d--, f--;
    imos[f][d]++, imos[f][e]--;
  }

  rep(i, c) _rep(j, 1, 100001) imos[i][j] += imos[i][j - 1];
  rep(i, c) rep(j, 100001) {
    if (imos[i][j] > 0)
      imos[i][j] = 1;
  }

  int ans = 0;
  rep(i, 100001) {
    int count = 0;
    rep(j, c) { count += imos[j][i]; }
    ans = max(count, ans);
  }
  cout << ans << endl;
}