We are in post. There are N switchboards. Each switchboard takes T of time to deal with the problems to the person who goes to that switchboard.
There are M people in line. How many minutes does Skyler (who is in the end of queue) have to wait to be assisted by the first free switchboard?
So, input:
T = [1, 2, 4, 1], T[i] says how long it takes the i-th switchboard to process a person (the numbers in T are >= 1 and the length of the array ranges from 1 to N)
M = 6 (this number goes from 0 to K), Skyler is the seventh.
Output for this example: 2 minutes
Why 2 minutes?
Because in the first minute, 4 people are assisted (there are still 2 left because 6 - 4 = 2). Switchboard T[0] and T[3] end after 1 minute. So, for now, Skyler is waiting 1 minute. The two remaining people go to the free switchboards (T[0] and T[3]). After another minute, people at the switchboards T[0] and T[3] are finished to be assisted and it's Skyler's turn. So Skyler waited 2 min.