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

#include <iostream>
#define mp make_pair
#include <cstdio>
#define MAX 86400
#include <algorithm>
#include <cstdlib>
#include <map>
#include <string>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, l, a;
  char s[20];
  P table[20000];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> s;
      l = atoi(s) * 3600 + atoi(&s[3]) * 60 + atoi(&s[6]);
      table[i] = P(l, 1);
      cin >> s;
      a = atoi(s) * 3600 + atoi(&s[3]) * 60 + atoi(&s[6]);
      table[i + n] = P(a, 0);
    }
    int now = 0, ans = 0;
    sort(table, table + 2 * n);
    for (int i = 0; i < 2 * n; i++) {
      if (table[i].second)
        now++;
      else
        now--;
      ans = max(now, ans);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, ma, sum;
  string s, t;
  vector<P> box;
  while (cin >> n, n) {
    ma = 0;
    for (int i = 0; i < n; i++) {
      cin >> s >> t;
      box.push_back(P(((s[0] - '0') * 10 + s[1] - '0') * 3600 +
                          ((s[3] - '0') * 10 + s[4] - '0') * 60 +
                          (s[6] - '0') * 10 + s[7] - '0',
                      ((t[0] - '0') * 10 + t[1] - '0') * 3600 +
                          ((t[3] - '0') * 10 + t[4] - '0') * 60 +
                          (t[6] - '0') * 10 + t[7] - '0'));
    }
    for (int i = 0; i < 24 * 60 * 60; i++) {
      sum = 0;
      for (int j = 0; j < n; j++) {
        if (box[j].first <= i && box[j].second > i)
          sum++;
      }
      if (sum > ma)
        ma = sum;
    }
    cout << ma << endl;
    box.clear();
  }
  return 0;
}
Problem p01138 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define INF 1 << 28
using namespace std;

typedef pair<int, int> P;

int main() {
  int n;
  while (cin >> n, n) {
    string str1, str2;
    vector<P> time;
    while (n--) {
      cin >> str1 >> str2;
      for (int i = 0; i < str1.size(); i++) {
        if (str1[i] == ':') {
          str1[i] = str2[i] = ' ';
        }
      }

      stringstream ss1, ss2;
      ss1 << str1;
      ss2 << str2;

      int t1, t2, t3;
      ss1 >> t1 >> t2 >> t3;
      int s = t1 * 60 * 60 + t2 * 60 + t3;
      ss2 >> t1 >> t2 >> t3;
      int e = t1 * 60 * 60 + t2 * 60 + t3;

      time.push_back(P(s, 1));
      time.push_back(P(e, -1));
    }

    sort(time.begin(), time.end());

    int res = 0, MAX = 0;
    for (int i = 0; i < time.size(); i++) {
      res += time[i].second;
      MAX = max(MAX, res);
    }

    cout << MAX << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define INF 1 << 28
using namespace std;

typedef pair<int, int> P;

int main() {
  int n;
  while (cin >> n, n) {
    string str1, str2;
    vector<P> time;
    while (n--) {
      cin >> str1 >> str2;
      for (int i = 0; i < str1.size(); i++) {
        if (str1[i] == ' ') {
          str1[i] = str2[i] = ' ';
        }
      }

      stringstream ss1, ss2;
      ss1 << str1;
      ss2 << str2;

      int t1, t2, t3;
      ss1 >> t1 >> t2 >> t3;
      int s = t1 * 60 * 60 + t2 * 60 + t3;
      ss2 >> t1 >> t2 >> t3;
      int e = t1 * 60 * 60 + t2 * 60 + t3;

      time.push_back(P(s, e));
    }

    time.push_back(P(INF, INF));
    vector<int> st, et;
    for (int i = 0; i < time.size(); i++) {
      st.push_back(time[i].first);
      et.push_back(time[i].second);
    }

    int k = 0, l = 0;
    int tmp = 0, MAX = 0;
    while (st[k] != INF || et[l] != INF) {
      if (st[k] < et[l]) {
        tmp++;
        k++;
      } else if (k > 0 && (st[k - 1] + 60 * 60) <= et[l]) {
        tmp--;
        l++;
      } else {
        MAX = MAX < tmp + 1 ? tmp + 1 : MAX;
      }
      MAX = MAX < tmp ? tmp : MAX;
    }

    cout << MAX << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
int N;
string In[10000], Out[10000];
int main() {
  while (cin >> N && N > 0) {
    for (int i = 0; i < N; ++i) {
      cin >> Out[i] >> In[i];
      //    for (int i=0; i<N; ++i)
      //      cout << Out[i] << ' ' << In[i] << endl;
    }
    sort(In, In + N);
    sort(Out, Out + N);
    int p = 0, taiki = 0, train = 0;
    for (int i = 0; i < N; ++i) {
      while (p < N && In[p] <= Out[i]) {
        taiki++;
        p = p + 1;
      }
      if (taiki > 0)
        taiki = taiki - 1;
      else
        train = train + 1;
    }
    cout << train << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
int N;
string In[10000], Out[10000];
int main() {
  while (cin >> N && N > 0) {
    for (int i = 0; i < N; ++i) {
      cin >> Out[i] >> In[i];
      sort(In, In + N);
      sort(Out, Out + N);
      //    for (int i=0; i<N; ++i)
      //      cout << Out[i] << ' ' << In[i] << endl;
    }

    int p = 0, taiki = 0, train = 0;
    for (int i = 0; i < N; ++i) {
      while (p < N && In[p] <= Out[i]) {
        taiki++;
        p = p + 1;
      }
      if (taiki > 0)
        taiki = taiki - 1;
      else
        train = train + 1;
    }
    cout << train << endl;
  }
}
Problem p01138 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define secondMAX (23 * 60 * 60 + 59 * 60 + 59)
using namespace std;

int main() {

  int n;
  int h, m, s;
  char gav;
  int table[secondMAX + 1];
  int max;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i <= secondMAX; i++)
      table[i] = 0;
    for (int i = 0; i < n; i++) {
      cin >> h >> gav >> m >> gav >> s;
      table[h * 60 * 60 + m * 60 + s] += 1;
      cin >> h >> gav >> m >> gav >> s;
      table[h * 60 * 60 + m * 60 + s] -= 1;
    }
    for (int i = 1; i <= secondMAX; i++)
      table[i] += table[i - 1];
    max = 0;
    for (int i = 0; i <= secondMAX; i++) {
      if (max < table[i])
        max = table[i];
    }

    cout << max << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define secondMAX (23 * 60 * 59 + 60 * 60 + 59)
using namespace std;

int main() {

  int n;
  int h, m, s;
  char gav;
  int table[secondMAX + 1];
  int max;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i <= secondMAX; i++)
      table[i] = 0;
    for (int i = 0; i < n; i++) {
      cin >> h >> gav >> m >> gav >> s;
      table[h * 60 * 60 + m * 60 + s] += 1;
      cin >> h >> gav >> m >> gav >> s;
      table[h * 60 * 60 + m * 60 + s] -= 1;
    }
    for (int i = 1; i <= secondMAX; i++)
      table[i] += table[i - 1];
    max = 0;
    for (int i = 0; i <= secondMAX; i++) {
      if (max < table[i])
        max = table[i];
    }

    cout << max << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

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

int n;
int imos[86400];

void solve() {
  rep(i, n) {
    int s[3];
    int t[3];
    scanf("%d:%d:%d", &s[0], &s[1], &s[2]);
    scanf("%d:%d:%d", &t[0], &t[1], &t[2]);

    // hh:mm:ss を 秒に変換
    int S = s[2] + 60 * (s[1] + s[0] * 60);
    int T = t[2] + 60 * (t[1] + t[0] * 60);

    // 入る時間に +1
    imos[S]++;

    // 出る時間に -1
    imos[T]--;

    // ナイーブな実装 (写経しなくて良い)
    // for(int j = S; j <= T; j++) imos[j]++;
  }

  // 累積和を計算する
  rep(i, 86400) if (i) imos[i] += imos[i - 1];

  int ans = 0;
  rep(i, 86400) ans = max(ans, imos[i]);

  cout << ans << endl;
}

int main() {
  // こう書くとn==0のときにwhileループが停止する
  while (cin >> n, n) {
    rep(i, 86400) imos[i] = 0;
    solve();
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

int n;
int imos[86400];

void solve() {
  rep(i, n) {
    int s[3];
    int t[3];
    scanf("%d:%d:%d", &s[0], &s[1], &s[2]);
    scanf("%d:%d:%d", &t[0], &t[1], &t[2]);

    // hh:mm:ss を 秒に変換
    int S = s[2] + 60 * (s[1] + s[0] * 60);
    int T = t[2] + 60 * (t[1] + t[0] * 60);

    // 入る時間に +1
    imos[S]++;

    // 出る時間+1に -1
    imos[T + 1]--;

    // ナイーブな実装 (写経しなくて良い)
    // for(int j = S; j <= T; j++) imos[j]++;
  }

  // 累積和を計算する
  rep(i, 86400) if (i) imos[i] += imos[i - 1];

  int ans = 0;
  rep(i, 86400) ans = max(ans, imos[i]);

  cout << ans << endl;
}

int main() {
  // こう書くとn==0のときにwhileループが停止する
  while (cin >> n, n) {
    rep(i, 86400) imos[i] = 0;
    solve();
  }
}
Problem p01138 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    vector<int> v(86400);
    for (int i = 0; i < n; ++i) {
      int h[2], m[2], s[2];
      scanf("%d:%d:%d", &h[0], &m[0], &s[0]);
      scanf("%d:%d:%d", &h[1], &m[1], &s[1]);
      int bg = h[0] * 3600 + m[0] * 60 + s[0];
      int ed = h[1] * 3600 + m[1] * 60 + s[1];
      ++v[bg];
      --v[ed];
    }
    for (int i = 1; i < 86400; ++i) {
      v[i] += v[i - 1];
    }
    cout << *max_element(begin(v), end(v)) << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  while (cin >> N, N) {
    int range[24 * 60 * 60 + 1];
    fill(range, range + 24 * 60 * 60 + 1, 0);
    for (int i = 0; i < N; ++i) {
      int h[2], m[2], s[2];
      scanf("%2d:%2d:%2d", &h[0], &m[0], &s[0]);
      scanf("%2d:%2d:%2d", &h[1], &m[1], &s[1]);
      int st = h[0] * 60 * 60 + m[0] * 60 + s[0],
          et = h[1] * 60 * 60 + m[1] * 60 + s[1];
      ++range[st], --range[et];
    }
    int ans = 0, acc = 0;
    for (int i = 0; i < 24 * 60 * 60; ++i) {
      acc += range[i];
      ans = max(ans, acc);
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N 100000
int x[MAX_N];

int main() {
  int n, a, b, c, d, e, maxn = 0;
  ;
  while (true) {
    for (int i = 0; i < MAX_N; i++) {
      x[i] = 0;
    }
    cin >> n;
    maxn = 0;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      scanf("%02d:%02d:%02d", &a, &b, &c);
      d = a * 3600 + b * 60 + c;
      scanf("%02d:%02d:%02d", &a, &b, &c);
      e = a * 3600 + b * 60 + c;
      x[d]++;
      x[e]--;
    }
    for (int i = 1; i < 99999; i++) {
      x[i] += x[i - 1];
      maxn = max(maxn, x[i]);
    }
    cout << maxn << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N 100000
int x[MAX_N];

int main() {
  int n, a, b, c, d, e, maxn = 0;
  ;
  while (true) {
    for (int i = 0; i < MAX_N; i++) {
      x[i] = 0;
    }
    cin >> n;
    maxn = 0;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      scanf("%02d:%02d:%02d", a, b, c);
      d = a * 3600 + b * 60 + c;
      scanf("%02d:%02d:%02d", a, b, c);
      e = a * 3600 + b * 60 + c;
      x[d]++;
      x[e]--;
    }
    for (int i = 1; i < 99999; i++) {
      x[i] += x[i - 1];
      maxn = max(maxn, x[i]);
    }
    cout << maxn << endl;
  }
}
Problem p01138 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

struct E {
  int time, c;
  E(int time, int c) : time(time), c(c) {}
  bool operator<(const E &e) const {
    if (time == e.time) {
      return c < e.c;
    }
    return time < e.time;
  }
};

int N;
vector<E> es;
bool input() {
  es.clear();
  scanf("%d\\n", &N);
  if (N == 0)
    return false;
  for (int i = 0; i < N; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int from = h * 3600 + m * 60 + s;
    es.push_back(E(from, +1));
    scanf(" %d:%d:%d\\n", &h, &m, &s);
    int to = h * 3600 + m * 60 + s;
    es.push_back(E(to, -1));
  }
  return true;
}

void solve() {
  sort(es.begin(), es.end());
  int ans = 0;
  int pool = 0;
  for (int i = 0; i < es.size(); i++) {
    const E &e = es[i];
    if (e.c == 1) {
      if (pool > 0)
        pool--;
      else
        ans++;
    } else {
      pool++;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  while (input())
    solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

struct E {
  int time, c;
  E(int time, int c) : time(time), c(c) {}
  bool operator<(const E &e) const { return time < e.time; }
};

int N;
vector<E> es;
bool input() {
  es.clear();
  scanf("%d\\n", &N);
  for (int i = 0; i < N; i++) {
    int h, m, s;
    scanf("%d:%d:%d", &h, &m, &s);
    int from = h * 3600 + m * 60 + s;
    es.push_back(E(from, +1));
    scanf(" %d:%d:%d\\n", &h, &m, &s);
    int to = h * 3600 + m * 60 + s;
    es.push_back(E(to, -1));
  }
  return true;
}

void solve() {
  sort(es.begin(), es.end());
  int ans = 0;
  int pool = 0;
  for (int i = 0; i < es.size(); i++) {
    const E &e = es[i];
    if (e.c == 1) {
      if (pool > 0)
        pool--;
      else
        ans++;
    } else {
      pool++;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  while (input())
    solve();
  return 0;
}
Problem p01138 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
int N;
P G[20000];
int solve() {
  int res = 0;
  int c = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (G[i].second) {
      c++;
      res = max(c, res);
    } else {
      c--;
    }
  }
  return res;
}
int main() {
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        char str[10];
        cin >> str;
        int a = (str[0] - '0') * 10 + str[1] - '0';
        int b = (str[3] - '0') * 10 + str[4] - '0';
        int c = (str[6] - '0') * 10 + str[7] - '0';
        G[i * 2 + j] = P(a * 60 * 60 + b * 60 + c, 1 - j);
      }
    }
    sort(G, G + 2 * N);
    cout << solve() << endl;
  }
}

Error: 0

Fixed submission:


#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
int N;
P G[10000];
int solve() {
  int res = 0;
  int c = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (G[i].second) {
      c++;
      res = max(c, res);
    } else {
      c--;
    }
  }
  return res;
}
int main() {
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        char str[10];
        cin >> str;
        int a = (str[0] - '0') * 10 + str[1] - '0';
        int b = (str[3] - '0') * 10 + str[4] - '0';
        int c = (str[6] - '0') * 10 + str[7] - '0';
        G[i * 2 + j] = P(a * 60 * 60 + b * 60 + c, 1 - j);
      }
    }
    sort(G, G + 2 * N);
    cout << solve() << endl;
  }
}
Problem p01138 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int main() {
  int n;

  while (cin >> n, n) {
    vector<P> v;
    int sh, sm, ss, th, tm, ts, Max = 0, Min = 99999, totals, totalt;
    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d", &sh, &sm, &ss);
      totals = sh * 3600 + sm * 60 + ss;
      v.push_back(P(totals, 1));
      scanf("%d:%d:%d", &th, &tm, &ts);
      totalt = th * 3600 + tm * 60 + ts;
      v.push_back(P(totalt, -1));
    }
    sort(v.begin(), v.end());

    int ans = 0, tmp = 0;
    for (int i = 0; i < v.size(); i++) {
      tmp += v[i].second;
      ans = max(ans, tmp);
    }
    cout << ans << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int main() {
  int n;

  while (cin >> n, n) {
    vector<P> v;
    int sh, sm, ss, th, tm, ts, Max = 0, Min = 100000, totals, totalt;
    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d", &sh, &sm, &ss);
      totals = sh * 3600 + sm * 60 + ss;
      Min = min(Min, totals);
      v.push_back(P(totals, 1));
      scanf("%d:%d:%d", &th, &tm, &ts);
      totalt = th * 3600 + tm * 60 + ts;
      v.push_back(P(totalt, -1));
      Max = max(Max, totalt);
    }
    sort(v.begin(), v.end());

    int ans = 0, tmp = 0;
    for (int i = Min; i <= Max; i++) {
      if (v[i].first) {
        tmp += v[i].second;
        ans = max(ans, tmp);
      }
    }
    cout << ans + 1 << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, h, m, s;
  while (scanf("%d", &n), n) {
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d", &h, &m, &s);
      v.push_back(make_pair(h * 3600 + m * 60 + s, 1));

      scanf("%d:%d:%d", &h, &m, &s);
      v.push_back(make_pair(h * 3600 + m * 60 + s, 0));
    }

    sort(v.begin(), v.end());

    int cnt = 0, ans = 0;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second == 1)
        cnt++;
      else
        cnt--;
      ans = max(ans, cnt);
    }

    printf("%d\\n", ans);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int t, train, max;
  int n;
  int dep[10000], arr[10000];
  int h, m, s;

  while (1) {
    cin >> n;
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      scanf("%d:%d:%d ", &h, &m, &s);
      dep[i] = h * 24 * 60 + m * 60 + s;
      scanf("%d:%d:%d ", &h, &m, &s);
      arr[i] = h * 24 * 60 + m * 60 + s;
    }

    train = 0;
    max = 0;
    for (t = 0; t <= 86400; t++) {
      for (int i = 0; i < n; i++) {
        if (dep[i] == t)
          train++;
        if (arr[i] == t)
          train--;
      }
      if (train > max)
        max = train;
    }

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

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const int MAX_N = 10000;

pair<int, int> p[MAX_N + 1];

int main() {
  _;
  int n, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
  while (scanf("%d", &n), n != 0) {
    REP(i, n) {
      scanf("%02d:%02d:%02d %02d:%02d:%02d", &a, &b, &c, &d, &e, &f);
      p[i] = make_pair(a * 3600 + b * 60 + c, d * 3600 + e * 60 + f);
    }
    priority_queue<int, vector<int>, greater<int>> que;
    int maxTrain = 0;
    sort(p, p + n);
    REP(i, n) {
      while (!que.empty() && que.top() <= p[i].first)
        que.pop();
      que.push(p[i].second);
      maxTrain = max(maxTrain, (int)que.size());
    }
    cout << maxTrain << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const int MAX_N = 1000;

pair<int, int> p[MAX_N + 1];

int main() {
  _;
  int n, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
  while (scanf("%d", &n), n != 0) {
    REP(i, n) {
      scanf("%02d:%02d:%02d %02d:%02d:%02d", &a, &b, &c, &d, &e, &f);
      p[i] = make_pair(a * 3600 + b * 60 + c, d * 3600 + e * 60 + f);
    }
    priority_queue<int, vector<int>, greater<int>> que;
    int maxTrain = 0;
    sort(p, p + n);
    REP(i, n) {
      while (!que.empty() && que.top() <= p[i].first)
        que.pop();
      que.push(p[i].second);
      maxTrain = max(maxTrain, (int)que.size());
    }
    cout << maxTrain << endl;
  }
}
Problem p01138 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n != 0) {
    int i, j, k;
    string str;
    int mp[86401] = {};
    for (i = 0; i < n; i++) {
      int st = 0, et = 0;
      cin >> str;
      st = ((str[0] - '0') * 10 + str[1] - '0') * 60 * 60 +
           ((str[3] - '0') * 10 + str[4] - '0') * 60 +
           ((str[6] - '0') * 10 + str[7] - '0');
      cin >> str;
      et = ((str[0] - '0') * 10 + str[1] - '0') * 60 * 60 +
           ((str[3] - '0') * 10 + str[4] - '0') * 60 +
           ((str[6] - '0') * 10 + str[7] - '0');
      for (j = st; j < et; j++)
        mp[j]++;
    }
    int m = 0, b;
    for (i = 0; i < 86401; i++)
      if (m < mp[i])
        m = mp[i];
    cout << m << endl;
    cin >> n;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> se;
typedef vector<se> tt;
int main() {
  int n;
  cin >> n;
  while (n != 0) {
    int i, j, k;
    string str;
    tt t;
    for (i = 0; i < n; i++) {
      int st = 0, et = 0;
      cin >> str;
      st += ((str[0] - '0') * 10 + str[1] - '0') * 24 * 60 +
            ((str[3] - '0') * 10 + str[4] - '0') * 60 +
            ((str[6] - '0') * 10 + str[7] - '0');
      cin >> str;
      et += ((str[0] - '0') * 10 + str[1] - '0') * 24 * 60 +
            ((str[3] - '0') * 10 + str[4] - '0') * 60 +
            ((str[6] - '0') * 10 + str[7] - '0');
      t.push_back(make_pair(st, et));
    }
    sort(t.begin(), t.end());
    int m = 0, b;
    for (j = 0; j < 86401; j++) {
      b = 0;
      for (k = 0; k < t.size(); k++) {
        if (t[k].first <= j && j < t[k].second)
          b++;
      }
      if (m < b)
        m = b;
    }
    cout << m << endl;
    cin >> n;
  }
  return 0;
}
Problem p01138 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define M 1e7
using namespace std;
int main() {
  int n, i, j, b[6];
  while (cin >> n, n) {
    int a[86400] = {0}, ans = 0, c = 0;
    while (n--) {
      scanf("%d:%d:%d %d:%d:%d", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]);
      a[b[0] * 3600 + b[1] * 60 + b[2]]++;
      a[b[3] * 3600 + b[4] * 60 + b[5]]--;
    }
    for (i = 0; i < 86400; i++) {
      c += a[i];
      ans = max(ans, c);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define M 1e7
using namespace std;
int main() {
  int n, i, j, b[6];
  while (cin >> n && n) {
    j = n;
    int a[10000], ans = 0, c = 0;
    while (--n) {
      scanf("%d:%d:%d %d:%d:%d", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]);
      a[n * 2 - 1] = b[0] * 3600 + b[1] * 60 + b[2] + M;
      a[n * 2 - 2] = b[3] * 3600 + b[4] * 60 + b[5];
    }
    sort(a, a + j * 2);
    for (i = 0; i < j * 2; j++) {
      if (a[i] > 1e7)
        c++;
      else
        c--;
      ans = max(ans, c);
    }
    cout << ans << endl;
  }
}