Problem p00592 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

//??\\?????\\??´?????£??????????????\\?°¨?????°??????map?????¨??????????????°???

int main() {
  int N;
  int start, end;
  while (cin >> N >> start >> end) {
    bool arr[2000] = {false};
    // map<int,int> mm;
    // map<int,int>::iterator iter;
    // map<int,int>::iterator iter2;
    if (N == 0 && start == 0 && end == 0)
      break;
    start = (start / 100) * 60 + (start % 100);
    end = (end / 100) * 60 + (end % 100);
    for (int i = 0; i < N; i++) {
      int kk;
      int temp;
      cin >> kk;
      int a, b;
      for (int j = 0; j < kk; j++) {
        cin >> a >> b;
        a = (a / 100) * 60 + (a % 100);
        b = (b / 100) * 60 + (b % 100);
        if (j == 0) {
          // if(a>start) mm[start]=a;
          if (a > start)
            for (int k = start; k < a; k++)
              arr[k] = true;
        } else {
          for (int k = temp; k < a; k++)
            arr[k] = true;
          // mm[temp]=a;
        }
        temp = b;
      }
      if (end > temp) {
        for (int k = temp; k < end; k++)
          arr[k] = true;
        // mm[temp]=end;
      }
    }
    /*
    for(iter2=mm.begin();iter2!=mm.end();++iter2)
    {
      cout<<iter2->first<<" "<<iter2->second<<endl;
    }
    */
    int max = 0;
    int duration = 0;
    for (int i = start; i < (end + 1); i++) {
      if (arr[i])
        duration++;
      else {
        if (duration > max)
          max = duration;
        duration = 0;
      }
      // cout<<duration<<endl;
    }
    cout << max << endl;
    /*
    iter=mm.begin();
    int start2=iter->first;
    int end2=iter->second;
    int max=end2-start2;
    iter++;
    for(;iter!=mm.end();++iter)
    {
      int p=iter->first;
      int q=iter->second;
      if(p<=end2&&q>=end2) end2=q;
      else if(p>end2)
      {
        start2=p;
        end2=q;
      }
      int dur=end2-start2;
      if(dur>max) max=dur;
    }
    cout<<max<<endl;
  }
  */
  }
  // while(1);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

//??\\?????\\??´?????£??????????????\\?°¨?????°??????map?????¨??????????????°???

int main() {
  int N;
  int start, end;
  while (cin >> N >> start >> end) {
    int arr[100 + 5][100 + 5];
    map<int, int> mm;
    map<int, int>::iterator iter;
    // map<int,int>::iterator iter2;
    if (N == 0 && start == 0 && end == 0)
      break;
    start = (start / 100) * 60 + (start % 60);
    end = (end / 100) * 60 + (end % 100);
    for (int i = 0; i < N; i++) {
      int kk;
      int temp;
      cin >> kk;
      int a, b;
      for (int j = 0; j < kk; j++) {
        cin >> a >> b;
        a = (a / 100) * 60 + (a % 100);
        b = (b / 100) * 60 + (b % 100);
        if (j == 0) {
          if (a > start)
            mm[start] = a;
        } else {
          mm[temp] = a;
        }
        temp = b;
      }
      if (end > temp)
        mm[temp] = end;
    }
    /*
    for(iter2=mm.begin();iter2!=mm.end();++iter2)
    {
      cout<<iter2->first<<" "<<iter2->second<<endl;
    }
    */
    iter = mm.begin();
    int start2 = iter->first;
    int end2 = iter->second;
    int max = end2 - start2;
    iter++;
    for (; iter != mm.end(); ++iter) {
      int p = iter->first;
      int q = iter->second;
      if (p <= end2 && q >= end2)
        end2 = q;
      else if (p > end2) {
        start2 = p;
        end2 = q;
      }
      int dur = end2 - start2;
      if (dur > max)
        max = dur;
    }
    cout << max << endl;
  }
  // while(1);
  return 0;
}