please write simple python3 program and also explain the logicof program because i am not understanding and crying so much
Problem Statement
There is a very famous old restaurant in ByteLand city,which canserve only 1 customer at any given time.It has B chairs outside forwaiting customers.The restautants manager has a list of people whowill be coming in today.The i-th customer will arrive at t[i] (allunique) time and will eat for d[i] unit of time.The restaurantattends to each customer as per the following rules:
1) if there is no customer being served currently,a new customerwill be served immediately
2) if one customer is being served and there is at least oneempty chair in the waiting area,a new customer will go and occupyone empty chair.
3)if the waiting area is full,a new customer will be rejectedand will never be served .
4)Waiting area works like a queue and the first to enter will beserved first.
Based on the list,the restaurant manager wants to know:
1.How many customers will be rejected today so that she can planthe food quantity accordingly and also 2 .v by what time will shefinish serving the last customer.
Input format:
The first line of the input contains two integers N andB(1<=N,B<=100,000)-- The number of customers and the numberof chairs in the waiting area.
Then follow N lines with queries descriptions (in chronologicalorder ). Each description consists of two integers t[i] and d[i] (1 <= t[i] , d[i]<= 10^9 ) , where t[i] is the moment of timewhen the i-th customer appears and d[i] is the time customer needsfor eating. it is gauranteed that t[i-1] < t[i] for all i>1
Output Format:
Print one integer corresponding to the number of customers whowill be rejected and time when the last customer will be finish hermeal.
Sample Input1:
5 1
2 9
4 8
10 9
15 2
19 1
Sample Output1
1 22
Explanation
1st customer comes at moment 2,no one is being served hence shewill be served immediately.
2nd customer comes at moment 4 , 1rst one is still being servedhence she will go and take chair in waiting area
3rd customer comes at moment 10 1rst one is still being servedand no chair is empty in waiting area.Hence she will berejected.
1st customer finishes at moment 11, 2nd customer will come fromwaiting area to get served and waiting area becomes empty.
4th customer comes at moment 15,2nd customer is being servedhence she will move to waiting area.
2nd customer finishes at moment 19, 4th customer will move fromwaiting area to get served and waiting area becomes empty.
5th customer comes at moment 19,4th customer is being servedhence she will move to waiting area
4th customer finishes at moment 21 , 5th customer will move fromwaiting area to get served and waiting area becomes empty.
5th customer finishes at moment 22
Sample input2
5 1
2 1
3 6
4 5
6 4
7 2
Sample putput 2:
2 14