The average waiting time for all customers is calculated by the known customer's arrival time t and the time it takes to service the customer

Source: Internet
Author: User
Tags range first row

Topic Overview

Suppose there are N customers waiting for service in the K window. Each window can hold one person, so other customers need to wait. When a customer service completes, the next customer can enter the window and be serviced. We assume that no window will be occupied for more than 1 hours.

Now we give each customer the arrival time t and the time required to service the customer p, please calculate the average waiting time for all customers.

Input

Each input file contains a test case. For each test case, the first row contains two integers n (<= 1000) and K (<= 100). where n represents the number of customers, K represents the number of Windows.

The next n lines, including two time: HH:MM:SS, indicating the customer's arrival time; P, which indicates the time (in minutes) that is required to service the customer.

The range of HH is [+], and the range of MM and SS is [00, 59]. We assume that no two customers arrive at the same time.

It should be explained that the bank's business hours are 08:00-17:00. If the arrival time is earlier than 08:00, the customer needs to wait until the bank opens to be served; If the customer arrives at the bank late (or exactly) 17:00:01, the customer is not serviced, and therefore the average waiting time for the customer is not calculated.

Output

For each test case, output the customer's average wait time, in minutes, and accurate to a decimal.

Ideas for solving problems

A typical simulation problem, and a simpler simulation than Pat 1014.

Automatically filters customers arriving after 17:00:00 when reading data.

Service in order of customer arrival, after the completion of customer service, update the window service completion time.

Customers Queue (service) each time the shortest service is completed.

The following conditions need to be considered:

-If the bank is not open, the customer needs to wait;

(and some of the situations described in "problems encountered")

Problems encountered

Several times WA, there are the following circumstances to consider

1. If all customers arrive after 17:00:00, the result is 0.0;

2. If all the current customers have completed the service, but the next customer has not arrived, need to wait for the window;

3. If the current customer does not need to wait, the window service completion time for the customer arrival time + service time; Otherwise, the window service completes the time that the previous customer completed + the customer service time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.