PAT甲1017

import heapq

# 时分秒字符串转为总秒数
def to_sec(time_str):
    h, m, s = map(int, time_str.split(':'))
    return h * 3600 + m * 60 + s

# 读取顾客数、窗口数
n, k = map(int, input().split())
customers = []
open_time = 8 * 3600    # 08:00:00 秒数
close_time = 17 * 3600  # 17:00:00 秒数

for _ in range(n):
    arr_t, p = input().split()
    arrive = to_sec(arr_t)
    process = int(p) * 60  # 办理分钟转秒
    # 到达晚于17点直接抛弃
    if arrive <= close_time:
        customers.append((arrive, process))

# 顾客按到达时间从小到大排序
customers.sort()

# 初始化k个窗口,初始空闲时间都是早上8点
heap = []
for _ in range(k):
    heapq.heappush(heap, open_time)

total_wait = 0

for arr, proc in customers:
    earliest_free = heapq.heappop(heap)
    # 实际开始办理的时间:取 到达时间 和 窗口空闲时间 的更大值
    start = max(arr, earliest_free)
    total_wait += start - arr
    # 更新窗口新的空闲时间,放回堆
    heapq.heappush(heap, start + proc)

# 平均等待分钟 = 总秒 / 人数 / 60
avg_min = total_wait / len(customers) / 60
# 保留1位小数输出
print("{0:.1f}".format(avg_min))