Facebook
From notMITstudent, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 129
  1.   ifstream cin("lifeguards.in");
  2.   ofstream cout("lifeguards.out");
  3.   int t; cin >> t;
  4.   pair <int, int> time[t];
  5.  
  6.   int max = 0;
  7.  
  8.   for (int i = 0; i < t; ++i)
  9.   {
  10.     cin >> time[i].first >> time[i].second;
  11.   }
  12.  
  13.   for (int i = 0; i < t; ++i)
  14.   {
  15.     int arr[1001] = {0};
  16.  
  17.     for (int j = 0; j < t; ++j)
  18.     {
  19.       if (i != j){
  20.         for (int k = time[j].first; k <= time[j].second; ++k)
  21.         {
  22.           arr[k]++;
  23.         }      
  24.       }
  25.     }
  26.     int ans = 0;
  27.     for (int o = 0; o < 1001; ++o)
  28.       {
  29.         if (arr[o] > 0) {
  30.           ans ++;
  31.           if (ans > max) max = ans;
  32.         }
  33.         else ans = 0;
  34.     }
  35.   }
  36.  
  37.  
  38.   cout << max;