eolymp
bolt
Try our new interface for solving problems
Problems

Is it a Heap?

Is it a Heap?

The \textbf{Heap} data structure can be implement using an array. The array must maintain the main heap property: for each $i~(1 \le i \le n)$ next conditions must hold: \begin{itemize} \item If $2i \le n$, then $a_i \le a_{2i}$ \item If $2i + 1 \le n$, then $a_i \le a_{2i+1}$ \end{itemize} The array of integers is given. Determine whether it is a heap. \InputFile First line contains number $n~(1 \le n \le 10^5)$. Second line contains $n$ integers that do not exceed $2 \cdot 10^9$ by absolute value. \OutputFile Print "\textbf{YES}", if the array is a heap and "\textbf{NO}" otherwise. \includegraphics{https://static.e-olymp.com/content/df/df4744ea60c745c1fd9f6799b84250a1161add24.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
7
3 10 5 12 11 6 7
Output example #1
YES