Problems > Can You Reach the End

Can You Reach the End

Difficulty: 1400 3000 ms 128 MB

greedy

From position i you may jump forward at most ai steps. Starting at position 1, can you reach position N?

Input: the first line has N; the second line has N non-negative integers.

Output: YES or NO.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ ai ≤ 105

Sample Tests

Input 1
5
2 3 1 1 4
Output 1
YES
Input 2
5
3 2 1 0 4
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.