<p>You are given an integer <code>hoursBefore</code>, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through <code>n</code> roads. The road lengths are given as an integer array <code>dist</code> of length <code>n</code>, where <code>dist[i]</code> describes the length of the <code>i<sup>th</sup></code> road in <strong>kilometers</strong>. In addition, you are given an integer <code>speed</code>, which is the speed (in <strong>km/h</strong>) you will travel at.</p>

<p>After you travel road <code>i</code>, you must rest and wait for the <strong>next integer hour</strong> before you can begin traveling on the next road. Note that you do not have to rest after traveling the last road because you are already at the meeting.</p>

<ul>
	<li>For example, if traveling a road takes <code>1.4</code> hours, you must wait until the <code>2</code> hour mark before traveling the next road. If traveling a road takes exactly&nbsp;<code>2</code>&nbsp;hours, you do not need to wait.</li>
</ul>

<p>However, you are allowed to <strong>skip</strong> some rests to be able to arrive on time, meaning you do not need to wait for the next integer hour. Note that this means you may finish traveling future roads at different hour marks.</p>

<ul>
	<li>For example, suppose traveling the first road takes <code>1.4</code> hours and traveling the second road takes <code>0.6</code> hours. Skipping the rest after the first road will mean you finish traveling the second road right at the <code>2</code> hour mark, letting you start traveling the third road immediately.</li>
</ul>

<p>Return <em>the <strong>minimum number of skips required</strong> to arrive at the meeting on time, or</em> <code>-1</code><em> if it is<strong> impossible</strong></em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> dist = [1,3,2], speed = 4, hoursBefore = 2
<strong>Output:</strong> 1
<strong>Explanation:</strong>
Without skipping any rests, you will arrive in (1/4 + 3/4) + (3/4 + 1/4) + (2/4) = 2.5 hours.
You can skip the first rest to arrive in ((1/4 + <u>0</u>) + (3/4 + 0)) + (2/4) = 1.5 hours.
Note that the second rest is shortened because you finish traveling the second road at an integer hour due to skipping the first rest.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> dist = [7,3,5,5], speed = 2, hoursBefore = 10
<strong>Output:</strong> 2
<strong>Explanation:</strong>
Without skipping any rests, you will arrive in (7/2 + 1/2) + (3/2 + 1/2) + (5/2 + 1/2) + (5/2) = 11.5 hours.
You can skip the first and third rest to arrive in ((7/2 + <u>0</u>) + (3/2 + 0)) + ((5/2 + <u>0</u>) + (5/2)) = 10 hours.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> dist = [7,3,5,5], speed = 1, hoursBefore = 10
<strong>Output:</strong> -1
<strong>Explanation:</strong> It is impossible to arrive at the meeting on time even if you skip all the rests.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == dist.length</code></li>
	<li><code>1 &lt;= n &lt;= 1000</code></li>
	<li><code>1 &lt;= dist[i] &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= speed &lt;= 10<sup>6</sup></code></li>
	<li><code>1 &lt;= hoursBefore &lt;= 10<sup>7</sup></code></li>
</ul>

from typing import List
from math import ceil, inf
from functools import cache

class Solution:
    def minSkips(self, dist: List[int], speed: int, hoursBefore: int) -> int:
        # Check if it's impossible to reach on time even with maximum skips
        if sum(dist) / speed > hoursBefore:
            return -1
        
        @cache
        def fn(i, k):
            """
            Return the minimum time (in terms of distance) required to travel the first i roads
            with k skips allowed.
            """
            if k < 0:
                return inf  # Impossible if skips are negative
            if i == 0:
                return 0  # Base case: no roads to travel, so time is 0
            
            # Option 1: Do not skip the rest after the (i-1)th road
            time_with_rest = ceil((fn(i - 1, k) + dist[i - 1]) / speed) * speed
            
            # Option 2: Skip the rest after the (i-1)th road
            time_with_skip = dist[i - 1] + fn(i - 1, k - 1)
            
            # Return the minimum time of the two options
            return min(time_with_rest, time_with_skip)
        
        # Try different numbers of skips from 0 to n-1
        for k in range(len(dist)):
            # Check if the total time with k skips is within the allowed time
            if fn(len(dist) - 1, k) + dist[-1] <= hoursBefore * speed:
                return k
        
        return -1

# Explanation:
# 1. The function `minSkips` calculates the minimum number of skips required to reach the meeting on time.
# 2. It first checks if the total distance divided by speed exceeds the available time (`hoursBefore`). If so, it returns -1 as it's impossible to reach on time.
# 3. The `fn` function is a recursive helper function with memoization (using `@cache`) to compute the minimum time required to travel the first `i` roads with `k` skips.
# 4. For each road, it considers two options: either take a rest or skip it, and calculates the time accordingly.
# 5. The loop iterates over possible numbers of skips, checking if the total travel time with those skips is within the allowed time.
# 6. If a valid number of skips is found, it returns that number. If no valid solution is found, it returns -1.
1019