Covid Rush

4.8

11 votes
Problem

There are M covid centres denoted by IDs 0 to M - 1 located on a cirular path (centre 1 is right to centre 0, centre 2 is right to centre 1, ... centre 0 is right to centre M - 1). Each centre can treat only one patient at a time. There are N patients and two arrays, arrival and treatment of length N is given. arrival denotes that ith patient arrives to (i%M)th centre on arrival[i]th day.

If the centre is occupied, then they try getting admitted to the closest vacant centre clockwise right to the (i%M)th centre.
If no centre is vacant, then the patient leaves.
Once admitted in a centre, the patients gets treated for treatment[i] days there and then leaves.

Output M values in which ith value denotes the number of patients treated by ith covid centre in total.

    Note - arrival[i] and treatment[i] is the i-th element of the array, arrival and treatment respectively. (0-indexing is followed)

 

Input Format -

    First line of input contains an integer , n ,denoting the number of patients and an interger, m, denoting the number of centres.

    Second line contains n space separated integers of the array, arrival.

Third line contains n space separated integers of the array, treatment.

Output Format -

Output M space seperated integers in which ith value denotes the number of patients treated by ith covid centre.

Constraints -

    1 ≤ N, M ≤ 10^5

    1 ≤ arrival[i], treatment[i] ≤ 10^8

    All the values of arrival are in strictly increasing order.

   

    

Sample Input
5 3
1 3 6 7 10
6 10 1 10 1
Sample Output
2 1 2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The first patient arrives on day 1 and as the 0th centre (because i%M = 0%3 = 0) is vacant, they occupy the 0th centre and will leave on (1 + 6) = 7th day.

The second patient arrives on day 3 and as 1st centre (because 1%3 = 1) is vacant, they occupy the 1st centre and will leave on (3 + 10) = 13th day.

The third patient arrives on day 6 and as 2nd centre (because 2%3 = 2) is vacant, they occupy the 2nd centre and will leave on (6 + 1) = 7th day.

The fourth patient arrives on day 7 and as 0th centre (because 3%3 = 0) is not vacant and next clockwise vacant centre is 2nd centre, they occupy the 2nd centre and will leave on (7 + 10) = 17th day.

The fifth and last patient arrives on day 10 and as 1st centre (because 4%3 = 1) is not vacant and next clockwise vacant centre is 0th, they occupy the 0th centre and will leave on (10 + 1) = 11th day.

Centre 0 was visited by : first and fifth patient

Centre 1 was visited by : second patient

Centre 2 was visited by : third and fourth patient

Editor Image

?