#include <algorithm>
#include<iostream>
using namespace std;
struct List
{
int start_time;//头指针计总分等待时间
int end_time;//头指针计最长等待时间
int wait_time;//代表服务了多少人
struct List *next;
};
void Insert_List(List *head, List *tail, List *L)
{
List *p = tail->next;
tail->next->next = L;
tail->next = L;
if(L->start_time > p->end_time)
{
L->end_time = L->start_time + L->wait_time;
L->wait_time = 0;
}
else
{
L->end_time = p->end_time + L->wait_time;
L->wait_time = p->end_time - L->start_time;
}
head->start_time += L->wait_time;
if(head->end_time < L->wait_time)
head->end_time = L->wait_time;
head->wait_time++;
}
int Get_short_List(List list_tail[15], int list_number, int limit)
{
int Min, i;
// printf("123\n");
for(i = 0; i < list_number; i++)
{
if(i==0)
Min = list_tail[i].next->end_time;
else if(Min > list_tail[i].next->end_time)
Min = list_tail[i].next->end_time;
}
for(i = 0; i < list_number; i++)
{
if(Min == list_tail[i].next->end_time || list_tail[i].next->end_time <= limit)
{
return i;
}
}
}
void ListPrint_L(List *L)
{
//输出单链表
List *p=L->next; //p指向第一个元素结点
while(p!=NULL)
{
if(p->next!=NULL)
printf("%d %d ",p->start_time, p->end_time);
else
printf("%d %d\n",p->start_time, p->end_time);
p=p->next;
}
}
int main()
{
List *number;
int people_number;
scanf("%d", &people_number);
number = new List[people_number + 2];
for(int i = 0; i < people_number; i++)
{
scanf("%d %d", &number[i].start_time, &number[i].wait_time);
if(number[i].wait_time > 60)
number[i].wait_time = 60;
number[i].next = NULL;
}
int list_number;
List list_head[15], list_tail[15];
scanf("%d", &list_number);
for(int i = 0; i < list_number; i++)
{
list_head[i].wait_time = 0;
list_head[i].start_time = 0;
list_head[i].end_time = 0;
list_head[i].next = NULL;
list_tail[i].next = &list_head[i];
}
for(int i = 0; i < people_number; i++)
{
int j = 0;
j = Get_short_List(list_tail, list_number, number[i].start_time);
Insert_List(&list_head[j], &list_tail[j], &number[i]);
}
double sum = 0;
int longest_wait = 0, finish_time = 0;
for(int i = 0; i < list_number; i++)
{
sum += list_head[i].start_time;
if(longest_wait < list_head[i].end_time)
longest_wait = list_head[i].end_time;
if(finish_time < list_tail[i].next->end_time)
finish_time = list_tail[i].next->end_time;
}
printf("%.1lf %d %d\n", sum/people_number, longest_wait, finish_time);
for(int i = 0; i < list_number; i++)
{
if(i)
printf(" %d", list_head[i].wait_time);
else
printf("%d", list_head[i].wait_time);
}
}