Loading...
Loading...
A coaching centre rents seats in a study hall for n days. A booking says: reserve c seats on every day from day l to day r, both days included. There are m bookings.
After all bookings, print the total number of reserved seats for each day.
Example
Input
5 3 1 3 2 2 5 1 4 4 6
Output
2 3 3 7 1
Day 4 gets 1 seat from the second booking and 6 from the third: 7 in total.
Try the problem first. Open one hint at a time.
Adding c to every day of every booking can take 10^10 steps.
Mark only where a booking starts and where it stops: add c at day l and subtract c right after day r.
After all bookings, a running total over the marks gives the real count for each day.
Make the mark array size n + 2 so that "right after day n" has a place. Use long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor