#3594

Minimum Time to Transport All Individuals

international master · 2035 · lc hard +32 · 28.1% accepted · 41 likes · top 6%

Description

There are n individuals crossing a river in a boat of capacity k. The environment cycles through m stages, each with speed multiplier mul[j] (larger value = slower). Each individual i has base crossing time time[i].

Rules:

- A group departing at stage j takes max(time[i]) * mul[j] minutes. The stage then advances by floor(crossing_time) % m.

- If anyone remains on the starting side, one person returns: return time = time[r] * mul[current_stage], stage advances by floor(return_time) % m.

Return the minimum total time to transport everyone, or -1 if impossible.

Code

1
2
3