#C10771. Jump Game

    ID: 40013 Type: Default 1000ms 256MiB

Jump Game

Jump Game

You are given an array of non-negative integers where each element represents your maximum jump length at that position. Your task is to determine if you can reach the last index of the array starting from the first index.

For example, if the array is \(a = [2, 3, 1, 1, 4]\), then you can jump from index 0 to 1 (since \(2 \geq 1\)), and then jump from index 1 to the last index, so the answer is YES.

If it is impossible to reach the last index, output NO.

Note: All indices are 0-based.

inputFormat

The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated non-negative integers which represent the jump lengths.

outputFormat

Output a single line containing YES if you can reach the last index, or NO otherwise.## sample

5
2 3 1 1 4
YES

</p>