Answers for "Hotel Bookings Possible"

0

Hotel Bookings Possible

bool Solution::hotel(vector<int> &arrive, vector<int> &depart, int K) {
   vector<pair<int,int>>A;
   int size=arrive.size();
   for(int i=0;i<size;i++)
   {
       A.push_back(make_pair(arrive[i],2));
       A.push_back(make_pair(depart[i],1));
   }
   sort(A.begin(),A.end());
   int curroom=0;
   int roommax=0;
   for(int i=0;i<2*size;i++)
   {
       if(A[i].second==2)
       {
           curroom++;
           roommax=max(curroom,roommax);
       }
       else{
           curroom--;
       }
   }
   return K>=roommax;
}
Posted by: Guest on August-25-2020

Browse Popular Code Answers by Language