Rink resurface board
MediumOnline Assessment
Build the day's board for an ice rink: when each skating session really starts, given that the ice has to be resurfaced by the Zamboni as it wears out.
The rink opens at minute 0 with freshly resurfaced ice and closes at minute closing. sessions lists the sessions as [kind, start, length] in non-decreasing order of the requested start. Each session adds wear to the ice: length for "public" and "figure" sessions, and 2 * length for "hockey" sessions. Resurfacing resets the wear to 0 and takes resurfaceMinutes, during which the rink is closed to skaters.
Handle the sessions in order. For each one:
- Resurfacing is needed if the ice has any wear (more than 0) and either the session is a
"figure"session (figure skaters always want fresh ice), or the current wear plus this session's wear would exceedwearLimit. Landing exactly on the limit is fine. A session on fresh ice never needs resurfacing, even if its own wear is above the limit. - The Zamboni can only start when the previous session that actually ran has finished. So the earliest start is that session's end (0 if none), plus
resurfaceMinutesif resurfacing is needed. The session starts at the later of its requestedstartand that earliest start. - The session is cancelled if it would start more than
maxDelayminutes after its requested start, or if it would end (start pluslength) afterclosing. Ending exactly atclosingis fine. A cancelled session does not change anything: no resurfacing happens, no wear is added, and the next session sees the same previous end. - Otherwise the session runs: perform the resurfacing if it was needed, then add the session's wear.
Input: sessions, wearLimit, resurfaceMinutes, maxDelay, closing.
Output: a two-element list [starts, resurfacings]: starts has one entry per session in the given order, with its actual start minute, or -1 if it was cancelled; resurfacings is the number of resurfacings that were performed.
Example 1
- Input:
- [[["public",0,60],["public",60,30],["hockey",90,30],["figure",100,40]],100,12,10,600]
- Output:
- [[0,60,-1,102],1]
- Explanation
- With
wearLimit = 100,resurfaceMinutes = 12,maxDelay = 10, the first two public sessions run at 0 and 60 for a wear of 90. The hockey session at 90 would add 60 wear (total 150), so it needs resurfacing: the earliest start is 90 + 12 = 102, which is 12 minutes late, more thanmaxDelay, so it is cancelled and nothing changes. The figure session requested at 100 always wants fresh ice and the ice is worn, so it needs resurfacing too: it starts at 102 (2 minutes late, allowed). One resurfacing happened.
Example 2
- Input:
- [[["hockey",0,30],["public",40,40],["figure",90,30],["public",590,20]],100,12,10,600]
- Output:
- [[0,40,92,-1],1]
- Explanation
- The hockey session adds 60 wear. The public session at 40 brings the wear to exactly 100, which is not above the limit, so no resurfacing is needed and it starts as requested at 40. The figure session requested at 90 needs resurfacing: the previous session ended at 80, so the earliest start is 92, and it starts at 92. The last public session would end at 610, after closing at 600, so it is cancelled.
Example 3
- Input:
- [[["hockey",0,80],["public",40,20],["public",100,10]],100,12,10,600]
- Output:
- [[0,-1,100],1]
- Explanation
- The first session is hockey on fresh ice: its wear of 160 is above the limit, but fresh ice is never resurfaced, so it runs at 0 and ends at 80. The public session at 40 would need resurfacing (earliest start 92, 52 minutes late) and is cancelled. The last public session at 100 also needs resurfacing, and the Zamboni can finish by 92, so it starts on time at 100. One resurfacing in total.
Constraints
0 <= sessions.length <= 500kindis"public","hockey"or"figure"0 <= start <= 1,440,1 <= length <= 2401 <= wearLimit <= 1,000,1 <= resurfaceMinutes <= 60,0 <= maxDelay <= 120,1 <= closing <= 1,500