Queue Data Structure
In civilized countries k ticket offices are working at the train station, but the queue to them is just one. The service works as follows. Initially, when all the ticket offices are free, the first k people from the queue go to the offices. The others are waiting their turn. As soon as someone is served and the corresponding office becomes free, the next person in the queue comes to this office. This continues until all the people will be served.
Find the time to serve all the clients.
The first line contains two integers: the queue size n and the number of ticket offices k (1 ≤ n ≤
10^5, 1 ≤ k ≤
10^4). n positive integers are given in the second line. The i-th number gives the time
t[i] (1 ≤
10^5) to serve the i-th client in the queue.
Print one integer - the time to serve all the people in the queue.
5 2 3 1 1 2 3
7 3 1 2 3 4 5 3 1