How to approach this problem?

I am trying to solve the problem sleeping schedule.
https://codeforces.com/contest/1324/problem/E
Please can u tell me how can i approach it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Think of the following four cases:

  1. if vova sleeps for a[i]-1 hrs and the duration is between l and r.
  2. if vova sleeps for a[i]-1 hrs and the duration is not between l and r.
  3. if vova sleeps for a[i] hrs and the duration is between l and r.
  4. if vova sleeps for a[i] hrs and the duration is between l and r.

so, there will be four recursive cases. Note that one day has h hours so total sleeping time will be ((previous sleeping time) + (current sleeping time(a[i] or a[i]-1)))%h.

Now, try to solve the problem.