#include<bits/stdc++.h>
using namespace std;
const int MAXN=10002;
const int INF=1000000000;
struct Node{
int start;
int startwork;
int time;
int flag;
int id;
}node[MAXN];
struct Table{
int vip;
int cnt;
int endtime;
}table[102];
bool cmp(Node a,Node b){
return a.start<b.start;
}
bool cmp1(Node a,Node b){
return a.startwork<b.startwork;
}
int main()
{
freopen("in.txt","r",stdin);
int n;cin>>n;vector<Node> ppp;
int sign1[MAXN]={};
for(int i=0;i<n;i++){
int h,m,s,t;
scanf("%d:%d:%d %d %d",&h,&m,&s,&t,&node[i].flag);
if(t>2*60){
t=2*60;
}
node[i].time=t*60;
node[i].start=h*3600+m*60+s;
node[i].id=i;
if(node[i].flag==1){
ppp.push_back(node[i]);
}
}
sort(node,node+n,cmp);
sort(ppp.begin(),ppp.end(),cmp);
int kk,m;cin>>kk>>m;
for(int i=1;i<=kk;i++){
table[i].vip=0;
table[i].endtime=8*3600;
}
for(int i=0;i<m;i++){
int temp;cin>>temp;
table[temp].vip=1;
}
vector<Node> temp;
for(int i=0;i<n;i++){
int k=-1;int MINendtime=INF;
for(int j=1;j<=kk;j++){
if(table[j].endtime<MINendtime){
k=j;
MINendtime=table[j].endtime;
}
}
if(table[k].endtime<21*3600){
if(table[k].vip==1){
if(ppp.size()!=0&&ppp[0].start<=table[k].endtime){
if(sign1[ppp[0].id]==0){
sign1[ppp[0].id]=1;
ppp[0].startwork=table[k].endtime;
table[k].endtime+=ppp[0].time;table[k].cnt++;
temp.push_back(ppp[0]);
ppp.erase(ppp.begin());
}else{
ppp.erase(ppp.begin());
}
i--;
}else{
if(sign1[node[i].id]==0){
sign1[node[i].id]=1;
if(node[i].start<=table[k].endtime){
node[i].startwork=table[k].endtime;
table[k].endtime+=node[i].time;table[k].cnt++;
temp.push_back(node[i]);
}else{
node[i].startwork=node[i].start;
table[k].endtime=node[i].start+node[i].time;table[k].cnt++;
temp.push_back(node[i]);
}
}else{
continue;
}
}
}else{
if(sign1[node[i].id]==0){
sign1[node[i].id]=1;
if(node[i].start<=table[k].endtime){
node[i].startwork=table[k].endtime;
table[k].endtime+=node[i].time;table[k].cnt++;
temp.push_back(node[i]);
}else{
node[i].startwork=node[i].start;
table[k].endtime=node[i].start+node[i].time;table[k].cnt++;
temp.push_back(node[i]);
}
}else{
continue;
}
}
}
}
sort(temp.begin(),temp.end(),cmp1);
for(int i=0;i<temp.size();i++){
int h1,m1,s1,h2,m2,s2,wt;
h1=temp[i].start/3600;m1=temp[i].start%3600/60;s1=temp[i].start%3600%60;
h2=temp[i].startwork/3600;m2=temp[i].startwork%3600/60;s2=temp[i].startwork%3600%60;
wt=temp[i].startwork-temp[i].start;
if(wt%60!=0){
wt=wt/60+1;
}else{
wt=wt/60;
}
printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",h1,m1,s1,h2,m2,s2,wt);
}
for(int i=1;i<=kk;i++){
if(i==1) cout<<table[i].cnt;
else cout<<' '<<table[i].cnt;
}
return 0;
}
23分飘过,待修改。。。