Technical lead of a development team has to send out a meeting invite to all his team members to discuss on a project they are working on.
There are N people in his team(including himself). He has the calendar of all the meeting participants, ie. he knows when each member
is busy. With this information, he has to schedule a meeting for T minutes, ie. find a slot of T minutes during which all participants
are free.
Input:
A single line of input. The first integer on the line represents T, the second interger represents N(N>=2). Then N pairs of strings
follows, each representing a period in time of a particular day during which that number is busy. The period will be of the format
“HHMM HHMM”. For example, if a pair reads, “0900 1500”, then the member is busy from 9AM to 3PM during the day, Note that the time is in
24-hour format. Note that the working hours of all participants are between 9AM and 9PM
Output:
Output the number of different slots(of T minutes) during which the meeting can be scheduled
Sample Output:
2
Explanation:
Here T=30 minute. There are 2 participants and the periods during which they are busy are as follows.
1st member -> 0900 2029 -> 9AM to 20:29PM
2nd member -> 0900 2029 -> 9AM to 20:29PM
The two available slots of 30 minutes are: 20:30 to 20:59 and 20:31 to 21:00
Code:
#include<iostream>
using namespace std;
int main(int argc,char **argv)
{
int n,i,j,k=0,T,v,m,slot=0;
cin>>T>>n;
int s[n],e[n],ts[n+2],te[n+2];
for(i=0;i<n;i++)
cin>>s[i]>>e[i];
for(i=0;i<n;i++)
{
v=s[i];
m=0;
for(j=i;j<n;j++)
{
if(s[i]==0)
break;
if(s[j]==v)
{
if(e[j]>m)
m=e[j];
if(j!=i)
s[j]=0;
}
}
if(s[i]!=0)
{
ts[k]=v;
te[k]=m;
k++;
}
}
if(ts[0]!=900)
{
for(i=k;i>0;i–)
{
ts[i]=ts[i-1];
te[i]=te[i-1];
}
ts[0]=te[0]=900;
k++;
}
ts[k]=2100;
te[k]=0;
k++;
for(i=0;i<k;i++)
for(j=i;j<k;j++)
if(ts[i]>ts[j])
{
int t=ts[i],t1=te[i];
ts[i]=ts[j];
te[i]=te[j];
ts[j]=t;
te[j]=t1;
}
for(i=0;i<k-1;i++)
{
int d=ts[i+1]-te[i];
if(d>60)
d=d-40;
if(d>=T)
slot+=(d-T)+1;
}
cout<<slot;
return 0;
}








