시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 (추가 시간 없음) | 1024 MB | 34 | 24 | 23 | 69.697% |
Grammy likes to eat noodles. She divided a very long strip of noodle into $N$ parts of unit length. Each part $i$ has deliciousness $a_i$. She would like to fold the noodle into one piece of unit length before eating by repeating the following operation several (possibly, zero) times.
Let $n$ be the current length of the noodle. In each operation, Grammy can choose a length $\ell$ such that $2 \ell \leq n$ and $a_i > 0$ for all $i \leq \ell$, and fold the noodle $a_1, a_2, \ldots, a_\ell, a_{\ell + 1}, \ldots, a_{2 \ell}, a_{2 \ell + 1}, \ldots, a_n$ into $a_{\ell + 1} + a_\ell, a_{\ell + 2} + a_{\ell - 1}, \ldots, a_{2 \ell} + a_1, a_{2 \ell + 1}, \ldots, a_n$, where $n$ is the length of the noodle before the operation. After the operation, the length will become $n - \ell$.
Grammy wants to know whether she can fold the noodle to length $1$, can you tell her?
The first line of input contains a single integer $N$ ($1 \leq N \leq 100\,000$).
The second line contains $N$ integers $a_i$ ($-20\,000 \leq a_i \leq 20\,000$), representing the deliciousness of each part of the noodle.
If Grammy can fold the noodle to length $1$, output a single line with the word "YES
". Otherwise, output a single line with the word "NO
".
3 1 2 -5
YES
5 2 -5 2 3 1
NO