USACO Silver 2018 January - Lifeguards

I recently attempted USACO Silver 2018 January - Lifeguards:

I’m confused regarding the method used to solve this problem from USACO guide:

I understand that they take the time intervals and sort it by starting time. Then they loop through it and determine how much time the guards all combined cover. So that is the code from 0-36. I’m a little confused what they do from lines 38-51. Can someone please explain that.


That portion is to calculate the minimum time that has been removed. To understand the formula, I would suggest you notice any patterns about the sample case.

1 Like