#include using namespace std; int main() { int n, target; stack st; cin >> n; int cur = 1; // 当前待入栈数字 for (int i = 0; i < n; i++) { cin >> target; // 读取目标出站值 // 当前目标值未入栈,持续入栈直到包含目标值 while (cur <= target) st.push(cur++); // 栈顶匹配则出栈 if (!st.empty() && st.top() == target) { st.pop(); } else { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; }