#C7278. Minimum Jump Count Problem

    ID: 51131 Type: Default 1000ms 256MiB

Minimum Jump Count Problem

Minimum Jump Count Problem

Given a series of platforms and a list of maximum jump lengths from each platform, determine the minimum number of jumps required to reach the last platform. If it is not possible to reach the last platform, output -1.

Formally, let \(n\) be the number of platforms and an array \(jumps\) where \(jumps[i]\) represents the maximum forward jump length available from platform \(i\). You are required to compute the minimal number of jumps needed to reach platform \(n-1\) (0-indexed) using a greedy strategy.

inputFormat

The input is given via stdin and consists of two lines:

  • The first line contains an integer \(n\), the number of platforms.
  • The second line contains \(n\) space-separated integers, where the \(i\)-th integer represents the maximum jump length from platform \(i\).

outputFormat

Output via stdout a single integer: the minimum number of jumps needed to reach the last platform. If it is not possible to reach the last platform, output -1.

## sample
6
3 3 1 0 2 0
3

</p>