A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. If all the tables are occupied, they will have to wait in a queue. It is assumed that every pair of players can play for at most 2 hours.
Your job is to count for everyone in queue their waiting time, and for each table the number of players it has served for the day.
One thing that makes this procedure a bit complicated is that the club reserves some tables for their VIP members. When a VIP table is open, the first VIP pair in the queue will have the priviledge to take it. However, if there is no VIP in the queue, the next pair of players can take it. On the other hand, if when it is the turn of a VIP pair, yet no VIP table is available, they can be assigned as any ordinary players.
Input Specification:
Each input file contains one test case. For each case, the first line contains an integer N (<=10000) - the total number of pairs of players. Then N lines follow, each contains 2 times and a VIP tag: HH:MM:SS - the arriving time, P - the playing time in minutes of a pair of players, and tag - which is 1 if they hold a VIP card, or 0 if not. It is guaranteed that the arriving time is between 08:00:00 and 21:00:00 while the club is open. It is assumed that no two customers arrives at the same time. Following the players' info, there are 2 positive integers: K (<=100) - the number of tables, and M (< K) - the number of VIP tables. The last line contains M table numbers.
Output Specification:
For each test case, first print the arriving time, serving time and the waiting time for each pair of players in the format shown by the sample. Then print in a line the number of players served by each table. Notice that the output must be listed in chronological order of the serving time. The waiting time must be rounded up to an integer minute(s). If one cannot get a table before the closing time, their information must NOT be printed.
Sample Input:9 20:52:00 10 0 08:00:00 20 0 08:02:00 30 0 20:51:00 10 0 08:10:00 5 0 08:12:00 10 1 20:50:00 10 0 08:01:30 15 1 20:53:00 10 1 3 1 2Sample Output:
08:00:00 08:00:00 0 08:01:30 08:01:30 0 08:02:00 08:02:00 0 08:12:00 08:16:30 5 08:10:00 08:20:00 10 20:50:00 20:50:00 0 20:51:00 20:51:00 0 20:52:00 20:52:00 0 3 3 2
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
struct customer
{
int arrTime;//arriving time in second
int serTime;//serving time in second
int waiTime;//waiting time in second
int plaTime;//playing time in second
int vip;//vip flag
bool operator < (const customer &c) const
{
return arrTime<c.arrTime;
}
};
vector<customer>ordCus; //ordinary customers vector
vector<customer>vipCus; //vip customers vector
int tabTime[100]={0};//the end of using time of current customer
int isVipTab[100]={0};//isVipTab[i]=1 if the i-th table is for vip
int tabUse[100]={0};//using times of each table
int str2sec(char *t)
{//transform s string in fomat HH:MM:SS to time in seconds
int time;
time=((t[0]- '0')*10+t[1]-'0' -8)*3600+((t[3]-'0')*10+t[4]- '0')*60+(t[6]-'0' )*10+t[7]-'0';
return time;
}
void sec2str(int time,char *t)
{//transform time in seconds to a string in format HH:MM:SS
t[2]=t[5]= ':';
t[0]=(time/3600+8)/10+ '0';
t[1]=(time/3600+8)%10+ '0';
t[3]=(time%3600)/60/10+ '0';
t[4]=((time%3600)/60)%10+ '0';
t[6]=(time%60)/10+ '0';
t[7]=(time%60)%10+ '0';
t[8]= '\0';
}
//bool cmp(customer a,customer b)
//{
// if(a.serTime==b.serTime)
// return a.arrTime<b.arrTime;
// else
// return a.serTime<b.serTime;
//}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;++i)
{
customer c;
char strTime[10];
int isvip;
cin>>strTime;
c.arrTime=str2sec(strTime);
cin>>c.plaTime>>c.vip;
if(c.plaTime>120)//if playing time is more than 120 minutes(2 hours),set it to be 120
c.plaTime=120;
c.plaTime*=60; //transform minute to be second
if(c.vip)//if the customer is vip, push him into vipCus
vipCus.push_back(c);
else ordCus.push_back(c);
}
if(ordCus.size()>0)
sort(ordCus.begin(),ordCus.end()); //sort in increasing arriving time
if(vipCus.size()>0)
sort(vipCus.begin(),vipCus.end());
int k,m,v;
cin>>k>>m;
for(int i=0;i<m;++i)
{
cin>>v;
isVipTab[v-1]=1; //record vip table
}
int ordIndex=0,vipIndex=0;
int j;
vector<customer> ans;
while(ordIndex<ordCus.size() || vipIndex<vipCus.size())
{
customer front;
int tab;//index of table occupied in this loop
//first find the front customer in the waitting queue
if(ordIndex==ordCus.size())
front=vipCus[vipIndex++];
else if (vipIndex==vipCus.size())
front=ordCus[ordIndex++];
else if (vipCus[vipIndex].arrTime<ordCus[ordIndex].arrTime)
front=vipCus[vipIndex++];
else front=ordCus[ordIndex++];
int availTime=tabTime[0],earlist=0;
vector< int>availTable;//available tables for the front customer
for(j=0;j<k;++j)
{ //find the tables which is available for the front customer
if(tabTime[j]<=front.arrTime)
availTable.push_back(j);
if(tabTime[j]<availTime)
{ //find the table which is earlist available with the smallist number
earlist=j;
availTime=tabTime[j];
}
}
//when the earlist table's available time or the front customer's arriving time
//is later than closing time, break the loop
if(availTime>=13*3600 || front.arrTime>=13*3600)
break;
if(front.vip)
{ //if the front customer is a vip
if(availTable.size()>0)
{ //if there are available tables when arriving
tab=availTable[0];
for(j=0;j<availTable.size();++j)
{ //if there is vip table available, choose the first one
//if not, still choose availTable[0] the table with the smallest number
if(isVipTab[availTable[j]])
{
tab=availTable[j];
break;
}
}
}
else
{ //if there is no available table when arriving, just wait for the earlist available table
for(j=0;j<k;++j)
{ //find all of the available table when the the earlist available table open
//that means there might be more than one table open at the same time
if(tabTime[j]<=availTime)
availTable.push_back(j);
}
tab=availTable[0];
for(j=0;j<availTable.size();++j)
{ //if there is vip table in all available tables, choose the first one
//if not, still choose availTable[0] the table with the smallest number
if(isVipTab[availTable[j]])
{
tab=availTable[j];
break;
}
}
}
}
else
{ //if the front customer is not a vip
if(availTable.size()>0)
{ //if there are available tables when arriving, use the table with the smallest number
tab=availTable[0];
}
else
{ //if there is no available table when arriving, just wait for the earlist available table
if(!vipCus.empty() && vipCus[vipIndex].arrTime<=availTime)
{ //if there is vip customer arrived before earlist first table open
for(j=0;j<k;++j)
{ //check if there is a vip table open at the available time
if(tabTime[j]<=availTime && isVipTab[j])
break;
}
if(j!=k)
{ //if there is vip table open, the vip customer has the previlidge to use it
tab=j;
front=vipCus[vipIndex++]; //then vip customer become the front one
--ordIndex; //the front ordinary customer back off
}
else
{ //if there is no vip table open, ignore the vip customer's previlidge
tab=earlist;
}
}
else
{ //if there is no vip customer arrived before earlist first table open
//choose the earlist open table
tab=earlist;
}
}
}
++tabUse[tab]; //count the use time
front.serTime=max(tabTime[tab],front.arrTime);
front.waiTime=front.serTime-front.arrTime;
tabTime[tab]=front.serTime+front.plaTime;
//ans.push_back(front);
char arr[10],ser[10];
sec2str(front.arrTime,arr);
sec2str(front.serTime,ser);
//round up to an integer minutes!!!!!!!!!!!!!神??坑??!!!!
cout<<arr<< ' '<<ser<<' ' <<(front.waiTime+30)/60<<endl;
}
//sort(ans.begin(),ans.end(),cmp);
//for(int i=0;i<ans.size();++i)
//{
// char arr[10],ser[10];
// sec2str(ans[i].arrTime,arr);
// sec2str(ans[i].serTime,ser);
// //round up to an integer minutes!!!!!!!!!!!!!
// cout<<arr<<' '<<ser<<' '<<(ans[i].waiTime+30)/60<<endl;
//}
cout<<tabUse[0];
for(int i=1;i<k;++i)
cout<< ' '<<tabUse[i];
return 0;
}