Problem p00592 (C++) — buggy submission, verdict: Runtime Error

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

struct interval {
  interval() {
    b = 0;
    e = 0;
  }
  interval(int x, int y) {
    b = x;
    e = y;
  }
  int b;
  int e;
  bool operator==(const interval &x) const { return (b == x.b) && (e == x.e); }
  bool operator!=(const interval &x) const { return (b != x.b) || (e != x.e); }
  bool operator<(const interval &x) const {
    return (b < x.b) || (b == x.b) && (e < x.e);
  }
  bool operator>(const interval &x) const {
    return (b > x.b) || (b == x.b) && (e > x.e);
  }
};

int main() {
  int n, start, stop;

  while (cin >> n >> start >> stop) {
    if (n == 0)
      return 0;

    int st = (start / 100) * 60 + (start % 100);
    int et = (stop / 100) * 60 + (stop % 100);

    stop = et - st; // ????????????

    vector<interval> slots;
    for (int i = 0; i < n; i++) {
      // ?¬¬i?????£????????????CM??????
      int k;
      cin >> k;

      interval t;
      int s = 0;
      int b, e;

      cin >> b >> e;

      int bt = (b / 100) * 60 + (b % 100) - st;
      int et = (e / 100) * 60 + (e % 100) - st;

      if (s != bt) {
        t.b = s;
        t.e = bt;
        slots.push_back(t);
      }

      s = et;

      for (int j = 1; j < k; j++) {
        cin >> b >> e;

        bt = (b / 100) * 60 + (b % 100) - st;
        et = (e / 100) * 60 + (e % 100) - st;

        if (s != bt) {
          t.b = s;
          t.e = bt;
          slots.push_back(t);
        }

        s = et;
      }

      if (s < stop) {
        t.b = s;
        t.e = stop;
        slots.push_back(t);
      }
    } // i?????£???????????????????????????

    sort(slots.begin(), slots.end());
    //========================================
    // cout << n << " channel(s) stop = " << stop << endl;
    // for (int p=0;p<slots.size();p++)
    // {
    //   cout << "(" << slots[p].b << "," << slots[p].e << ") ";
    // }
    // cout << endl;
    //========================================

    // slot?????????CM??\\??????????????????????????\\??£?????????
    int s = 0;
    int k = 0; // ?????????index
    int maxlen = 0;
    int len = 0;
    while (k < slots.size()) {
      if ((s >= slots[k].b) && (s <= slots[k].e)) {
        // ?§???????
        len += slots[k].e - s;
        s = slots[k].e;
        k++;
        if (maxlen < len)
          maxlen = len;
      } else if ((s > slots[k].b) && (s > slots[k].e)) {
        k++;
      } else if (s < slots[k].b) {
        // ?§?????????¨???????????????
        if (maxlen < len)
          maxlen = len;
        len = 0;
        s = slots[k].b;
      }
    } // ??¢?´¢??????
    cout << maxlen << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

struct interval {
  interval() {
    b = 0;
    e = 0;
  }
  interval(int x, int y) {
    b = x;
    e = y;
  }
  int b;
  int e;
  bool operator==(const interval &x) const { return (b == x.b) && (e == x.e); }
  bool operator!=(const interval &x) const { return (b != x.b) || (e != x.e); }
  bool operator<(const interval &x) const {
    return (b < x.b) || (b == x.b) && (e < x.e);
  }
  bool operator>(const interval &x) const {
    return (b > x.b) || (b == x.b) && (e > x.e);
  }
};

int main() {
  int n, start, stop;

  while (cin >> n >> start >> stop) {
    if (n == 0)
      return 0;

    int st = (start / 100) * 60 + (start % 100);
    int et = (stop / 100) * 60 + (stop % 100);

    int stop = et - st; // ????????????

    vector<interval> slots;
    for (int i = 0; i < n; i++) {
      // ?¬¬i?????£????????????CM??????
      int k;
      cin >> k;

      interval t;
      int s = 0;
      int b, e;

      cin >> b >> e;
      int bt = (b / 100) * 60 + (b % 100) - st;
      int et = (e / 100) * 60 + (e % 100) - st;
      if (s != bt) {
        t.b = s;
        t.e = bt;
        slots.push_back(t);
      }
      s = et;

      for (int j = 1; j < k; j++) {
        cin >> b >> e;
        bt = (b / 100) * 60 + (b % 100) - st;
        et = (e / 100) * 60 + (e % 100) - st;
        if (s != bt) {
          t.b = s;
          t.e = bt;
          slots.push_back(t);
        }
        s = et;
      }

      if (s < stop) {
        t.b = s;
        t.e = stop;
        slots.push_back(t);
      }
    } // i?????£???????????????????????????

    sort(slots.begin(), slots.end());
    //========================================
    // cout << n << " channel(s) stop = " << stop << endl;
    // for (int p=0;p<slots.size();p++)
    // {
    //   cout << "(" << slots[p].b << "," << slots[p].e << ") ";
    // }
    // cout << endl;
    //========================================

    // slot?????????CM??\\??????????????????????????\\??£?????????
    int s = 0;
    int k = 0; // ?????????index
    int maxlen = 0;
    int len = 0;
    while (s != stop) {
      if ((s >= slots[k].b) && (s <= slots[k].e)) {
        // ?§???????
        len += slots[k].e - s;
        s = slots[k].e;
        k++;
        if (maxlen < len)
          maxlen = len;
      } else if ((s > slots[k].b) && (s > slots[k].e)) {
        k++;
      } else if (s < slots[k].b) {
        // ?§?????????¨???????????????
        if (maxlen < len)
          maxlen = len;
        len = 0;
        s = slots[k].b;
      }
    } // ??¢?´¢??????
    cout << maxlen << endl;
  }

  return 0;
}