Row Logic - Python

2

I have a question in a question, and I hope you guys can help me, the question itself is not how to develop the issue, this is not the problem, the problem lies in the logic of the issue that I am not getting understand, the question is this:

  

Existing legislation requires banks to start   client within 20 minutes after the client enters the queue   of the bank branch. The queue is unique, so a free box   asks the first customer in the queue to come to your booth to be   attended. (Let's ignore the problem of priority customers here,   elderly, pregnant women, people with special needs, etc.).   assuming also that no mailbox serves two clients at the same time.

     

Your program will receive the number of active boxes in the branch, the number   of customers, and for each customer, two information, namely the time   customer in the queue, and the duration of the customer's   client. Initially all boxes are empty, since the agency   just opened Your problem is to determine the number of customers   will wait more than 20 minutes to have your service started.

Entry:

  

The first line of the entry contains two integers separated by a   blank space. The first, C, is the number of active boxes in the   bank branch The second, N, the number of customers who will seek   the agency that day. The next N lines will have each   an information about a client, consisting of two integers, T and D,   separated by a space. The integer T gives the moment in   that the customer enters the queue, in minutes, from the instant of   opening of the agency. The integer D provides, in minutes, the time   necessary to serve the client. The rows are sorted by   clients in the queue.

     

Suppose:

     
asked by anonymous 26.03.2017 / 01:15

1 answer

0

See the following timeline.

(12)-(123)-(1234)--------( 234)----------( 34)----------( 45)----------( 5)----------( )
 ^^     ^      ^          1               2              3 ^            4              5
  • Each stroke is one minute passed
  • In parentheses is the customer queue (the farthest left being serviced)
  • The bottom row indicates who entered (with ^ ) and who left (lowering the number)

Analyzing events:

  • At minute zero, the first and second customer entered and the first one started being serviced
  • 1 minute passed
  • At minute 1, the third customer entered
  • 1 minute passed
  • In minute 2, the fourth customer entered
  • 8 minutes passed
  • At minute 10, the first client left and the second started to be serviced
  • It's been 10 minutes
  • At minute 20, the second client left and the third began to be serviced
  • It's been 10 minutes
  • At minute 30, the third customer left, the fourth began to be serviced and the fifth entered
  • It's been 10 minutes
  • In minute 40, the fourth customer left and the fifth began to be serviced
  • It's been 10 minutes
  • At minute 50, the fifth client left

Calculating the timeout:

  • Client 1 waited 0 minutes (entered the minute 0, was filled in minute 0)
  • Client 2 waited 10 minutes (entered the minute 0, was served in minute 10)
  • Client 3 waited 19 minutes (entered 1 minute, was served in minute 20)
  • Client 4 waited 28 minutes (entered minute 2, was served in minute 30)
  • Customer 5 waited 10 minutes (entered the 30th minute, was answered in the 40th minute)

That is, client 4 was the only one that waited more than 20 minutes, so the output of the program is 1.

    
18.07.2018 / 20:06