#GYM104671B. Starving
Starving
Description
You're in a field, which can be represented by $n + 1$ cells numbered from $0$ to $n$. The state of the field can be represented by a sequence of $n$ integers $a_1, a_2, ..., a_n$. For all $i$, if $a_i > 0$, then cell $i$ contains a watermelon worth $a_i$ health. Otherwise, if $a_i = 0$, then cell $i$ is empty. Cell $0$ is always empty. Initially, you're located in cell $0$ and have $h$ health.
In each minute, the following will occur in order:
- Suppose you're in cell $i$. If $i < n$, you have the option to move to cell $i + 1$. If $i > 0$, you have the option to move to cell $i - 1$. You must pick an option. Let $j$ be the new cell you move to.
- If cell $j$ contains a watermelon, you eat it and $h$ increases by $a_j$. The watermelon disappears and $a_j$ becomes $0$.
- $h$ decreases by $1$. If $h = 0$, then you starve.
- The health value of all uneaten watermelons increases by $1$. In other words, for all $k$ such that $a_k > 0$, $a_k$ increases by $1$.
Please determine if it's possible for you to reach cell $n$ without starving. It doesn't count if you starve in the last minute.
The first line of input consists of two space-separated integers $n$ and $h$ $(1 \leq n, h \leq 2 \cdot 10^5)$.
The second line of input consists of $n$ space-separated integers $a_1, a_2, ..., a_n$ $(0 \leq a_i \leq 2 \cdot 10^5)$.
On the first and only line, output YES if it's possible for you to reach cell $n$ without starving. Otherwise, output NO.
Input
The first line of input consists of two space-separated integers $n$ and $h$ $(1 \leq n, h \leq 2 \cdot 10^5)$.
The second line of input consists of $n$ space-separated integers $a_1, a_2, ..., a_n$ $(0 \leq a_i \leq 2 \cdot 10^5)$.
Output
On the first and only line, output YES if it's possible for you to reach cell $n$ without starving. Otherwise, output NO.
10 3
1 1 1 0 0 0 0 0 0 0
11 3
1 1 1 0 0 0 0 0 0 0 0
1 1
1
YES
NO
YES
Note
One possible path to cell $n$ for the first sample test case looks like this:
It can be proven that it is impossible to reach cell $n$ without starving in the second test case.